Skip to content

Commit

Permalink
Revert Heartbeat logic to upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Albu committed Apr 3, 2023
1 parent 5e3b619 commit b8e14c2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 3 additions & 1 deletion custom_components/localtuya/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@ async def _make_connection(self):
status = await self._interface.status()
if status is None:
raise Exception("Failed to retrieve status")


self._interface.start_heartbeat()
self.status_updated(status)

if self._disconnect_task is not None:
Expand Down Expand Up @@ -340,6 +341,7 @@ async def _make_connection(self):
is_gateway=True,
)

self._interface.start_heartbeat()
# Re-add and get status of previously added sub-devices
# Note this assumes the gateway device has not been tear down
for subitem in self._sub_devices.items():
Expand Down
7 changes: 5 additions & 2 deletions custom_components/localtuya/pytuya/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,11 @@ def _status_update(self, msg):

def connection_made(self, transport):
"""Did connect to the device."""
self.transport = transport
self.on_connected.set_result(True)

def start_heartbeat(self):
"""Start the heartbeat transmissions with the device."""

async def heartbeat_loop():
"""Continuously send heart beat updates."""
Expand All @@ -712,8 +717,6 @@ async def heartbeat_loop():
self.transport = None
transport.close()

self.transport = transport
self.on_connected.set_result(True)
self.heartbeater = self.loop.create_task(heartbeat_loop())

def data_received(self, data):
Expand Down

0 comments on commit b8e14c2

Please sign in to comment.