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
pull/43754/head
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
1 changed files with 14 additions and 10 deletions

View File

@ -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()