Don't poll entities for unavailable ZHA devices (#39756)
* Don't poll entities for unavailable ZHA devices * Update homeassistant/components/zha/entity.py Co-authored-by: Bas Nijholt <basnijholt@gmail.com> * cleanup after accepting suggestion Co-authored-by: Bas Nijholt <basnijholt@gmail.com>
This commit is contained in:
parent
36a1877cbd
commit
be8aa16170
3 changed files with 15 additions and 8 deletions
|
@ -202,9 +202,13 @@ class ZhaEntity(BaseZhaEntity, RestoreEntity):
|
||||||
|
|
||||||
async def async_update(self) -> None:
|
async def async_update(self) -> None:
|
||||||
"""Retrieve latest state."""
|
"""Retrieve latest state."""
|
||||||
for channel in self.cluster_channels.values():
|
tasks = [
|
||||||
if hasattr(channel, "async_update"):
|
channel.async_update()
|
||||||
await channel.async_update()
|
for channel in self.cluster_channels.values()
|
||||||
|
if hasattr(channel, "async_update")
|
||||||
|
]
|
||||||
|
if tasks:
|
||||||
|
await asyncio.gather(*tasks)
|
||||||
|
|
||||||
|
|
||||||
class ZhaGroupEntity(BaseZhaEntity):
|
class ZhaGroupEntity(BaseZhaEntity):
|
||||||
|
|
|
@ -410,13 +410,10 @@ class Light(BaseLight, ZhaEntity):
|
||||||
if "effect" in last_state.attributes:
|
if "effect" in last_state.attributes:
|
||||||
self._effect = last_state.attributes["effect"]
|
self._effect = last_state.attributes["effect"]
|
||||||
|
|
||||||
async def async_update(self):
|
|
||||||
"""Attempt to retrieve on off state from the light."""
|
|
||||||
await super().async_update()
|
|
||||||
await self.async_get_state()
|
|
||||||
|
|
||||||
async def async_get_state(self, from_cache=True):
|
async def async_get_state(self, from_cache=True):
|
||||||
"""Attempt to retrieve on off state from the light."""
|
"""Attempt to retrieve on off state from the light."""
|
||||||
|
if not from_cache and not self.available:
|
||||||
|
return
|
||||||
self.debug("polling current state - from cache: %s", from_cache)
|
self.debug("polling current state - from cache: %s", from_cache)
|
||||||
if self._on_off_channel:
|
if self._on_off_channel:
|
||||||
state = await self._on_off_channel.get_attribute_value(
|
state = await self._on_off_channel.get_attribute_value(
|
||||||
|
|
|
@ -210,6 +210,12 @@ class ElectricalMeasurement(Sensor):
|
||||||
return round(value, self._decimals)
|
return round(value, self._decimals)
|
||||||
return round(value)
|
return round(value)
|
||||||
|
|
||||||
|
async def async_update(self) -> None:
|
||||||
|
"""Retrieve latest state."""
|
||||||
|
if not self.available:
|
||||||
|
return
|
||||||
|
await super().async_update()
|
||||||
|
|
||||||
|
|
||||||
@STRICT_MATCH(generic_ids=CHANNEL_ST_HUMIDITY_CLUSTER)
|
@STRICT_MATCH(generic_ids=CHANNEL_ST_HUMIDITY_CLUSTER)
|
||||||
@STRICT_MATCH(channel_names=CHANNEL_HUMIDITY)
|
@STRICT_MATCH(channel_names=CHANNEL_HUMIDITY)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue