Remove unneeded guards from (async_)add_entities call (#80471)

This commit is contained in:
Franck Nijhof 2022-10-17 21:11:58 +02:00 committed by GitHub
parent ebf73f41ba
commit a8f1cc0d33
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
66 changed files with 74 additions and 148 deletions

View file

@ -84,8 +84,7 @@ async def async_setup_entry(
unique_id = f"{config_entry.unique_id} {mode}" unique_id = f"{config_entry.unique_id} {mode}"
entities.append(AemetWeather(name, unique_id, weather_coordinator, mode)) entities.append(AemetWeather(name, unique_id, weather_coordinator, mode))
if entities: async_add_entities(entities, False)
async_add_entities(entities, False)
class AemetWeather(CoordinatorEntity[WeatherUpdateCoordinator], WeatherEntity): class AemetWeather(CoordinatorEntity[WeatherUpdateCoordinator], WeatherEntity):

View file

@ -47,8 +47,7 @@ def add_entities(
new_tracked.append(AsusWrtDevice(router, device)) new_tracked.append(AsusWrtDevice(router, device))
tracked.add(mac) tracked.add(mac)
if new_tracked: async_add_entities(new_tracked)
async_add_entities(new_tracked)
class AsusWrtDevice(ScannerEntity): class AsusWrtDevice(ScannerEntity):

View file

@ -274,8 +274,7 @@ async def async_setup_entry(
) )
entities.extend(device_entities) entities.extend(device_entities)
if entities: async_add_entities(entities)
async_add_entities(entities)
class BondButtonEntity(BondEntity, ButtonEntity): class BondButtonEntity(BondEntity, ButtonEntity):

View file

@ -53,8 +53,7 @@ async def async_setup_entry(
) )
) )
if entities: async_add_entities(entities)
async_add_entities(entities)
class ShutterContactSensor(SHCEntity, BinarySensorEntity): class ShutterContactSensor(SHCEntity, BinarySensorEntity):

View file

@ -36,8 +36,7 @@ async def async_setup_entry(
) )
) )
if entities: async_add_entities(entities)
async_add_entities(entities)
class ShutterControlCover(SHCEntity, CoverEntity): class ShutterControlCover(SHCEntity, CoverEntity):

View file

@ -157,8 +157,7 @@ async def async_setup_entry(
) )
) )
if entities: async_add_entities(entities)
async_add_entities(entities)
class TemperatureSensor(SHCEntity, SensorEntity): class TemperatureSensor(SHCEntity, SensorEntity):

View file

@ -156,8 +156,7 @@ async def async_setup_entry(
) )
) )
if entities: async_add_entities(entities)
async_add_entities(entities)
class SHCSwitch(SHCEntity, SwitchEntity): class SHCSwitch(SHCEntity, SwitchEntity):

View file

@ -50,8 +50,7 @@ async def async_setup_entry(
# device supports the streamer, so assume so if it does support # device supports the streamer, so assume so if it does support
# advanced modes. # advanced modes.
switches.append(DaikinStreamerSwitch(daikin_api)) switches.append(DaikinStreamerSwitch(daikin_api))
if switches: async_add_entities(switches)
async_add_entities(switches)
class DaikinZoneSwitch(SwitchEntity): class DaikinZoneSwitch(SwitchEntity):

View file

@ -55,8 +55,7 @@ async def async_setup_entry(
) )
) )
tracked.add(station[MAC_ADDRESS]) tracked.add(station[MAC_ADDRESS])
if new_entities: async_add_entities(new_entities)
async_add_entities(new_entities)
@callback @callback
def restore_entities() -> None: def restore_entities() -> None:
@ -82,8 +81,7 @@ async def async_setup_entry(
) )
tracked.add(mac_address) tracked.add(mac_address)
if missing: async_add_entities(missing)
async_add_entities(missing)
if device.device and "wifi1" in device.device.features: if device.device and "wifi1" in device.device.features:
restore_entities() restore_entities()

View file

