Skip to content

Commit 1fe66ee

Browse files
committed
Add possibility to update localkey for fake gateway fails. rospogrigio#194
1 parent ea137b1 commit 1fe66ee

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

custom_components/localtuya/coordinator.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ async def _make_connection(self):
223223
if self._fake_gateway:
224224
self.warning(f"Failed to use {name} as gateway.")
225225
await self.abort_connect()
226+
update_localkey = True
226227

227228
if self._interface is not None:
228229
# Attempt to restore status for all entities that need to first set
@@ -308,6 +309,8 @@ async def close(self):
308309
async def update_local_key(self):
309310
"""Retrieve updated local_key from Cloud API and update the config_entry."""
310311
dev_id = self._device_config.id
312+
name = self._device_config.name
313+
311314
cloud_api = self._hass_entry.cloud_data
312315
await cloud_api.async_get_devices_list()
313316
discovery = self._hass.data[DOMAIN].get(DATA_DISCOVERY)
@@ -330,21 +333,22 @@ async def update_local_key(self):
330333

331334
# Update Gateway ID and IP
332335
if new_gw := get_gateway_by_deviceid(dev_id, cloud_devs):
336+
self.info(f"Updated {name} gateway ID to: {new_gw.id}")
333337
new_data[CONF_DEVICES][dev_id][CONF_GATEWAY_ID] = new_gw.id
334-
self.info(f"Updated {dev_id} gateway ID to: {new_gw.id}")
338+
335339
if discovery and (local_gw := discovery.devices.get(new_gw.id)):
336340
new_ip = local_gw.get(CONF_TUYA_IP, self._device_config.host)
337341
new_data[CONF_DEVICES][dev_id][CONF_HOST] = new_ip
338-
self.info(f"Updated {dev_id} IP to: {new_ip}")
342+
self.info(f"Updated {name} IP to: {new_ip}")
339343

340-
self.info(f"Updated informations for sub-device {dev_id}.")
344+
self.info(f"Updated informations for sub-device {name}.")
341345

342346
new_data[CONF_DEVICES][dev_id][CONF_LOCAL_KEY] = self._local_key
343347
new_data[ATTR_UPDATED_AT] = str(int(time.time() * 1000))
344348
self._hass.config_entries.async_update_entry(
345349
self._config_entry, data=new_data
346350
)
347-
self.info(f"local_key updated for device {dev_id}.")
351+
self.info(f"local_key updated for device {name}.")
348352

349353
async def set_values(self):
350354
"""Send self._pending_status payload to device."""

0 commit comments

Comments
 (0)