Skip to content

Commit

Permalink
Use dispatcher_send instead of async on dispatch status
Browse files Browse the repository at this point in the history
  • Loading branch information
xZetsubou committed Jun 7, 2024
1 parent d95ae5e commit b0a806b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
11 changes: 5 additions & 6 deletions custom_components/localtuya/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def is_connecting(self):
@property
def connected(self):
"""Return if connected to device."""
return self._interface is not None
return self._interface and self._interface.is_connected

@property
def is_subdevice(self):
Expand Down Expand Up @@ -396,7 +396,7 @@ async def _async_refresh(self, _now):

def _dispatch_status(self):
signal = f"localtuya_{self._device_config.id}"
async_dispatcher_send(self._hass, signal, self._status)
dispatcher_send(self._hass, signal, self._status)

def _handle_event(self, old_status: dict, new_status: dict, deviceID=None):
"""Handle events in HA when devices updated."""
Expand Down Expand Up @@ -434,17 +434,16 @@ def fire_event(event, data: dict):

def _shutdown_entities(self, now=None):
"""Shutdown device entities"""
if self.is_sleep:
if self.is_sleep or self.connected:
return

if self.is_subdevice:
self.warning(f"Sub-device disconnected from: {self._device_config.host}")
else:
self.warning(f"Disconnected: waiting for discovery broadcast")

if not self.connected:
signal = f"localtuya_{self._device_config.id}"
dispatcher_send(self._hass, signal, None)
signal = f"localtuya_{self._device_config.id}"
dispatcher_send(self._hass, signal, None)

@callback
def status_updated(self, status: dict):
Expand Down
2 changes: 1 addition & 1 deletion custom_components/localtuya/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
"iot_class": "local_push",
"issue_tracker": "https://github.com/xZetsubou/hass-localtuya/issues",
"requirements": [],
"version": "2024.5.0"
"version": "2024.6.0"
}

0 comments on commit b0a806b

Please sign in to comment.