@ -90,8 +90,7 @@ def setup(hass: HomeAssistant, config: ConfigType) -> bool:
order = DominosOrder(order_info, dominos) order = DominosOrder(order_info, dominos)
entities.append(order) entities.append(order)
if entities: component.add_entities(entities)
component.add_entities(entities)
# Return boolean to indicate that initialization was successfully. # Return boolean to indicate that initialization was successfully.
return True return True

View file

@ -31,8 +31,7 @@ def async_setup_entry_base(
added_entities = [] added_entities = []
for device in devices: for device in devices:
added_entities.append(entity_from_device(device, bridge)) added_entities.append(entity_from_device(device, bridge))
if added_entities: async_add_entities(added_entities)
async_add_entities(added_entities)
bridge.register_add_devices(platform, async_add_entities_platform) bridge.register_add_devices(platform, async_add_entities_platform)

View file

@ -148,8 +148,7 @@ def setup_platform(
elif sensor_type == SENSOR_TYPE_WINDOWHANDLE: elif sensor_type == SENSOR_TYPE_WINDOWHANDLE:
entities = [EnOceanWindowHandle(dev_id, dev_name, SENSOR_DESC_WINDOWHANDLE)] entities = [EnOceanWindowHandle(dev_id, dev_name, SENSOR_DESC_WINDOWHANDLE)]
if entities: add_entities(entities)
add_entities(entities)
class EnOceanSensor(EnOceanEntity, RestoreEntity, SensorEntity): class EnOceanSensor(EnOceanEntity, RestoreEntity, SensorEntity):

View file

@ -40,8 +40,7 @@ async def async_setup_entry(
binary_sensor_entity = FirmataBinarySensor(api, config_entry, name, pin) binary_sensor_entity = FirmataBinarySensor(api, config_entry, name, pin)
new_entities.append(binary_sensor_entity) new_entities.append(binary_sensor_entity)
if new_entities: async_add_entities(new_entities)
async_add_entities(new_entities)
class FirmataBinarySensor(FirmataPinEntity, BinarySensorEntity): class FirmataBinarySensor(FirmataPinEntity, BinarySensorEntity):

View file

@ -46,8 +46,7 @@ async def async_setup_entry(
light_entity = FirmataLight(api, config_entry, name, pin) light_entity = FirmataLight(api, config_entry, name, pin)
new_entities.append(light_entity) new_entities.append(light_entity)
if new_entities: async_add_entities(new_entities)
async_add_entities(new_entities)
class FirmataLight(FirmataPinEntity, LightEntity): class FirmataLight(FirmataPinEntity, LightEntity):

View file

@ -40,8 +40,7 @@ async def async_setup_entry(
sensor_entity = FirmataSensor(api, config_entry, name, pin) sensor_entity = FirmataSensor(api, config_entry, name, pin)
new_entities.append(sensor_entity) new_entities.append(sensor_entity)
if new_entities: async_add_entities(new_entities)
async_add_entities(new_entities)
class FirmataSensor(FirmataPinEntity, SensorEntity): class FirmataSensor(FirmataPinEntity, SensorEntity):

View file

@ -42,8 +42,7 @@ async def async_setup_entry(
switch_entity = FirmataSwitch(api, config_entry, name, pin) switch_entity = FirmataSwitch(api, config_entry, name, pin)
new_entities.append(switch_entity) new_entities.append(switch_entity)
if new_entities: async_add_entities(new_entities)
async_add_entities(new_entities)
class FirmataSwitch(FirmataPinEntity, SwitchEntity): class FirmataSwitch(FirmataPinEntity, SwitchEntity):

View file

@ -122,8 +122,7 @@ async def async_setup_entry(
] ]
) )
if flume_entity_list: async_add_entities(flume_entity_list)
async_add_entities(flume_entity_list)
class FlumeNotificationBinarySensor(FlumeEntity, BinarySensorEntity): class FlumeNotificationBinarySensor(FlumeEntity, BinarySensorEntity):

View file

@ -120,8 +120,7 @@ async def async_setup_entry(
] ]
) )
if flume_entity_list: async_add_entities(flume_entity_list)
async_add_entities(flume_entity_list)
class FlumeSensor(FlumeEntity, SensorEntity): class FlumeSensor(FlumeEntity, SensorEntity):

