Update sensor state before adding device (#14357)
parent
8fcf085829
commit
ef8fc1f201
|
@ -25,7 +25,7 @@ def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
|
|||
return
|
||||
|
||||
sensor = yield from make_sensor(discovery_info)
|
||||
async_add_devices([sensor])
|
||||
async_add_devices([sensor], update_before_add=True)
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
|
@ -61,6 +61,11 @@ class Sensor(zha.Entity):
|
|||
value_attribute = 0
|
||||
min_reportable_change = 1
|
||||
|
||||
@property
|
||||
def should_poll(self) -> bool:
|
||||
"""State gets pushed from device."""
|
||||
return False
|
||||
|
||||
@property
|
||||
def state(self) -> str:
|
||||
"""Return the state of the entity."""
|
||||
|
@ -75,6 +80,14 @@ class Sensor(zha.Entity):
|
|||
self._state = value
|
||||
self.async_schedule_update_ha_state()
|
||||
|
||||
async def async_update(self):
|
||||
"""Retrieve latest state."""
|
||||
result = await zha.safe_read(
|
||||
list(self._in_clusters.values())[0],
|
||||
[self.value_attribute]
|
||||
)
|
||||
self._state = result.get(self.value_attribute, self._state)
|
||||
|
||||
|
||||
class TemperatureSensor(Sensor):
|
||||
"""ZHA temperature sensor."""
|
||||
|
|
Loading…
Reference in New Issue