UniFi - Handle disabled switches (#29824)

This commit is contained in:
Robert Svensson 2019-12-10 20:04:48 +01:00 committed by Paulus Schoutsen
parent 4dd1c51186
commit 2fb36d3dea

View File

@ -74,12 +74,13 @@ 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:
LOGGER.debug( if switches[block_client_id].enabled:
"Updating UniFi block switch %s (%s)", LOGGER.debug(
switches[block_client_id].entity_id, "Updating UniFi block switch %s (%s)",
switches[block_client_id].client.mac, switches[block_client_id].entity_id,
) switches[block_client_id].client.mac,
switches[block_client_id].async_schedule_update_ha_state() )
switches[block_client_id].async_schedule_update_ha_state()
continue continue
if client_id not in controller.api.clients_all: if client_id not in controller.api.clients_all:
@ -88,7 +89,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:
@ -96,12 +96,13 @@ 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:
LOGGER.debug( if switches[poe_client_id].enabled:
"Updating UniFi POE switch %s (%s)", LOGGER.debug(
switches[poe_client_id].entity_id, "Updating UniFi POE switch %s (%s)",
switches[poe_client_id].client.mac, switches[poe_client_id].entity_id,
) switches[poe_client_id].client.mac,
switches[poe_client_id].async_schedule_update_ha_state() )
switches[poe_client_id].async_schedule_update_ha_state()
continue continue
client = controller.api.clients[client_id] client = controller.api.clients[client_id]
@ -139,7 +140,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)
@ -180,6 +180,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:
@ -263,6 +264,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."""