View file

@ -89,8 +89,7 @@ async def async_setup_entry(
FluxSpeedNumber(coordinator, base_unique_id, f"{name} Effect Speed", None) FluxSpeedNumber(coordinator, base_unique_id, f"{name} Effect Speed", None)
) )
if entities: async_add_entities(entities)
async_add_entities(entities)
class FluxSpeedNumber( class FluxSpeedNumber(

View file

@ -81,8 +81,7 @@ async def async_setup_entry(
if FLUX_COLOR_MODE_RGBW in device.color_modes: if FLUX_COLOR_MODE_RGBW in device.color_modes:
entities.append(FluxWhiteChannelSelect(coordinator.device, entry)) entities.append(FluxWhiteChannelSelect(coordinator.device, entry))
if entities: async_add_entities(entities)
async_add_entities(entities)
class FluxConfigAtStartSelect(FluxBaseEntity, SelectEntity): class FluxConfigAtStartSelect(FluxBaseEntity, SelectEntity):

View file

@ -48,8 +48,7 @@ async def async_setup_entry(
FluxMusicSwitch(coordinator, base_unique_id, f"{name} Music", "music") FluxMusicSwitch(coordinator, base_unique_id, f"{name} Music", "music")
) )
if entities: async_add_entities(entities)
async_add_entities(entities)
class FluxSwitch( class FluxSwitch(

View file

@ -48,8 +48,7 @@ def add_entities(
new_tracked.append(FreeboxDevice(router, device)) new_tracked.append(FreeboxDevice(router, device))
tracked.add(mac) tracked.add(mac)
if new_tracked: async_add_entities(new_tracked, True)
async_add_entities(new_tracked, True)
class FreeboxDevice(ScannerEntity): class FreeboxDevice(ScannerEntity):

View file

@ -65,8 +65,7 @@ def _async_add_entities(
new_tracked.append(FritzBoxTracker(avm_wrapper, device)) new_tracked.append(FritzBoxTracker(avm_wrapper, device))
data_fritz.tracked[avm_wrapper.unique_id].add(mac) data_fritz.tracked[avm_wrapper.unique_id].add(mac)
if new_tracked: async_add_entities(new_tracked)
async_add_entities(new_tracked)
class FritzBoxTracker(FritzDeviceBase, ScannerEntity): class FritzBoxTracker(FritzDeviceBase, ScannerEntity):

View file

@ -104,8 +104,7 @@ class FroniusCoordinatorBase(
continue continue
new_entities.append(entity_constructor(self, key, solar_net_id)) new_entities.append(entity_constructor(self, key, solar_net_id))
self.unregistered_keys[solar_net_id].remove(key) self.unregistered_keys[solar_net_id].remove(key)
if new_entities: async_add_entities(new_entities)
async_add_entities(new_entities)
_add_entities_for_unregistered_keys() _add_entities_for_unregistered_keys()
self.solar_net.cleanup_callbacks.append( self.solar_net.cleanup_callbacks.append(

View file

@ -142,8 +142,7 @@ async def async_setup_entry(
elif isinstance(group, AsyncSecurityZoneGroup): elif isinstance(group, AsyncSecurityZoneGroup):
entities.append(HomematicipSecurityZoneSensorGroup(hap, device=group)) entities.append(HomematicipSecurityZoneSensorGroup(hap, device=group))
if entities: async_add_entities(entities)
async_add_entities(entities)
class HomematicipCloudConnectionSensor(HomematicipGenericEntity, BinarySensorEntity): class HomematicipCloudConnectionSensor(HomematicipGenericEntity, BinarySensorEntity):

View file

@ -51,8 +51,7 @@ async def async_setup_entry(
if isinstance(device, AsyncHeatingGroup): if isinstance(device, AsyncHeatingGroup):
entities.append(HomematicipHeatingGroup(hap, device)) entities.append(HomematicipHeatingGroup(hap, device))
if entities: async_add_entities(entities)
async_add_entities(entities)
class HomematicipHeatingGroup(HomematicipGenericEntity, ClimateEntity): class HomematicipHeatingGroup(HomematicipGenericEntity, ClimateEntity):

View file

@ -62,8 +62,7 @@ async def async_setup_entry(
if isinstance(group, AsyncExtendedLinkedShutterGroup): if isinstance(group, AsyncExtendedLinkedShutterGroup):
entities.append(HomematicipCoverShutterGroup(hap, group)) entities.append(HomematicipCoverShutterGroup(hap, group))
if entities: async_add_entities(entities)
async_add_entities(entities)
class HomematicipBlindModule(HomematicipGenericEntity, CoverEntity): class HomematicipBlindModule(HomematicipGenericEntity, CoverEntity):

View file

@ -62,8 +62,7 @@ async def async_setup_entry(
): ):
entities.append(HomematicipDimmer(hap, device)) entities.append(HomematicipDimmer(hap, device))
if entities: async_add_entities(entities)
async_add_entities(entities)
class HomematicipLight(HomematicipGenericEntity, LightEntity): class HomematicipLight(HomematicipGenericEntity, LightEntity):

View file

@ -130,8 +130,7 @@ async def async_setup_entry(
entities.append(HomematicpTemperatureExternalSensorCh2(hap, device)) entities.append(HomematicpTemperatureExternalSensorCh2(hap, device))
entities.append(HomematicpTemperatureExternalSensorDelta(hap, device)) entities.append(HomematicpTemperatureExternalSensorDelta(hap, device))
if entities: async_add_entities(entities)
async_add_entities(entities)
class HomematicipAccesspointDutyCycle(HomematicipGenericEntity, SensorEntity): class HomematicipAccesspointDutyCycle(HomematicipGenericEntity, SensorEntity):

View file

@ -82,8 +82,7 @@ async def async_setup_entry(
if isinstance(group, (AsyncExtendedLinkedSwitchingGroup, AsyncSwitchingGroup)): if isinstance(group, (AsyncExtendedLinkedSwitchingGroup, AsyncSwitchingGroup)):
entities.append(HomematicipGroupSwitch(hap, group)) entities.append(HomematicipGroupSwitch(hap, group))
if entities: async_add_entities(entities)
async_add_entities(entities)
class HomematicipMultiSwitch(HomematicipGenericEntity, SwitchEntity): class HomematicipMultiSwitch(HomematicipGenericEntity, SwitchEntity):

View file

@ -64,8 +64,7 @@ async def async_setup_entry(
entities.append(HomematicipHomeWeather(hap)) entities.append(HomematicipHomeWeather(hap))
if entities: async_add_entities(entities)
async_add_entities(entities)
class HomematicipWeatherSensor(HomematicipGenericEntity, WeatherEntity): class HomematicipWeatherSensor(HomematicipGenericEntity, WeatherEntity):

View file

@ -51,8 +51,7 @@ def add_entities(account: IcloudAccount, async_add_entities, tracked):
new_tracked.append(IcloudTrackerEntity(account, device)) new_tracked.append(IcloudTrackerEntity(account, device))
tracked.add(dev_id) tracked.add(dev_id)
if new_tracked: async_add_entities(new_tracked, True)
async_add_entities(new_tracked, True)
class IcloudTrackerEntity(TrackerEntity): class IcloudTrackerEntity(TrackerEntity):

View file

@ -47,8 +47,7 @@ def add_entities(account, async_add_entities, tracked):
new_tracked.append(IcloudDeviceBatterySensor(account, device)) new_tracked.append(IcloudDeviceBatterySensor(account, device))
tracked.add(dev_id) tracked.add(dev_id)
if new_tracked: async_add_entities(new_tracked, True)
async_add_entities(new_tracked, True)
class IcloudDeviceBatterySensor(SensorEntity): class IcloudDeviceBatterySensor(SensorEntity):

View file

@ -392,5 +392,4 @@ def async_add_insteon_entities(
groups = get_platform_groups(device, platform) groups = get_platform_groups(device, platform)
for group in groups: for group in groups:
new_entities.append(entity_type(device, group)) new_entities.append(entity_type(device, group))
if new_entities: async_add_entities(new_entities)
async_add_entities(new_entities)

View file

@ -154,8 +154,7 @@ async def async_setup_entry(
for key in coordinator.data["sensors"] for key in coordinator.data["sensors"]
if key not in created if key not in created
] ]
if entities: async_add_entities(entities)
async_add_entities(entities)
coordinator.async_add_listener(new_data_received) coordinator.async_add_listener(new_data_received)

View file

@ -64,8 +64,7 @@ async def async_setup_entry(
) )
) )
if restored: async_add_entities(restored)
async_add_entities(restored)
async_dispatcher_connect(hass, router.signal_update, update_from_router) async_dispatcher_connect(hass, router.signal_update, update_from_router)
@ -79,8 +78,7 @@ def update_items(router: KeeneticRouter, async_add_entities, tracked: set[str]):
tracked.add(mac) tracked.add(mac)
new_tracked.append(KeeneticTracker(device, router)) new_tracked.append(KeeneticTracker(device, router))
if new_tracked: async_add_entities(new_tracked)
async_add_entities(new_tracked)
class KeeneticTracker(ScannerEntity): class KeeneticTracker(ScannerEntity):

View file

@ -87,8 +87,7 @@ async def async_setup_entry(
and not new_members_only and not new_members_only
): ):
new_entities.append(Life360DeviceTracker(coordinator, member_id)) new_entities.append(Life360DeviceTracker(coordinator, member_id))
if new_entities: async_add_entities(new_entities)
async_add_entities(new_entities)
process_data(new_members_only=False) process_data(new_members_only=False)
entry.async_on_unload(coordinator.async_add_listener(process_data)) entry.async_on_unload(coordinator.async_add_listener(process_data))

View file

@ -67,8 +67,7 @@ async def async_setup_entry(
), ),
) )
if entities: async_add_entities(entities)
async_add_entities(entities)
class LutronCasetaButton(LutronCasetaDevice, ButtonEntity): class LutronCasetaButton(LutronCasetaDevice, ButtonEntity):

View file

@ -28,8 +28,7 @@ def setup_platform(
if device.is_windowshutter(): if device.is_windowshutter():
devices.append(MaxCubeShutter(handler, device)) devices.append(MaxCubeShutter(handler, device))
if devices: add_entities(devices)
add_entities(devices)
class MaxCubeBinarySensorBase(BinarySensorEntity): class MaxCubeBinarySensorBase(BinarySensorEntity):

View file

@ -60,8 +60,7 @@ def setup_platform(
if device.is_thermostat() or device.is_wallthermostat(): if device.is_thermostat() or device.is_wallthermostat():
devices.append(MaxCubeClimate(handler, device)) devices.append(MaxCubeClimate(handler, device))
if devices: add_entities(devices)
add_entities(devices)
class MaxCubeClimate(ClimateEntity): class MaxCubeClimate(ClimateEntity):

View file

@ -68,8 +68,7 @@ def update_items(
tracked[mac] = MikrotikDataUpdateCoordinatorTracker(device, coordinator) tracked[mac] = MikrotikDataUpdateCoordinatorTracker(device, coordinator)
new_tracked.append(tracked[mac]) new_tracked.append(tracked[mac])
if new_tracked: async_add_entities(new_tracked)
async_add_entities(new_tracked)
class MikrotikDataUpdateCoordinatorTracker( class MikrotikDataUpdateCoordinatorTracker(

View file

@ -88,8 +88,7 @@ def setup_platform(
departure.get(CONF_TIME), departure.get(CONF_TIME),
) )
) )
if sensors: add_entities(sensors, True)
add_entities(sensors, True)
def valid_stations(stations, given_stations): def valid_stations(stations, given_stations):

View file

@ -399,8 +399,7 @@ async def async_setup_entry(
for device_id in entities.values(): for device_id in entities.values():
device_registry.async_remove_device(device_id) device_registry.async_remove_device(device_id)
if new_entities: async_add_entities(new_entities)
async_add_entities(new_entities)
async_dispatcher_connect( async_dispatcher_connect(
hass, f"signal-{DOMAIN}-public-update-{entry.entry_id}", add_public_entities hass, f"signal-{DOMAIN}-public-update-{entry.entry_id}", add_public_entities

View file

@ -39,8 +39,7 @@ async def async_setup_entry(
new_entities.append(NetgearScannerEntity(coordinator, router, device)) new_entities.append(NetgearScannerEntity(coordinator, router, device))
tracked.add(mac) tracked.add(mac)
if new_entities: async_add_entities(new_entities)
async_add_entities(new_entities)
entry.async_on_unload(coordinator.async_add_listener(new_device_callback)) entry.async_on_unload(coordinator.async_add_listener(new_device_callback))

View file

@ -338,8 +338,7 @@ async def async_setup_entry(
) )
tracked.add(mac) tracked.add(mac)
if new_entities: async_add_entities(new_entities)
async_add_entities(new_entities)
entry.async_on_unload(coordinator.async_add_listener(new_device_callback)) entry.async_on_unload(coordinator.async_add_listener(new_device_callback))

View file

@ -143,8 +143,7 @@ async def async_setup_entry(
) )
tracked.add(mac) tracked.add(mac)
if new_entities: async_add_entities(new_entities)
async_add_entities(new_entities)
entry.async_on_unload(coordinator.async_add_listener(new_device_callback)) entry.async_on_unload(coordinator.async_add_listener(new_device_callback))

View file

@ -71,8 +71,7 @@ async def async_setup_entry(
device_id, device_id,
) )
) )
if new_tools: async_add_entities(new_tools)
async_add_entities(new_tools)
config_entry.async_on_unload(coordinator.async_add_listener(async_add_tool_sensors)) config_entry.async_on_unload(coordinator.async_add_listener(async_add_tool_sensors))

View file

@ -49,8 +49,7 @@ async def async_setup_entry(
hass.data[OT_DOMAIN]["context"].set_async_see(_receive_data) hass.data[OT_DOMAIN]["context"].set_async_see(_receive_data)
if entities: async_add_entities(entities)
async_add_entities(entities)
class OwnTracksEntity(TrackerEntity, RestoreEntity): class OwnTracksEntity(TrackerEntity, RestoreEntity):

View file

@ -42,8 +42,7 @@ async def async_setup_entry(
logical_load = plum.get_load(device["llid"]) logical_load = plum.get_load(device["llid"])
entities.append(PlumLight(load=logical_load)) entities.append(PlumLight(load=logical_load))
if entities: async_add_entities(entities)
async_add_entities(entities)
async def new_load(device): async def new_load(device):
setup_entities(device) setup_entities(device)

View file

@ -55,8 +55,7 @@ def add_new_entities(coordinator, async_add_entities, tracked):
new_tracked.append(RuckusUnleashedDevice(coordinator, mac, device[API_NAME])) new_tracked.append(RuckusUnleashedDevice(coordinator, mac, device[API_NAME]))
tracked.add(mac) tracked.add(mac)
if new_tracked: async_add_entities(new_tracked)
async_add_entities(new_tracked)
@callback @callback
@ -77,8 +76,7 @@ def restore_entities(registry, coordinator, entry, async_add_entities, tracked):
) )
tracked.add(entity.unique_id) tracked.add(entity.unique_id)
if missing: async_add_entities(missing)
async_add_entities(missing)
class RuckusUnleashedDevice(CoordinatorEntity, ScannerEntity): class RuckusUnleashedDevice(CoordinatorEntity, ScannerEntity):

View file

@ -90,8 +90,7 @@ async def async_setup_entry(
] ]
) )
if entities: async_add_entities(entities, True)
async_add_entities(entities, True)
class TadoDeviceBinarySensor(TadoDeviceEntity, BinarySensorEntity): class TadoDeviceBinarySensor(TadoDeviceEntity, BinarySensorEntity):

View file

@ -104,8 +104,7 @@ async def async_setup_entry(
"set_temp_offset", "set_temp_offset",
) )
if entities: async_add_entities(entities, True)
async_add_entities(entities, True)
def _generate_entities(tado): def _generate_entities(tado):

View file

@ -82,8 +82,7 @@ async def async_setup_entry(
] ]
) )
if entities: async_add_entities(entities, True)
async_add_entities(entities, True)
class TadoHomeSensor(TadoHomeEntity, SensorEntity): class TadoHomeSensor(TadoHomeEntity, SensorEntity):

View file

@ -75,8 +75,7 @@ async def async_setup_entry(
"set_timer", "set_timer",
) )
if entities: async_add_entities(entities, True)
async_add_entities(entities, True)
def _generate_entities(tado): def _generate_entities(tado):

