Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions homeassistant/components/binary_sensor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ async def async_setup_entry(hass, entry):
return await hass.data[DOMAIN].async_setup_entry(entry)


async def async_unload_entry(hass, entry):
"""Unload a config entry."""
return await hass.data[DOMAIN].async_unload_entry(entry)


# pylint: disable=no-self-use
class BinarySensorDevice(Entity):
"""Represent a binary sensor."""
Expand Down
21 changes: 19 additions & 2 deletions homeassistant/components/deconz/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@

# Loading the config flow file will register the flow
from .config_flow import configured_hosts
from .const import CONFIG_FILE, DATA_DECONZ_ID, DOMAIN, _LOGGER
from .const import (
CONFIG_FILE, DATA_DECONZ_EVENT, DATA_DECONZ_ID, DOMAIN, _LOGGER)

REQUIREMENTS = ['pydeconz==36']

Expand All @@ -26,6 +27,8 @@
})
}, extra=vol.ALLOW_EXTRA)

SERVICE_DECONZ = 'configure'

SERVICE_FIELD = 'field'
SERVICE_ENTITY = 'entity'
SERVICE_DATA = 'data'
Expand Down Expand Up @@ -77,6 +80,7 @@ async def async_setup_entry(hass, config_entry):
return False

hass.data[DOMAIN] = deconz
hass.data[DATA_DECONZ_EVENT] = []
hass.data[DATA_DECONZ_ID] = {}

for component in ['binary_sensor', 'light', 'scene', 'sensor']:
Expand Down Expand Up @@ -112,7 +116,7 @@ async def async_configure(call):
return
await deconz.async_put_state(field, data)
hass.services.async_register(
DOMAIN, 'configure', async_configure, schema=SERVICE_SCHEMA)
DOMAIN, SERVICE_DECONZ, async_configure, schema=SERVICE_SCHEMA)

@callback
def deconz_shutdown(event):
Expand All @@ -127,3 +131,16 @@ def deconz_shutdown(event):

hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, deconz_shutdown)
return True


async def async_unload_entry(hass, config_entry):
"""Unload deCONZ config entry."""
deconz = hass.data.pop(DOMAIN)
hass.services.async_remove(DOMAIN, SERVICE_DECONZ)
deconz.close()
for component in ['binary_sensor', 'light', 'scene', 'sensor']:
await hass.config_entries.async_forward_entry_unload(
config_entry, component)
for event in hass.data[DATA_DECONZ_EVENT]:
del event
return True
1 change: 1 addition & 0 deletions homeassistant/components/deconz/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@

DOMAIN = 'deconz'
CONFIG_FILE = 'deconz.conf'
DATA_DECONZ_EVENT = 'deconz_events'
DATA_DECONZ_ID = 'deconz_entities'
5 changes: 5 additions & 0 deletions homeassistant/components/scene/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ async def async_setup_entry(hass, entry):
return await hass.data[DOMAIN].async_setup_entry(entry)


async def async_unload_entry(hass, entry):
"""Unload a config entry."""
return await hass.data[DOMAIN].async_unload_entry(entry)


class Scene(Entity):
"""A scene is a group of entities and the states we want them to be."""

Expand Down
5 changes: 5 additions & 0 deletions homeassistant/components/sensor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,8 @@ async def async_setup(hass, config):
async def async_setup_entry(hass, entry):
"""Setup a config entry."""
return await hass.data[DOMAIN].async_setup_entry(entry)


async def async_unload_entry(hass, entry):
"""Unload a config entry."""
return await hass.data[DOMAIN].async_unload_entry(entry)
4 changes: 2 additions & 2 deletions homeassistant/components/sensor/deconz.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
https://home-assistant.io/components/sensor.deconz/
"""
from homeassistant.components.deconz import (
DOMAIN as DATA_DECONZ, DATA_DECONZ_ID)
DOMAIN as DATA_DECONZ, DATA_DECONZ_EVENT, DATA_DECONZ_ID)
from homeassistant.const import (
ATTR_BATTERY_LEVEL, ATTR_VOLTAGE, CONF_EVENT, CONF_ID)
from homeassistant.core import EventOrigin, callback
Expand Down Expand Up @@ -35,7 +35,7 @@ async def async_setup_entry(hass, config_entry, async_add_devices):
for sensor in sensors.values():
if sensor and sensor.type in DECONZ_SENSOR:
if sensor.type in DECONZ_REMOTE:
DeconzEvent(hass, sensor)
hass.data[DATA_DECONZ_EVENT].append(DeconzEvent(hass, sensor))

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@balloob do you want me to move the creation of the events and the class definition to be created by the setup entry method instead?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since it's just firing events, it should indeed be handled at the component level. It should not be done in the sensor platform.

if sensor.battery:
entities.append(DeconzBattery(sensor))
else:
Expand Down