UniFi - Handle disabled switches (#29824)
This commit is contained in:
parent
e28fd16c84
commit
47e5142ddb
1 changed files with 19 additions and 14 deletions
|
@ -73,12 +73,13 @@ def update_items(controller, async_add_entities, switches, switches_off):
|
|||
block_client_id = f"block-{client_id}"
|
||||
|
||||
if block_client_id in switches:
|
||||
LOGGER.debug(
|
||||
"Updating UniFi block switch %s (%s)",
|
||||
switches[block_client_id].entity_id,
|
||||
switches[block_client_id].client.mac,
|
||||
)
|
||||
switches[block_client_id].async_schedule_update_ha_state()
|
||||
if switches[block_client_id].enabled:
|
||||
LOGGER.debug(
|
||||
"Updating UniFi block switch %s (%s)",
|
||||
switches[block_client_id].entity_id,
|
||||
switches[block_client_id].client.mac,
|
||||
)
|
||||
switches[block_client_id].async_schedule_update_ha_state()
|
||||
continue
|
||||
|
||||
if client_id not in controller.api.clients_all:
|
||||
|
@ -87,7 +88,6 @@ def update_items(controller, async_add_entities, switches, switches_off):
|
|||
client = controller.api.clients_all[client_id]
|
||||
switches[block_client_id] = UniFiBlockClientSwitch(client, controller)
|
||||
new_switches.append(switches[block_client_id])
|
||||
LOGGER.debug("New UniFi Block switch %s (%s)", client.hostname, client.mac)
|
||||
|
||||
# control POE
|
||||
for client_id in controller.api.clients:
|
||||
|
@ -95,12 +95,13 @@ def update_items(controller, async_add_entities, switches, switches_off):
|
|||
poe_client_id = f"poe-{client_id}"
|
||||
|
||||
if poe_client_id in switches:
|
||||
LOGGER.debug(
|
||||
"Updating UniFi POE switch %s (%s)",
|
||||
switches[poe_client_id].entity_id,
|
||||
switches[poe_client_id].client.mac,
|
||||
)
|
||||
switches[poe_client_id].async_schedule_update_ha_state()
|
||||
if switches[poe_client_id].enabled:
|
||||
LOGGER.debug(
|
||||
"Updating UniFi POE switch %s (%s)",
|
||||
switches[poe_client_id].entity_id,
|
||||
switches[poe_client_id].client.mac,
|
||||
)
|
||||
switches[poe_client_id].async_schedule_update_ha_state()
|
||||
continue
|
||||
|
||||
client = controller.api.clients[client_id]
|
||||
|
@ -138,7 +139,6 @@ def update_items(controller, async_add_entities, switches, switches_off):
|
|||
|
||||
switches[poe_client_id] = UniFiPOEClientSwitch(client, controller)
|
||||
new_switches.append(switches[poe_client_id])
|
||||
LOGGER.debug("New UniFi POE switch %s (%s)", client.hostname, client.mac)
|
||||
|
||||
if new_switches:
|
||||
async_add_entities(new_switches)
|
||||
|
@ -179,6 +179,7 @@ class UniFiPOEClientSwitch(UniFiClient, SwitchDevice, RestoreEntity):
|
|||
|
||||
async def async_added_to_hass(self):
|
||||
"""Call when entity about to be added to Home Assistant."""
|
||||
LOGGER.debug("New UniFi POE switch %s (%s)", self.name, self.client.mac)
|
||||
state = await self.async_get_last_state()
|
||||
|
||||
if state is None:
|
||||
|
@ -252,6 +253,10 @@ class UniFiPOEClientSwitch(UniFiClient, SwitchDevice, RestoreEntity):
|
|||
class UniFiBlockClientSwitch(UniFiClient, SwitchDevice):
|
||||
"""Representation of a blockable client."""
|
||||
|
||||
async def async_added_to_hass(self):
|
||||
"""Call when entity about to be added to Home Assistant."""
|
||||
LOGGER.debug("New UniFi Block switch %s (%s)", self.name, self.client.mac)
|
||||
|
||||
@property
|
||||
def unique_id(self):
|
||||
"""Return a unique identifier for this switch."""
|
||||
|
|
Loading…
Add table
Reference in a new issue