From 111e515da71702a29b0572dcbe768ea9b498480a Mon Sep 17 00:00:00 2001 From: Lev Aronsky Date: Tue, 27 Feb 2018 08:31:47 +0200 Subject: [PATCH] Fix a problem with calling `deconz.close` (#12657) * Fix a problem with calling `deconz.close` The event object (`EVENT_HOMEASSISTANT_STOP`) is sent as an argument to the callable passed to `async_listen_once`. However, `deconz.close` is a bound method that takes no arguments. Therefore, it needs a wrapper to discard the event object. * Removed unnecessary code and added a docstring. * Fix the docstring according to guidelines. * Removed unnecessary whitespace. --- homeassistant/components/deconz/__init__.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/deconz/__init__.py b/homeassistant/components/deconz/__init__.py index 693f3e4470a..18197b84b61 100644 --- a/homeassistant/components/deconz/__init__.py +++ b/homeassistant/components/deconz/__init__.py @@ -13,6 +13,7 @@ import voluptuous as vol from homeassistant.components.discovery import SERVICE_DECONZ from homeassistant.const import ( CONF_API_KEY, CONF_HOST, CONF_PORT, EVENT_HOMEASSISTANT_STOP) +from homeassistant.core import callback from homeassistant.helpers import config_validation as cv from homeassistant.helpers import discovery from homeassistant.helpers.aiohttp_client import async_get_clientsession @@ -143,7 +144,18 @@ def async_setup_deconz(hass, config, deconz_config): hass.services.async_register( DOMAIN, 'configure', async_configure, schema=SERVICE_SCHEMA) - hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, deconz.close) + @callback + def deconz_shutdown(event): + """ + Wrap the call to deconz.close. + + Used as an argument to EventBus.async_listen_once - EventBus calls + this method with the event as the first argument, which should not + be passed on to deconz.close. + """ + deconz.close() + + hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, deconz_shutdown) return True