Skip to content

Commit e856f89

Browse files
committed
adding two lines that handle reconnection if api is lost, but entity is known
1 parent 896ecb4 commit e856f89

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

custom_components/powersensor/PowersensorDiscoveryService.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,7 @@ async def _async_get_service_info(self, zc, type_, name):
9292

9393

9494
def __add_plug(self, zc, type_, name):
95-
_LOGGER.error('Before calling get_service_info')
9695
info = zc.get_service_info(type_, name)
97-
_LOGGER.error('After calling get_service_info')
9896

9997
if info:
10098
self._plugs[name] = {'type': type_,

custom_components/powersensor/PowersensorMessageDispatacher.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,14 @@ async def _monitor_plug_queue(self):
7474
while not self._stop_task and self._plug_added_queue:
7575
queue_snapshot = await self._plug_added_queue.copy()
7676
for mac_address, host, port, name in queue_snapshot:
77+
#@todo: maybe better to query the entity registry?
7778
if not self._plug_has_been_seen(mac_address, name):
7879
async_dispatcher_send(self._hass, f"{DOMAIN}_create_plug",
7980
mac_address, host, port, name)
81+
elif mac_address in self._known_plugs and not mac_address in self.plugs:
82+
_LOGGER.info(f"Plug with mac {mac_address} is known, but API is missing."
83+
f"Reconnecting without requesting entity creation...")
84+
self._create_api(mac_address,host, port, name)
8085
else:
8186
_LOGGER.debug(f"Plug: {mac_address} has already been created as an entity in Home Assistant."
8287
f" Skipping and flushing from queue.")

0 commit comments

Comments
 (0)