Improve service by allowing to reference entity id instead of deconz id (#11862)
* Improve service by allowing to reference entity id instead of deconz id * Change from having access to full entities to only store entity id together with deconz id * Don't use eval, there is a dict type for voluptuous * Use entity registry instead of keeping a local registry over entity ids * Removed old code * Add test for get_entry * Bump dependency to v28 Fixed call to protected member * Use chain to iterate over dict values * Cleanup * Fix hound comment * Cleanup * Follow refactoring of entity * Revert to using a local registry * Remove unused import * self.hass is automatically available when entity is registered in hass
This commit is contained in:
parent
a4944da68f
commit
8bff813014
7 changed files with 46 additions and 17 deletions
|
@ -7,7 +7,8 @@ https://home-assistant.io/components/binary_sensor.deconz/
|
|||
import asyncio
|
||||
|
||||
from homeassistant.components.binary_sensor import BinarySensorDevice
|
||||
from homeassistant.components.deconz import DOMAIN as DECONZ_DATA
|
||||
from homeassistant.components.deconz import (
|
||||
DOMAIN as DATA_DECONZ, DATA_DECONZ_ID)
|
||||
from homeassistant.const import ATTR_BATTERY_LEVEL
|
||||
from homeassistant.core import callback
|
||||
|
||||
|
@ -21,7 +22,7 @@ def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
|
|||
return
|
||||
|
||||
from pydeconz.sensor import DECONZ_BINARY_SENSOR
|
||||
sensors = hass.data[DECONZ_DATA].sensors
|
||||
sensors = hass.data[DATA_DECONZ].sensors
|
||||
entities = []
|
||||
|
||||
for key in sorted(sensors.keys(), key=int):
|
||||
|
@ -42,6 +43,7 @@ class DeconzBinarySensor(BinarySensorDevice):
|
|||
def async_added_to_hass(self):
|
||||
"""Subscribe sensors events."""
|
||||
self._sensor.register_async_callback(self.async_update_callback)
|
||||
self.hass.data[DATA_DECONZ_ID][self.entity_id] = self._sensor.deconz_id
|
||||
|
||||
@callback
|
||||
def async_update_callback(self, reason):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue