mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Update sensor state before adding device (#14357)
This commit is contained in:
parent
8fcf085829
commit
ef8fc1f201
@ -25,7 +25,7 @@ def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
|
|||||||
return
|
return
|
||||||
|
|
||||||
sensor = yield from make_sensor(discovery_info)
|
sensor = yield from make_sensor(discovery_info)
|
||||||
async_add_devices([sensor])
|
async_add_devices([sensor], update_before_add=True)
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
@ -61,6 +61,11 @@ class Sensor(zha.Entity):
|
|||||||
value_attribute = 0
|
value_attribute = 0
|
||||||
min_reportable_change = 1
|
min_reportable_change = 1
|
||||||
|
|
||||||
|
@property
|
||||||
|
def should_poll(self) -> bool:
|
||||||
|
"""State gets pushed from device."""
|
||||||
|
return False
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self) -> str:
|
def state(self) -> str:
|
||||||
"""Return the state of the entity."""
|
"""Return the state of the entity."""
|
||||||
@ -75,6 +80,14 @@ class Sensor(zha.Entity):
|
|||||||
self._state = value
|
self._state = value
|
||||||
self.async_schedule_update_ha_state()
|
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):
|
class TemperatureSensor(Sensor):
|
||||||
"""ZHA temperature sensor."""
|
"""ZHA temperature sensor."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user