View file

@ -111,8 +111,7 @@ def add_client_entities(controller, async_add_entities, clients):
trackers.append(UniFiClientTracker(client, controller)) trackers.append(UniFiClientTracker(client, controller))
if trackers: async_add_entities(trackers)
async_add_entities(trackers)
@callback @callback
@ -127,8 +126,7 @@ def add_device_entities(controller, async_add_entities, devices):
device = controller.api.devices[mac] device = controller.api.devices[mac]
trackers.append(UniFiDeviceTracker(device, controller)) trackers.append(UniFiDeviceTracker(device, controller))
if trackers: async_add_entities(trackers)
async_add_entities(trackers)
class UniFiClientTracker(UniFiClientBase, ScannerEntity): class UniFiClientTracker(UniFiClientBase, ScannerEntity):

View file

@ -67,8 +67,7 @@ def add_bandwidth_entities(controller, async_add_entities, clients):
client = controller.api.clients[mac] client = controller.api.clients[mac]
sensors.append(sensor_class(client, controller)) sensors.append(sensor_class(client, controller))
if sensors: async_add_entities(sensors)
async_add_entities(sensors)
@callback @callback
@ -83,8 +82,7 @@ def add_uptime_entities(controller, async_add_entities, clients):
client = controller.api.clients[mac] client = controller.api.clients[mac]
sensors.append(UniFiUpTimeSensor(client, controller)) sensors.append(UniFiUpTimeSensor(client, controller))
if sensors: async_add_entities(sensors)
async_add_entities(sensors)
class UniFiBandwidthSensor(UniFiClient, SensorEntity): class UniFiBandwidthSensor(UniFiClient, SensorEntity):

