From 6eeb9c0e49a1453c8c9c22975be76826485248bc Mon Sep 17 00:00:00 2001 From: Bas Nijholt Date: Sun, 29 Nov 2020 20:47:46 +0100 Subject: [PATCH] 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 --- homeassistant/components/zha/light.py | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/homeassistant/components/zha/light.py b/homeassistant/components/zha/light.py index 1f310c32aab..6b3a39d0926 100644 --- a/homeassistant/components/zha/light.py +++ b/homeassistant/components/zha/light.py @@ -280,7 +280,7 @@ class BaseLight(LogMixin, light.LightEntity): 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 self._effect = None @@ -421,20 +421,20 @@ class Light(BaseLight, ZhaEntity): if "effect" in last_state.attributes: self._effect = last_state.attributes["effect"] - async def async_get_state(self, from_cache=True): - """Attempt to retrieve on off state from the light.""" - if not from_cache and not self.available: + async def async_get_state(self): + """Attempt to retrieve the state from the light.""" + if not self.available: return - self.debug("polling current state - from cache: %s", from_cache) + self.debug("polling current state") if self._on_off_channel: 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: self._state = state if self._level_channel: level = await self._level_channel.get_attribute_value( - "current_level", from_cache=from_cache + "current_level", from_cache=False ) if level is not None: self._brightness = level @@ -447,7 +447,7 @@ class Light(BaseLight, ZhaEntity): ] results = await self._color_channel.get_attributes( - attributes, from_cache=from_cache + attributes, from_cache=False ) color_temp = results.get("color_temperature") @@ -468,15 +468,19 @@ class Light(BaseLight, ZhaEntity): else: self._effect = None + async def async_update(self): + """Update to the latest state.""" + await self.async_get_state() + async def _refresh(self, time): """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() async def _maybe_force_refresh(self, signal): """Force update the state if the signal contains the entity id for this entity.""" 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()