Skip to content

Commit

Permalink
Simplified async_update_callback() processing for Climate, Fan
Browse files Browse the repository at this point in the history
  • Loading branch information
nao-pon committed Feb 16, 2024
1 parent ac8f59b commit 3f926e6
Show file tree
Hide file tree
Showing 9 changed files with 12 additions and 21 deletions.
2 changes: 1 addition & 1 deletion custom_components/echonetlite/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ async def async_update_data(self, kwargs):
self._update_data.update(update_data)
return self._update_data

async def async_update_callback(self, isPush=False):
async def async_update_callback(self, isPush: bool = False):
await self.async_update_data(kwargs={"no_request": True})
for update_func in self._update_callbacks:
await update_func(isPush)
Expand Down
9 changes: 2 additions & 7 deletions custom_components/echonetlite/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ async def async_added_to_hass(self):
self._connector.add_update_option_listener(self.update_option_listener)
self._connector.register_async_update_callbacks(self.async_update_callback)

async def async_update_callback(self, isPush=False):
async def async_update_callback(self, isPush: bool = False):
changed = (
self._olddata != self._connector._update_data
or self._attr_available != self._server_state["available"]
Expand All @@ -368,12 +368,7 @@ async def async_update_callback(self, isPush=False):
self._olddata = self._connector._update_data.copy()
self._attr_available = self._server_state["available"]
self._set_attrs()
self.async_schedule_update_ha_state(_force)
if isPush:
try:
await self._connector.async_update()
except TimeoutError:
pass
self.async_schedule_update_ha_state(_force | isPush)

def update_option_listener(self):
"""list of available fan modes."""
Expand Down
10 changes: 3 additions & 7 deletions custom_components/echonetlite/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,21 +188,17 @@ async def async_added_to_hass(self):
self._connector.register_async_update_callbacks(self.async_update_callback)
self._connector.add_update_option_listener(self.update_option_listener)

async def async_update_callback(self, isPush=False):
async def async_update_callback(self, isPush: bool = False):
changed = (
self._olddata != self._connector._update_data
or self._attr_available != self._server_state["available"]
)
if changed:
_force = bool(not self._attr_available and self._server_state["available"])
self._olddata = self._connector._update_data.copy()
self._attr_available = self._server_state["available"]
self._set_attrs()
self.async_schedule_update_ha_state()
if isPush:
try:
await self._connector.async_update()
except TimeoutError:
pass
self.async_schedule_update_ha_state(_force | isPush)

def update_option_listener(self):
_should_poll = (
Expand Down
2 changes: 1 addition & 1 deletion custom_components/echonetlite/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ async def async_added_to_hass(self):
self._connector.add_update_option_listener(self.update_option_listener)
self._connector.register_async_update_callbacks(self.async_update_callback)

async def async_update_callback(self, isPush=False):
async def async_update_callback(self, isPush: bool = False):
changed = (
self._olddata != self._connector._update_data
or self._attr_available != self._server_state["available"]
Expand Down
2 changes: 1 addition & 1 deletion custom_components/echonetlite/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ async def async_added_to_hass(self):
self._connector.add_update_option_listener(self.update_option_listener)
self._connector.register_async_update_callbacks(self.async_update_callback)

async def async_update_callback(self, isPush=False):
async def async_update_callback(self, isPush: bool = False):
new_val = self.get_value()
changed = (
self._attr_native_value != new_val
Expand Down
2 changes: 1 addition & 1 deletion custom_components/echonetlite/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ async def async_added_to_hass(self):
self._connector.add_update_option_listener(self.update_option_listener)
self._connector.register_async_update_callbacks(self.async_update_callback)

async def async_update_callback(self, isPush=False):
async def async_update_callback(self, isPush: bool = False):
new_val = self._connector._update_data.get(self._code)
changed = (
new_val is not None and self._attr_current_option != new_val
Expand Down
2 changes: 1 addition & 1 deletion custom_components/echonetlite/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ async def async_added_to_hass(self):
self._connector.add_update_option_listener(self.update_option_listener)
self._connector.register_async_update_callbacks(self.async_update_callback)

async def async_update_callback(self, isPush=False):
async def async_update_callback(self, isPush: bool = False):
new_val = self._connector._update_data.get(self._op_code)
if "dict_key" in self._sensor_attributes:
if hasattr(new_val, "get"):
Expand Down
2 changes: 1 addition & 1 deletion custom_components/echonetlite/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ async def async_added_to_hass(self):
self._connector.add_update_option_listener(self.update_option_listener)
self._connector.register_async_update_callbacks(self.async_update_callback)

async def async_update_callback(self, isPush=False):
async def async_update_callback(self, isPush: bool = False):
new_val = self._connector._update_data[self._code] in self._on_vals
changed = (
self._attr_is_on != new_val
Expand Down
2 changes: 1 addition & 1 deletion custom_components/echonetlite/time.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ async def async_added_to_hass(self):
self._connector.add_update_option_listener(self.update_option_listener)
self._connector.register_async_update_callbacks(self.async_update_callback)

async def async_update_callback(self, isPush=False):
async def async_update_callback(self, isPush: bool = False):
new_val = self.get_time()
changed = (
self._attr_native_value != new_val
Expand Down

0 comments on commit 3f926e6

Please sign in to comment.