View file

@ -124,8 +124,7 @@ def add_block_entities(controller, async_add_entities, clients):
client = controller.api.clients[mac] client = controller.api.clients[mac]
switches.append(UniFiBlockClientSwitch(client, controller)) switches.append(UniFiBlockClientSwitch(client, controller))
if switches: async_add_entities(switches)
async_add_entities(switches)
@callback @callback
@ -175,8 +174,7 @@ def add_poe_entities(controller, async_add_entities, clients, known_poe_clients)
switches.append(UniFiPOEClientSwitch(client, controller)) switches.append(UniFiPOEClientSwitch(client, controller))
if switches: async_add_entities(switches)
async_add_entities(switches)
@callback @callback
@ -193,8 +191,7 @@ def add_dpi_entities(controller, async_add_entities, dpi_groups):
switches.append(UniFiDPIRestrictionSwitch(dpi_groups[group], controller)) switches.append(UniFiDPIRestrictionSwitch(dpi_groups[group], controller))
if switches: async_add_entities(switches)
async_add_entities(switches)
@callback @callback
@ -213,8 +210,7 @@ def add_outlet_entities(controller, async_add_entities, devices):
if outlet.has_relay: if outlet.has_relay:
switches.append(UniFiOutletSwitch(device, controller, outlet.index)) switches.append(UniFiOutletSwitch(device, controller, outlet.index))
if switches: async_add_entities(switches)
async_add_entities(switches)
class UniFiPOEClientSwitch(UniFiClient, SwitchEntity, RestoreEntity): class UniFiPOEClientSwitch(UniFiClient, SwitchEntity, RestoreEntity):

