ZHA: remove unused 'from_cache' argument from 'async_get_state' and add 'async_update' (#42413)

* remove unused 'from_cache' argument from 'async_get_state'

* define async_update to use homeassistant.update_entity
This commit is contained in:
Bas Nijholt 2020-11-29 20:47:46 +01:00 committed by GitHub
parent 54425ae0f3
commit 6eeb9c0e49
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -280,7 +280,7 @@ class BaseLight(LogMixin, light.LightEntity):
0x0, 0x0,
0x0, 0x0,
0x0, 0x0,
0x0, # update action only, action off, no dir,time,hue 0x0, # update action only, action off, no dir, time, hue
) )
t_log["color_loop_set"] = result t_log["color_loop_set"] = result
self._effect = None self._effect = None
@ -421,20 +421,20 @@ 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_get_state(self, from_cache=True): async def async_get_state(self):
"""Attempt to retrieve on off state from the light.""" """Attempt to retrieve the state from the light."""
if not from_cache and not self.available: if not self.available:
return return
self.debug("polling current state - from cache: %s", from_cache) self.debug("polling current state")
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(
"on_off", from_cache=from_cache "on_off", from_cache=False
) )
if state is not None: if state is not None:
self._state = state self._state = state
if self._level_channel: if self._level_channel:
level = await self._level_channel.get_attribute_value( level = await self._level_channel.get_attribute_value(
"current_level", from_cache=from_cache "current_level", from_cache=False
) )
if level is not None: if level is not None:
self._brightness = level self._brightness = level
@ -447,7 +447,7 @@ class Light(BaseLight, ZhaEntity):
] ]
results = await self._color_channel.get_attributes( results = await self._color_channel.get_attributes(
attributes, from_cache=from_cache attributes, from_cache=False
) )
color_temp = results.get("color_temperature") color_temp = results.get("color_temperature")
@ -468,15 +468,19 @@ class Light(BaseLight, ZhaEntity):
else: else:
self._effect = None self._effect = None
async def async_update(self):
"""Update to the latest state."""
await self.async_get_state()
async def _refresh(self, time): async def _refresh(self, time):
"""Call async_get_state at an interval.""" """Call async_get_state at an interval."""
await self.async_get_state(from_cache=False) await self.async_get_state()
self.async_write_ha_state() self.async_write_ha_state()
async def _maybe_force_refresh(self, signal): async def _maybe_force_refresh(self, signal):
"""Force update the state if the signal contains the entity id for this entity.""" """Force update the state if the signal contains the entity id for this entity."""
if self.entity_id in signal["entity_ids"]: if self.entity_id in signal["entity_ids"]:
await self.async_get_state(from_cache=False) await self.async_get_state()
self.async_write_ha_state() self.async_write_ha_state()