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