View file

@ -64,8 +64,7 @@ def add_device_update_entities(controller, async_add_entities, devices):
device = controller.api.devices[mac] device = controller.api.devices[mac]
entities.append(UniFiDeviceUpdateEntity(device, controller)) entities.append(UniFiDeviceUpdateEntity(device, controller))
if entities: async_add_entities(entities)
async_add_entities(entities)
class UniFiDeviceUpdateEntity(UniFiBase, UpdateEntity): class UniFiDeviceUpdateEntity(UniFiBase, UpdateEntity):

View file

@ -76,8 +76,7 @@ def async_setup_bridge(
known_light_ids.add(light_id) known_light_ids.add(light_id)
new_lights.append(WemoLight(coordinator, light)) new_lights.append(WemoLight(coordinator, light))
if new_lights: async_add_entities(new_lights)
async_add_entities(new_lights)
async_update_lights() async_update_lights()
config_entry.async_on_unload(coordinator.async_add_listener(async_update_lights)) config_entry.async_on_unload(coordinator.async_add_listener(async_update_lights))

View file

@ -270,5 +270,4 @@ def async_update_segments(
current_ids.add(segment_id) current_ids.add(segment_id)
new_entities.append(WLEDSegmentLight(coordinator, segment_id)) new_entities.append(WLEDSegmentLight(coordinator, segment_id))
if new_entities: async_add_entities(new_entities)
async_add_entities(new_entities)

View file

@ -147,5 +147,4 @@ def async_update_segments(
for desc in NUMBERS: for desc in NUMBERS:
new_entities.append(WLEDNumber(coordinator, segment_id, desc)) new_entities.append(WLEDNumber(coordinator, segment_id, desc))
if new_entities: async_add_entities(new_entities)
async_add_entities(new_entities)

View file

@ -195,5 +195,4 @@ def async_update_segments(
current_ids.add(segment_id) current_ids.add(segment_id)
new_entities.append(WLEDPaletteSelect(coordinator, segment_id)) new_entities.append(WLEDPaletteSelect(coordinator, segment_id))
if new_entities: async_add_entities(new_entities)
async_add_entities(new_entities)

View file

@ -215,5 +215,4 @@ def async_update_segments(
current_ids.add(segment_id) current_ids.add(segment_id)
new_entities.append(WLEDReverseSwitch(coordinator, segment_id)) new_entities.append(WLEDReverseSwitch(coordinator, segment_id))
if new_entities: async_add_entities(new_entities)
async_add_entities(new_entities)

View file

@ -62,8 +62,7 @@ def async_update_friends(
] ]
new_entities = new_entities + current[xuid] new_entities = new_entities + current[xuid]
if new_entities: async_add_entities(new_entities)
async_add_entities(new_entities)
# Process deleted favorites, remove them from Home Assistant # Process deleted favorites, remove them from Home Assistant
for xuid in current_ids - new_ids: for xuid in current_ids - new_ids:

View file

@ -64,8 +64,7 @@ def async_update_friends(
] ]
new_entities = new_entities + current[xuid] new_entities = new_entities + current[xuid]
if new_entities: async_add_entities(new_entities)
async_add_entities(new_entities)
# Process deleted favorites, remove them from Home Assistant # Process deleted favorites, remove them from Home Assistant
for xuid in current_ids - new_ids: for xuid in current_ids - new_ids:

View file

@ -60,8 +60,7 @@ def setup_platform(
continue continue
entities.append(XboxSensor(api, xuid, gamercard, interval)) entities.append(XboxSensor(api, xuid, gamercard, interval))
if entities: add_entities(entities, True)
add_entities(entities, True)
def get_user_gamercard(api, xuid): def get_user_gamercard(api, xuid):