mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Improve lists in integrations [E-F] (#113075)
This commit is contained in:
parent
d33fdd3289
commit
643e6096da
@ -38,13 +38,13 @@ def setup_platform(
|
||||
monitored_conditions = discovery_info["monitored_conditions"]
|
||||
name = discovery_info["client_name"]
|
||||
|
||||
dev = []
|
||||
for condition in monitored_conditions:
|
||||
dev.append(
|
||||
add_entities(
|
||||
(
|
||||
EbusdSensor(ebusd_api, discovery_info["sensor_types"][condition], name)
|
||||
)
|
||||
|
||||
add_entities(dev, True)
|
||||
for condition in monitored_conditions
|
||||
),
|
||||
True,
|
||||
)
|
||||
|
||||
|
||||
class EbusdSensor(SensorEntity):
|
||||
|
@ -54,16 +54,17 @@ async def async_setup_entry(
|
||||
) -> None:
|
||||
"""Set up the ecobee thermostat number entity."""
|
||||
data: EcobeeData = hass.data[DOMAIN]
|
||||
entities = []
|
||||
_LOGGER.debug("Adding min time ventilators numbers (if present)")
|
||||
for index, thermostat in enumerate(data.ecobee.thermostats):
|
||||
if thermostat["settings"]["ventilatorType"] == "none":
|
||||
continue
|
||||
_LOGGER.debug("Adding %s's ventilator min times number", thermostat["name"])
|
||||
for numbers in VENTILATOR_NUMBERS:
|
||||
entities.append(EcobeeVentilatorMinTime(data, index, numbers))
|
||||
|
||||
async_add_entities(entities, True)
|
||||
async_add_entities(
|
||||
(
|
||||
EcobeeVentilatorMinTime(data, index, numbers)
|
||||
for index, thermostat in enumerate(data.ecobee.thermostats)
|
||||
if thermostat["settings"]["ventilatorType"] != "none"
|
||||
for numbers in VENTILATOR_NUMBERS
|
||||
),
|
||||
True,
|
||||
)
|
||||
|
||||
|
||||
class EcobeeVentilatorMinTime(EcobeeBaseEntity, NumberEntity):
|
||||
|
@ -185,17 +185,17 @@ class EcoNetThermostat(EcoNetEntity, ClimateEntity):
|
||||
@property
|
||||
def fan_modes(self):
|
||||
"""Return the fan modes."""
|
||||
econet_fan_modes = self._econet.fan_modes
|
||||
fan_list = []
|
||||
for mode in econet_fan_modes:
|
||||
return [
|
||||
ECONET_FAN_STATE_TO_HA[mode]
|
||||
for mode in self._econet.fan_modes
|
||||
# Remove the MEDLO MEDHI once we figure out how to handle it
|
||||
if mode not in [
|
||||
if mode
|
||||
not in [
|
||||
ThermostatFanMode.UNKNOWN,
|
||||
ThermostatFanMode.MEDLO,
|
||||
ThermostatFanMode.MEDHI,
|
||||
]:
|
||||
fan_list.append(ECONET_FAN_STATE_TO_HA[mode])
|
||||
return fan_list
|
||||
]
|
||||
]
|
||||
|
||||
def set_fan_mode(self, fan_mode: str) -> None:
|
||||
"""Set the fan mode."""
|
||||
|
@ -74,18 +74,15 @@ async def async_setup_entry(
|
||||
entities: list[EcovacsEntity] = get_supported_entitites(
|
||||
controller, EcovacsButtonEntity, ENTITY_DESCRIPTIONS
|
||||
)
|
||||
for device in controller.devices(Capabilities):
|
||||
lifespan_capability = device.capabilities.life_span
|
||||
for description in LIFESPAN_ENTITY_DESCRIPTIONS:
|
||||
if description.component in lifespan_capability.types:
|
||||
entities.append(
|
||||
EcovacsResetLifespanButtonEntity(
|
||||
device, lifespan_capability, description
|
||||
)
|
||||
)
|
||||
|
||||
if entities:
|
||||
async_add_entities(entities)
|
||||
entities.extend(
|
||||
EcovacsResetLifespanButtonEntity(
|
||||
device, device.capabilities.life_span, description
|
||||
)
|
||||
for device in controller.devices(Capabilities)
|
||||
for description in LIFESPAN_ENTITY_DESCRIPTIONS
|
||||
if description.component in device.capabilities.life_span.types
|
||||
)
|
||||
async_add_entities(entities)
|
||||
|
||||
|
||||
class EcovacsButtonEntity(
|
||||
|
@ -42,10 +42,10 @@ async def async_setup_entry(
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the Ecovacs mowers."""
|
||||
mowers: list[EcovacsMower] = []
|
||||
controller: EcovacsController = hass.data[DOMAIN][config_entry.entry_id]
|
||||
for device in controller.devices(MowerCapabilities):
|
||||
mowers.append(EcovacsMower(device))
|
||||
mowers: list[EcovacsMower] = [
|
||||
EcovacsMower(device) for device in controller.devices(MowerCapabilities)
|
||||
]
|
||||
_LOGGER.debug("Adding Ecovacs Mowers to Home Assistant: %s", mowers)
|
||||
async_add_entities(mowers)
|
||||
|
||||
|
@ -180,16 +180,17 @@ async def async_setup_entry(
|
||||
entities: list[EcovacsEntity] = get_supported_entitites(
|
||||
controller, EcovacsSensor, ENTITY_DESCRIPTIONS
|
||||
)
|
||||
for device in controller.devices(Capabilities):
|
||||
lifespan_capability = device.capabilities.life_span
|
||||
for description in LIFESPAN_ENTITY_DESCRIPTIONS:
|
||||
if description.component in lifespan_capability.types:
|
||||
entities.append(
|
||||
EcovacsLifespanSensor(device, lifespan_capability, description)
|
||||
)
|
||||
|
||||
if capability := device.capabilities.error:
|
||||
entities.append(EcovacsErrorSensor(device, capability))
|
||||
entities.extend(
|
||||
EcovacsLifespanSensor(device, device.capabilities.life_span, description)
|
||||
for device in controller.devices(Capabilities)
|
||||
for description in LIFESPAN_ENTITY_DESCRIPTIONS
|
||||
if description.component in device.capabilities.life_span.types
|
||||
)
|
||||
entities.extend(
|
||||
EcovacsErrorSensor(device, capability)
|
||||
for device in controller.devices(Capabilities)
|
||||
if (capability := device.capabilities.error)
|
||||
)
|
||||
|
||||
async_add_entities(entities)
|
||||
|
||||
|
@ -31,13 +31,10 @@ def get_supported_entitites(
|
||||
descriptions: tuple[EcovacsCapabilityEntityDescription, ...],
|
||||
) -> list[EcovacsEntity]:
|
||||
"""Return all supported entities for all devices."""
|
||||
entities: list[EcovacsEntity] = []
|
||||
|
||||
for device in controller.devices(Capabilities):
|
||||
for description in descriptions:
|
||||
if isinstance(device.capabilities, description.device_capabilities) and (
|
||||
capability := description.capability_fn(device.capabilities)
|
||||
):
|
||||
entities.append(entity_class(device, capability, description))
|
||||
|
||||
return entities
|
||||
return [
|
||||
entity_class(device, capability, description)
|
||||
for device in controller.devices(Capabilities)
|
||||
for description in descriptions
|
||||
if isinstance(device.capabilities, description.device_capabilities)
|
||||
if (capability := description.capability_fn(device.capabilities))
|
||||
]
|
||||
|
@ -127,15 +127,15 @@ async def async_setup_entry(
|
||||
description,
|
||||
entity_registry_enabled_default=len(api.sids) > 1,
|
||||
)
|
||||
for sid in api.sids:
|
||||
sensors.append(
|
||||
EfergySensor(
|
||||
api,
|
||||
description,
|
||||
entry.entry_id,
|
||||
sid=sid,
|
||||
)
|
||||
sensors.extend(
|
||||
EfergySensor(
|
||||
api,
|
||||
description,
|
||||
entry.entry_id,
|
||||
sid=sid,
|
||||
)
|
||||
for sid in api.sids
|
||||
)
|
||||
async_add_entities(sensors, True)
|
||||
|
||||
|
||||
|
@ -245,19 +245,17 @@ def get_forecast(ec_data, hourly) -> list[Forecast] | None:
|
||||
)
|
||||
|
||||
else:
|
||||
for hour in ec_data.hourly_forecasts:
|
||||
forecast_array.append(
|
||||
{
|
||||
ATTR_FORECAST_TIME: hour["period"].isoformat(),
|
||||
ATTR_FORECAST_NATIVE_TEMP: int(hour["temperature"]),
|
||||
ATTR_FORECAST_CONDITION: icon_code_to_condition(
|
||||
int(hour["icon_code"])
|
||||
),
|
||||
ATTR_FORECAST_PRECIPITATION_PROBABILITY: int(
|
||||
hour["precip_probability"]
|
||||
),
|
||||
}
|
||||
)
|
||||
forecast_array.extend(
|
||||
{
|
||||
ATTR_FORECAST_TIME: hour["period"].isoformat(),
|
||||
ATTR_FORECAST_NATIVE_TEMP: int(hour["temperature"]),
|
||||
ATTR_FORECAST_CONDITION: icon_code_to_condition(int(hour["icon_code"])),
|
||||
ATTR_FORECAST_PRECIPITATION_PROBABILITY: int(
|
||||
hour["precip_probability"]
|
||||
),
|
||||
}
|
||||
for hour in ec_data.hourly_forecasts
|
||||
)
|
||||
|
||||
return forecast_array
|
||||
|
||||
|
@ -773,8 +773,7 @@ def _setup_services(
|
||||
# New service
|
||||
to_register.append(service)
|
||||
|
||||
for service in old_services.values():
|
||||
to_unregister.append(service)
|
||||
to_unregister.extend(old_services.values())
|
||||
|
||||
entry_data.services = {serv.key: serv for serv in services}
|
||||
|
||||
|
@ -47,12 +47,9 @@ async def async_setup_platform(
|
||||
jails = config[CONF_JAILS]
|
||||
log_file = config.get(CONF_FILE_PATH, DEFAULT_LOG)
|
||||
|
||||
device_list = []
|
||||
log_parser = BanLogParser(log_file)
|
||||
for jail in jails:
|
||||
device_list.append(BanSensor(name, jail, log_parser))
|
||||
|
||||
async_add_entities(device_list, True)
|
||||
async_add_entities((BanSensor(name, jail, log_parser) for jail in jails), True)
|
||||
|
||||
|
||||
class BanSensor(SensorEntity):
|
||||
|
@ -27,13 +27,15 @@ async def async_setup_entry(
|
||||
"""Set up the Fibaro event entities."""
|
||||
controller: FibaroController = hass.data[DOMAIN][entry.entry_id]
|
||||
|
||||
entities = []
|
||||
for device in controller.fibaro_devices[Platform.EVENT]:
|
||||
for scene_event in device.central_scene_event:
|
||||
# Each scene event represents a button on a device
|
||||
entities.append(FibaroEventEntity(device, scene_event))
|
||||
|
||||
async_add_entities(entities, True)
|
||||
# Each scene event represents a button on a device
|
||||
async_add_entities(
|
||||
(
|
||||
FibaroEventEntity(device, scene_event)
|
||||
for device in controller.fibaro_devices[Platform.EVENT]
|
||||
for scene_event in device.central_scene_event
|
||||
),
|
||||
True,
|
||||
)
|
||||
|
||||
|
||||
class FibaroEventEntity(FibaroDevice, EventEntity):
|
||||
|
@ -106,29 +106,27 @@ async def async_setup_entry(
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the Fibaro controller devices."""
|
||||
entities: list[SensorEntity] = []
|
||||
|
||||
controller: FibaroController = hass.data[DOMAIN][entry.entry_id]
|
||||
entities: list[SensorEntity] = [
|
||||
FibaroSensor(device, MAIN_SENSOR_TYPES.get(device.type))
|
||||
for device in controller.fibaro_devices[Platform.SENSOR]
|
||||
]
|
||||
|
||||
for device in controller.fibaro_devices[Platform.SENSOR]:
|
||||
entity_description = MAIN_SENSOR_TYPES.get(device.type)
|
||||
|
||||
# main sensors are created even if the entity type is not known
|
||||
entities.append(FibaroSensor(device, entity_description))
|
||||
|
||||
for platform in (
|
||||
Platform.BINARY_SENSOR,
|
||||
Platform.CLIMATE,
|
||||
Platform.COVER,
|
||||
Platform.LIGHT,
|
||||
Platform.LOCK,
|
||||
Platform.SENSOR,
|
||||
Platform.SWITCH,
|
||||
):
|
||||
for device in controller.fibaro_devices[platform]:
|
||||
for entity_description in ADDITIONAL_SENSOR_TYPES:
|
||||
if entity_description.key in device.properties:
|
||||
entities.append(FibaroAdditionalSensor(device, entity_description))
|
||||
entities.extend(
|
||||
FibaroAdditionalSensor(device, entity_description)
|
||||
for platform in (
|
||||
Platform.BINARY_SENSOR,
|
||||
Platform.CLIMATE,
|
||||
Platform.COVER,
|
||||
Platform.LIGHT,
|
||||
Platform.LOCK,
|
||||
Platform.SWITCH,
|
||||
)
|
||||
for device in controller.fibaro_devices[platform]
|
||||
for entity_description in ADDITIONAL_SENSOR_TYPES
|
||||
if entity_description.key in device.properties
|
||||
)
|
||||
|
||||
async_add_entities(entities, True)
|
||||
|
||||
|
@ -61,9 +61,7 @@ class FiveMDataUpdateCoordinator(DataUpdateCoordinator[dict[str, Any]]):
|
||||
except FiveMServerOfflineError as err:
|
||||
raise UpdateFailed from err
|
||||
|
||||
players_list: list[str] = []
|
||||
for player in server.players:
|
||||
players_list.append(player.name)
|
||||
players_list: list[str] = [player.name for player in server.players]
|
||||
players_list.sort()
|
||||
|
||||
resources_list = server.resources
|
||||
|
@ -34,11 +34,10 @@ async def async_setup_entry(
|
||||
devices: list[FloDeviceDataUpdateCoordinator] = hass.data[FLO_DOMAIN][
|
||||
config_entry.entry_id
|
||||
]["devices"]
|
||||
entities = []
|
||||
for device in devices:
|
||||
if device.device_type != "puck_oem":
|
||||
entities.append(FloSwitch(device))
|
||||
async_add_entities(entities)
|
||||
|
||||
async_add_entities(
|
||||
[FloSwitch(device) for device in devices if device.device_type != "puck_oem"]
|
||||
)
|
||||
|
||||
platform = entity_platform.async_get_current_platform()
|
||||
|
||||
|
@ -106,10 +106,9 @@ async def async_setup_entry(
|
||||
|
||||
@callback
|
||||
def async_add_zones(api, outputs):
|
||||
zone_entities = []
|
||||
for output in outputs:
|
||||
zone_entities.append(ForkedDaapdZone(api, output, config_entry.entry_id))
|
||||
async_add_entities(zone_entities, False)
|
||||
async_add_entities(
|
||||
ForkedDaapdZone(api, output, config_entry.entry_id) for output in outputs
|
||||
)
|
||||
|
||||
remove_add_zones_listener = async_dispatcher_connect(
|
||||
hass, SIGNAL_ADD_ZONES.format(config_entry.entry_id), async_add_zones
|
||||
@ -433,17 +432,16 @@ class ForkedDaapdMaster(MediaPlayerEntity):
|
||||
# restore state
|
||||
await self.api.set_volume(volume=self._last_volume * 100)
|
||||
if self._last_outputs:
|
||||
futures: list[asyncio.Task[int]] = []
|
||||
for output in self._last_outputs:
|
||||
futures.append(
|
||||
asyncio.create_task(
|
||||
self.api.change_output(
|
||||
output["id"],
|
||||
selected=output["selected"],
|
||||
volume=output["volume"],
|
||||
)
|
||||
futures: list[asyncio.Task[int]] = [
|
||||
asyncio.create_task(
|
||||
self.api.change_output(
|
||||
output["id"],
|
||||
selected=output["selected"],
|
||||
volume=output["volume"],
|
||||
)
|
||||
)
|
||||
for output in self._last_outputs
|
||||
]
|
||||
await asyncio.wait(futures)
|
||||
else: # enable all outputs
|
||||
await self.api.set_enabled_outputs(
|
||||
@ -651,15 +649,14 @@ class ForkedDaapdMaster(MediaPlayerEntity):
|
||||
self._last_outputs = self._outputs
|
||||
if self._outputs:
|
||||
await self.api.set_volume(volume=self._tts_volume * 100)
|
||||
futures = []
|
||||
for output in self._outputs:
|
||||
futures.append(
|
||||
asyncio.create_task(
|
||||
self.api.change_output(
|
||||
output["id"], selected=True, volume=self._tts_volume * 100
|
||||
)
|
||||
futures = [
|
||||
asyncio.create_task(
|
||||
self.api.change_output(
|
||||
output["id"], selected=True, volume=self._tts_volume * 100
|
||||
)
|
||||
)
|
||||
for output in self._outputs
|
||||
]
|
||||
await asyncio.wait(futures)
|
||||
|
||||
async def _pause_and_wait_for_callback(self):
|
||||
|
@ -39,14 +39,14 @@ async def async_setup_entry(
|
||||
"""Set up alarm panel."""
|
||||
router: FreeboxRouter = hass.data[DOMAIN][entry.unique_id]
|
||||
|
||||
alarm_entities: list[AlarmControlPanelEntity] = []
|
||||
|
||||
for node in router.home_devices.values():
|
||||
if node["category"] == FreeboxHomeCategory.ALARM:
|
||||
alarm_entities.append(FreeboxAlarm(hass, router, node))
|
||||
|
||||
if alarm_entities:
|
||||
async_add_entities(alarm_entities, True)
|
||||
async_add_entities(
|
||||
(
|
||||
FreeboxAlarm(hass, router, node)
|
||||
for node in router.home_devices.values()
|
||||
if node["category"] == FreeboxHomeCategory.ALARM
|
||||
),
|
||||
True,
|
||||
)
|
||||
|
||||
|
||||
class FreeboxAlarm(FreeboxHomeEntity, AlarmControlPanelEntity):
|
||||
|
@ -53,16 +53,17 @@ async def async_setup_entry(
|
||||
elif node["category"] == FreeboxHomeCategory.DWS:
|
||||
binary_entities.append(FreeboxDwsSensor(hass, router, node))
|
||||
|
||||
for endpoint in node["show_endpoints"]:
|
||||
binary_entities.extend(
|
||||
FreeboxCoverSensor(hass, router, node)
|
||||
for endpoint in node["show_endpoints"]
|
||||
if (
|
||||
endpoint["name"] == "cover"
|
||||
and endpoint["ep_type"] == "signal"
|
||||
and endpoint.get("value") is not None
|
||||
):
|
||||
binary_entities.append(FreeboxCoverSensor(hass, router, node))
|
||||
)
|
||||
)
|
||||
|
||||
if binary_entities:
|
||||
async_add_entities(binary_entities, True)
|
||||
async_add_entities(binary_entities, True)
|
||||
|
||||
|
||||
class FreeboxHomeBinarySensor(FreeboxHomeEntity, BinarySensorEntity):
|
||||
|
@ -128,12 +128,10 @@ class FritzBoxCallMonitorConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
|
||||
async def _get_list_of_phonebook_names(self) -> list[str]:
|
||||
"""Return list of names for all available phonebooks."""
|
||||
phonebook_names: list[str] = []
|
||||
|
||||
for phonebook_id in self._phonebook_ids:
|
||||
phonebook_names.append(await self._get_name_of_phonebook(phonebook_id))
|
||||
|
||||
return phonebook_names
|
||||
return [
|
||||
await self._get_name_of_phonebook(phonebook_id)
|
||||
for phonebook_id in self._phonebook_ids
|
||||
]
|
||||
|
||||
@staticmethod
|
||||
@callback
|
||||
|
Loading…
x
Reference in New Issue
Block a user