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.pull/12742/head
parent
68f92d2e7c
commit
0a067f4cc7
|
@ -13,6 +13,7 @@ import voluptuous as vol
|
||||||
from homeassistant.components.discovery import SERVICE_DECONZ
|
from homeassistant.components.discovery import SERVICE_DECONZ
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
CONF_API_KEY, CONF_HOST, CONF_PORT, EVENT_HOMEASSISTANT_STOP)
|
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 config_validation as cv
|
||||||
from homeassistant.helpers import discovery
|
from homeassistant.helpers import discovery
|
||||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
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(
|
hass.services.async_register(
|
||||||
DOMAIN, 'configure', async_configure, schema=SERVICE_SCHEMA)
|
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
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue