Skip to content

Commit

Permalink
Fix: update the ip address if it changed
Browse files Browse the repository at this point in the history
* Before that if the ip changed it won't update the ip because it will only if check the device ID if it exists in skip.
  • Loading branch information
xZetsubou committed Jan 5, 2024
1 parent 8f3ffe1 commit 452cedc
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions custom_components/localtuya/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,13 @@ def datagram_received(self, data, addr):

def device_found(self, device):
"""Discover a new device."""
if device.get("gwId") not in self.devices:
self.devices[device.get("gwId")] = device
gwid, ip = device.get("gwId"), device.get("ip")
# If device found but the ip changed.
if gwid in self.devices and (self.devices[gwid].get("ip") != ip):
self.devices.pop(gwid)

if gwid not in self.devices:
self.devices[gwid] = device
# Sort devices by ip.
sort_devices = sorted(
self.devices.items(), key=lambda i: inet_aton(i[1].get("ip", "0"))
Expand Down

0 comments on commit 452cedc

Please sign in to comment.