Skip to content

Commit

Permalink
feat: poll device states per 10s to improve responsiveness
Browse files Browse the repository at this point in the history
  • Loading branch information
stackia committed Mar 27, 2024
1 parent db6fa5d commit 5338b7e
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion custom_components/deye_dehumidifier/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,21 @@ async def async_added_to_hass(self) -> None:
self.update_device_state,
)
)

self.poll_device_state()
self.async_on_remove(self.cancel_polling)

@callback
def poll_device_state(self, now: datetime | None = None) -> None:
"""
Some Deye devices have a very long heartbeat period. So polling is still necessary to get the latest state as
quickly as possible.
"""
self._mqtt_client.publish_command(
self._device["product_id"],
self._device["device_id"],
QUERY_DEVICE_STATE_COMMAND,
)
self.cancel_polling = async_call_later(self.hass, 10, self.poll_device_state)

def mute_subscription_for_a_while(self) -> None:
"""Mute subscription for a while to avoid state bouncing."""
Expand Down

0 comments on commit 5338b7e

Please sign in to comment.