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
|
@ -6,7 +6,8 @@ https://home-assistant.io/components/sensor.deconz/
|
|||
"""
|
||||
import asyncio
|
||||
|
||||
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, CONF_EVENT, CONF_ID
|
||||
from homeassistant.core import EventOrigin, callback
|
||||
from homeassistant.helpers.entity import Entity
|
||||
|
@ -25,7 +26,7 @@ def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
|
|||
return
|
||||
|
||||
from pydeconz.sensor import DECONZ_SENSOR, SWITCH as DECONZ_REMOTE
|
||||
sensors = hass.data[DECONZ_DATA].sensors
|
||||
sensors = hass.data[DATA_DECONZ].sensors
|
||||
entities = []
|
||||
|
||||
for key in sorted(sensors.keys(), key=int):
|
||||
|
@ -51,6 +52,7 @@ class DeconzSensor(Entity):
|
|||
def async_added_to_hass(self):
|
||||
"""Subscribe to 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):
|
||||
|
@ -127,6 +129,7 @@ class DeconzBattery(Entity):
|
|||
def async_added_to_hass(self):
|
||||
"""Subscribe to sensors events."""
|
||||
self._device.register_async_callback(self.async_update_callback)
|
||||
self.hass.data[DATA_DECONZ_ID][self.entity_id] = self._device.deconz_id
|
||||
|
||||
@callback
|
||||
def async_update_callback(self, reason):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue