mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Improve lists in integrations [L-M] (#113227)
* Improve lists in integrations [L-M] * Update homeassistant/components/mailbox/__init__.py Co-authored-by: Jan Bouwhuis <jbouwh@users.noreply.github.com> * Fix --------- Co-authored-by: Jan Bouwhuis <jbouwh@users.noreply.github.com>
This commit is contained in:
parent
4547131bbc
commit
595d07f1c6
@ -208,19 +208,18 @@ async def async_setup_entry(
|
|||||||
"""Set up number entities."""
|
"""Set up number entities."""
|
||||||
coordinator = hass.data[DOMAIN][config_entry.entry_id]
|
coordinator = hass.data[DOMAIN][config_entry.entry_id]
|
||||||
|
|
||||||
async_add_entities(
|
entities: list[NumberEntity] = [
|
||||||
LaMarzoccoNumberEntity(coordinator, description)
|
LaMarzoccoNumberEntity(coordinator, description)
|
||||||
for description in ENTITIES
|
for description in ENTITIES
|
||||||
if description.supported_fn(coordinator)
|
if description.supported_fn(coordinator)
|
||||||
)
|
]
|
||||||
|
|
||||||
entities: list[LaMarzoccoKeyNumberEntity] = []
|
|
||||||
for description in KEY_ENTITIES:
|
for description in KEY_ENTITIES:
|
||||||
if description.supported_fn(coordinator):
|
if description.supported_fn(coordinator):
|
||||||
num_keys = KEYS_PER_MODEL[coordinator.lm.model_name]
|
num_keys = KEYS_PER_MODEL[coordinator.lm.model_name]
|
||||||
for key in range(min(num_keys, 1), num_keys + 1):
|
entities.extend(
|
||||||
entities.append(
|
|
||||||
LaMarzoccoKeyNumberEntity(coordinator, description, key)
|
LaMarzoccoKeyNumberEntity(coordinator, description, key)
|
||||||
|
for key in range(min(num_keys, 1), num_keys + 1)
|
||||||
)
|
)
|
||||||
|
|
||||||
async_add_entities(entities)
|
async_add_entities(entities)
|
||||||
|
@ -286,11 +286,10 @@ async def async_setup_entry(
|
|||||||
name="Landis+Gyr Heat Meter",
|
name="Landis+Gyr Heat Meter",
|
||||||
)
|
)
|
||||||
|
|
||||||
sensors = []
|
async_add_entities(
|
||||||
for description in HEAT_METER_SENSOR_TYPES:
|
HeatMeterSensor(coordinator, description, device)
|
||||||
sensors.append(HeatMeterSensor(coordinator, description, device))
|
for description in HEAT_METER_SENSOR_TYPES
|
||||||
|
)
|
||||||
async_add_entities(sensors)
|
|
||||||
|
|
||||||
|
|
||||||
class HeatMeterSensor(
|
class HeatMeterSensor(
|
||||||
|
@ -43,16 +43,13 @@ async def async_setup_entry(
|
|||||||
async_add_entities: AddEntitiesCallback,
|
async_add_entities: AddEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up LCN switch entities from a config entry."""
|
"""Set up LCN switch entities from a config entry."""
|
||||||
entities = []
|
|
||||||
|
|
||||||
for entity_config in config_entry.data[CONF_ENTITIES]:
|
async_add_entities(
|
||||||
if entity_config[CONF_DOMAIN] == DOMAIN_BINARY_SENSOR:
|
|
||||||
entities.append(
|
|
||||||
create_lcn_binary_sensor_entity(hass, entity_config, config_entry)
|
create_lcn_binary_sensor_entity(hass, entity_config, config_entry)
|
||||||
|
for entity_config in config_entry.data[CONF_ENTITIES]
|
||||||
|
if entity_config[CONF_DOMAIN] == DOMAIN_BINARY_SENSOR
|
||||||
)
|
)
|
||||||
|
|
||||||
async_add_entities(entities)
|
|
||||||
|
|
||||||
|
|
||||||
class LcnRegulatorLockSensor(LcnEntity, BinarySensorEntity):
|
class LcnRegulatorLockSensor(LcnEntity, BinarySensorEntity):
|
||||||
"""Representation of a LCN binary sensor for regulator locks."""
|
"""Representation of a LCN binary sensor for regulator locks."""
|
||||||
|
@ -56,16 +56,13 @@ async def async_setup_entry(
|
|||||||
async_add_entities: AddEntitiesCallback,
|
async_add_entities: AddEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up LCN switch entities from a config entry."""
|
"""Set up LCN switch entities from a config entry."""
|
||||||
entities = []
|
|
||||||
|
|
||||||
for entity_config in config_entry.data[CONF_ENTITIES]:
|
async_add_entities(
|
||||||
if entity_config[CONF_DOMAIN] == DOMAIN_CLIMATE:
|
|
||||||
entities.append(
|
|
||||||
create_lcn_climate_entity(hass, entity_config, config_entry)
|
create_lcn_climate_entity(hass, entity_config, config_entry)
|
||||||
|
for entity_config in config_entry.data[CONF_ENTITIES]
|
||||||
|
if entity_config[CONF_DOMAIN] == DOMAIN_CLIMATE
|
||||||
)
|
)
|
||||||
|
|
||||||
async_add_entities(entities)
|
|
||||||
|
|
||||||
|
|
||||||
class LcnClimate(LcnEntity, ClimateEntity):
|
class LcnClimate(LcnEntity, ClimateEntity):
|
||||||
"""Representation of a LCN climate device."""
|
"""Representation of a LCN climate device."""
|
||||||
|
@ -40,13 +40,12 @@ async def async_setup_entry(
|
|||||||
async_add_entities: AddEntitiesCallback,
|
async_add_entities: AddEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up LCN cover entities from a config entry."""
|
"""Set up LCN cover entities from a config entry."""
|
||||||
entities = []
|
|
||||||
|
|
||||||
for entity_config in config_entry.data[CONF_ENTITIES]:
|
async_add_entities(
|
||||||
if entity_config[CONF_DOMAIN] == DOMAIN_COVER:
|
create_lcn_cover_entity(hass, entity_config, config_entry)
|
||||||
entities.append(create_lcn_cover_entity(hass, entity_config, config_entry))
|
for entity_config in config_entry.data[CONF_ENTITIES]
|
||||||
|
if entity_config[CONF_DOMAIN] == DOMAIN_COVER
|
||||||
async_add_entities(entities)
|
)
|
||||||
|
|
||||||
|
|
||||||
class LcnOutputsCover(LcnEntity, CoverEntity):
|
class LcnOutputsCover(LcnEntity, CoverEntity):
|
||||||
|
@ -53,13 +53,12 @@ async def async_setup_entry(
|
|||||||
async_add_entities: AddEntitiesCallback,
|
async_add_entities: AddEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up LCN light entities from a config entry."""
|
"""Set up LCN light entities from a config entry."""
|
||||||
entities = []
|
|
||||||
|
|
||||||
for entity_config in config_entry.data[CONF_ENTITIES]:
|
async_add_entities(
|
||||||
if entity_config[CONF_DOMAIN] == DOMAIN_LIGHT:
|
create_lcn_light_entity(hass, entity_config, config_entry)
|
||||||
entities.append(create_lcn_light_entity(hass, entity_config, config_entry))
|
for entity_config in config_entry.data[CONF_ENTITIES]
|
||||||
|
if entity_config[CONF_DOMAIN] == DOMAIN_LIGHT
|
||||||
async_add_entities(entities)
|
)
|
||||||
|
|
||||||
|
|
||||||
class LcnOutputLight(LcnEntity, LightEntity):
|
class LcnOutputLight(LcnEntity, LightEntity):
|
||||||
|
@ -43,13 +43,12 @@ async def async_setup_entry(
|
|||||||
async_add_entities: AddEntitiesCallback,
|
async_add_entities: AddEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up LCN switch entities from a config entry."""
|
"""Set up LCN switch entities from a config entry."""
|
||||||
entities = []
|
|
||||||
|
|
||||||
for entity_config in config_entry.data[CONF_ENTITIES]:
|
async_add_entities(
|
||||||
if entity_config[CONF_DOMAIN] == DOMAIN_SCENE:
|
create_lcn_scene_entity(hass, entity_config, config_entry)
|
||||||
entities.append(create_lcn_scene_entity(hass, entity_config, config_entry))
|
for entity_config in config_entry.data[CONF_ENTITIES]
|
||||||
|
if entity_config[CONF_DOMAIN] == DOMAIN_SCENE
|
||||||
async_add_entities(entities)
|
)
|
||||||
|
|
||||||
|
|
||||||
class LcnScene(LcnEntity, Scene):
|
class LcnScene(LcnEntity, Scene):
|
||||||
|
@ -56,13 +56,12 @@ async def async_setup_entry(
|
|||||||
async_add_entities: AddEntitiesCallback,
|
async_add_entities: AddEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up LCN switch entities from a config entry."""
|
"""Set up LCN switch entities from a config entry."""
|
||||||
entities = []
|
|
||||||
|
|
||||||
for entity_config in config_entry.data[CONF_ENTITIES]:
|
async_add_entities(
|
||||||
if entity_config[CONF_DOMAIN] == DOMAIN_SENSOR:
|
create_lcn_sensor_entity(hass, entity_config, config_entry)
|
||||||
entities.append(create_lcn_sensor_entity(hass, entity_config, config_entry))
|
for entity_config in config_entry.data[CONF_ENTITIES]
|
||||||
|
if entity_config[CONF_DOMAIN] == DOMAIN_SENSOR
|
||||||
async_add_entities(entities)
|
)
|
||||||
|
|
||||||
|
|
||||||
class LcnVariableSensor(LcnEntity, SensorEntity):
|
class LcnVariableSensor(LcnEntity, SensorEntity):
|
||||||
|
@ -41,13 +41,11 @@ async def async_setup_entry(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Set up LCN switch entities from a config entry."""
|
"""Set up LCN switch entities from a config entry."""
|
||||||
|
|
||||||
entities = []
|
async_add_entities(
|
||||||
|
create_lcn_switch_entity(hass, entity_config, config_entry)
|
||||||
for entity_config in config_entry.data[CONF_ENTITIES]:
|
for entity_config in config_entry.data[CONF_ENTITIES]
|
||||||
if entity_config[CONF_DOMAIN] == DOMAIN_SWITCH:
|
if entity_config[CONF_DOMAIN] == DOMAIN_SWITCH
|
||||||
entities.append(create_lcn_switch_entity(hass, entity_config, config_entry))
|
)
|
||||||
|
|
||||||
async_add_entities(entities)
|
|
||||||
|
|
||||||
|
|
||||||
class LcnOutputSwitch(LcnEntity, SwitchEntity):
|
class LcnOutputSwitch(LcnEntity, SwitchEntity):
|
||||||
|
@ -166,11 +166,11 @@ class LGDevice(MediaPlayerEntity):
|
|||||||
@property
|
@property
|
||||||
def sound_mode_list(self):
|
def sound_mode_list(self):
|
||||||
"""Return the available sound modes."""
|
"""Return the available sound modes."""
|
||||||
modes = []
|
return sorted(
|
||||||
for equaliser in self._equalisers:
|
temescal.equalisers[equaliser]
|
||||||
if equaliser < len(temescal.equalisers):
|
for equaliser in self._equalisers
|
||||||
modes.append(temescal.equalisers[equaliser])
|
if equaliser < len(temescal.equalisers)
|
||||||
return sorted(modes)
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def source(self):
|
def source(self):
|
||||||
@ -182,11 +182,11 @@ class LGDevice(MediaPlayerEntity):
|
|||||||
@property
|
@property
|
||||||
def source_list(self):
|
def source_list(self):
|
||||||
"""List of available input sources."""
|
"""List of available input sources."""
|
||||||
sources = []
|
return sorted(
|
||||||
for function in self._functions:
|
temescal.functions[function]
|
||||||
if function < len(temescal.functions):
|
for function in self._functions
|
||||||
sources.append(temescal.functions[function])
|
if function < len(temescal.functions)
|
||||||
return sorted(sources)
|
)
|
||||||
|
|
||||||
def set_volume_level(self, volume: float) -> None:
|
def set_volume_level(self, volume: float) -> None:
|
||||||
"""Set volume level, range 0..1."""
|
"""Set volume level, range 0..1."""
|
||||||
|
@ -381,8 +381,7 @@ class LIFXUpdateCoordinator(DataUpdateCoordinator[None]):
|
|||||||
|
|
||||||
# pad the color list with blanks if necessary
|
# pad the color list with blanks if necessary
|
||||||
if len(colors) < 82:
|
if len(colors) < 82:
|
||||||
for _ in range(82 - len(colors)):
|
colors.extend([(0, 0, 0, 0) for _ in range(82 - len(colors))])
|
||||||
colors.append((0, 0, 0, 0))
|
|
||||||
|
|
||||||
await async_execute_lifx(
|
await async_execute_lifx(
|
||||||
partial(
|
partial(
|
||||||
|
@ -176,9 +176,9 @@ def async_subscribe_events(
|
|||||||
event_forwarder = event_forwarder_filtered(
|
event_forwarder = event_forwarder_filtered(
|
||||||
target, entities_filter, entity_ids, device_ids
|
target, entities_filter, entity_ids, device_ids
|
||||||
)
|
)
|
||||||
for event_type in event_types:
|
subscriptions.extend(
|
||||||
subscriptions.append(
|
|
||||||
hass.bus.async_listen(event_type, event_forwarder, run_immediately=True)
|
hass.bus.async_listen(event_type, event_forwarder, run_immediately=True)
|
||||||
|
for event_type in event_types
|
||||||
)
|
)
|
||||||
|
|
||||||
if device_ids and not entity_ids:
|
if device_ids and not entity_ids:
|
||||||
|
@ -72,11 +72,8 @@ def setup_platform(
|
|||||||
"""Set up the London Air sensor."""
|
"""Set up the London Air sensor."""
|
||||||
data = APIData()
|
data = APIData()
|
||||||
data.update()
|
data.update()
|
||||||
sensors = []
|
|
||||||
for name in config[CONF_LOCATIONS]:
|
|
||||||
sensors.append(AirSensor(name, data))
|
|
||||||
|
|
||||||
add_entities(sensors, True)
|
add_entities((AirSensor(name, data) for name in config[CONF_LOCATIONS]), True)
|
||||||
|
|
||||||
|
|
||||||
class APIData:
|
class APIData:
|
||||||
@ -141,14 +138,16 @@ class AirSensor(SensorEntity):
|
|||||||
|
|
||||||
def update(self) -> None:
|
def update(self) -> None:
|
||||||
"""Update the sensor."""
|
"""Update the sensor."""
|
||||||
sites_status = []
|
sites_status: list = []
|
||||||
self._api_data.update()
|
self._api_data.update()
|
||||||
if self._api_data.data:
|
if self._api_data.data:
|
||||||
self._site_data = self._api_data.data[self._name]
|
self._site_data = self._api_data.data[self._name]
|
||||||
self._updated = self._site_data[0]["updated"]
|
self._updated = self._site_data[0]["updated"]
|
||||||
for site in self._site_data:
|
sites_status.extend(
|
||||||
if site["pollutants_status"] != "no_species_data":
|
site["pollutants_status"]
|
||||||
sites_status.append(site["pollutants_status"])
|
for site in self._site_data
|
||||||
|
if site["pollutants_status"] != "no_species_data"
|
||||||
|
)
|
||||||
|
|
||||||
if sites_status:
|
if sites_status:
|
||||||
self._state = max(set(sites_status), key=sites_status.count)
|
self._state = max(set(sites_status), key=sites_status.count)
|
||||||
|
@ -45,11 +45,9 @@ async def async_setup_platform(
|
|||||||
if not coordinator.last_update_success:
|
if not coordinator.last_update_success:
|
||||||
raise PlatformNotReady
|
raise PlatformNotReady
|
||||||
|
|
||||||
sensors = []
|
async_add_entities(
|
||||||
for line in config[CONF_LINE]:
|
LondonTubeSensor(coordinator, line) for line in config[CONF_LINE]
|
||||||
sensors.append(LondonTubeSensor(coordinator, line))
|
)
|
||||||
|
|
||||||
async_add_entities(sensors)
|
|
||||||
|
|
||||||
|
|
||||||
class LondonTubeSensor(CoordinatorEntity[LondonTubeCoordinator], SensorEntity):
|
class LondonTubeSensor(CoordinatorEntity[LondonTubeCoordinator], SensorEntity):
|
||||||
|
@ -96,14 +96,11 @@ class LuciDeviceScanner(DeviceScanner):
|
|||||||
|
|
||||||
_LOGGER.debug("Luci get_all_connected_devices returned: %s", result)
|
_LOGGER.debug("Luci get_all_connected_devices returned: %s", result)
|
||||||
|
|
||||||
last_results = []
|
self.last_results = [
|
||||||
for device in result:
|
device
|
||||||
if (
|
for device in result
|
||||||
not hasattr(self.router.router.owrt_version, "release")
|
if not hasattr(self.router.router.owrt_version, "release")
|
||||||
or not self.router.router.owrt_version.release
|
or not self.router.router.owrt_version.release
|
||||||
or self.router.router.owrt_version.release[0] < 19
|
or self.router.router.owrt_version.release[0] < 19
|
||||||
or device.reachable
|
or device.reachable
|
||||||
):
|
]
|
||||||
last_results.append(device)
|
|
||||||
|
|
||||||
self.last_results = last_results
|
|
||||||
|
@ -35,13 +35,12 @@ async def async_setup_entry(
|
|||||||
|
|
||||||
device_types = CONST.TYPE_OPENING + CONST.TYPE_SENSOR
|
device_types = CONST.TYPE_OPENING + CONST.TYPE_SENSOR
|
||||||
|
|
||||||
sensors = []
|
|
||||||
partial_func = partial(data.get_devices, generic_type=device_types)
|
partial_func = partial(data.get_devices, generic_type=device_types)
|
||||||
devices = await hass.async_add_executor_job(partial_func)
|
devices = await hass.async_add_executor_job(partial_func)
|
||||||
for device in devices:
|
|
||||||
sensors.append(LupusecBinarySensor(device, config_entry.entry_id))
|
|
||||||
|
|
||||||
async_add_entities(sensors)
|
async_add_entities(
|
||||||
|
LupusecBinarySensor(device, config_entry.entry_id) for device in devices
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class LupusecBinarySensor(LupusecBaseSensor, BinarySensorEntity):
|
class LupusecBinarySensor(LupusecBaseSensor, BinarySensorEntity):
|
||||||
|
@ -30,13 +30,12 @@ async def async_setup_entry(
|
|||||||
|
|
||||||
device_types = CONST.TYPE_SWITCH
|
device_types = CONST.TYPE_SWITCH
|
||||||
|
|
||||||
switches = []
|
|
||||||
partial_func = partial(data.get_devices, generic_type=device_types)
|
partial_func = partial(data.get_devices, generic_type=device_types)
|
||||||
devices = await hass.async_add_executor_job(partial_func)
|
devices = await hass.async_add_executor_job(partial_func)
|
||||||
for device in devices:
|
|
||||||
switches.append(LupusecSwitch(device, config_entry.entry_id))
|
|
||||||
|
|
||||||
async_add_entities(switches)
|
async_add_entities(
|
||||||
|
LupusecSwitch(device, config_entry.entry_id) for device in devices
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class LupusecSwitch(LupusecBaseSensor, SwitchEntity):
|
class LupusecSwitch(LupusecBaseSensor, SwitchEntity):
|
||||||
|
@ -379,8 +379,6 @@ async def async_get_triggers(
|
|||||||
hass: HomeAssistant, device_id: str
|
hass: HomeAssistant, device_id: str
|
||||||
) -> list[dict[str, str]]:
|
) -> list[dict[str, str]]:
|
||||||
"""List device triggers for lutron caseta devices."""
|
"""List device triggers for lutron caseta devices."""
|
||||||
triggers = []
|
|
||||||
|
|
||||||
# Check if device is a valid keypad. Return empty if not.
|
# Check if device is a valid keypad. Return empty if not.
|
||||||
if not (data := get_lutron_data_by_dr_id(hass, device_id)) or not (
|
if not (data := get_lutron_data_by_dr_id(hass, device_id)) or not (
|
||||||
keypad := data.keypad_data.dr_device_id_to_keypad.get(device_id)
|
keypad := data.keypad_data.dr_device_id_to_keypad.get(device_id)
|
||||||
@ -395,9 +393,7 @@ async def async_get_triggers(
|
|||||||
keypad_button_names_to_leap[keypad["lutron_device_id"]],
|
keypad_button_names_to_leap[keypad["lutron_device_id"]],
|
||||||
)
|
)
|
||||||
|
|
||||||
for trigger in SUPPORTED_INPUTS_EVENTS_TYPES:
|
return [
|
||||||
for subtype in valid_buttons:
|
|
||||||
triggers.append(
|
|
||||||
{
|
{
|
||||||
CONF_PLATFORM: "device",
|
CONF_PLATFORM: "device",
|
||||||
CONF_DEVICE_ID: device_id,
|
CONF_DEVICE_ID: device_id,
|
||||||
@ -405,9 +401,9 @@ async def async_get_triggers(
|
|||||||
CONF_TYPE: trigger,
|
CONF_TYPE: trigger,
|
||||||
CONF_SUBTYPE: subtype,
|
CONF_SUBTYPE: subtype,
|
||||||
}
|
}
|
||||||
)
|
for trigger in SUPPORTED_INPUTS_EVENTS_TYPES
|
||||||
|
for subtype in valid_buttons
|
||||||
return triggers
|
]
|
||||||
|
|
||||||
|
|
||||||
async def async_attach_trigger(
|
async def async_attach_trigger(
|
||||||
|
@ -126,11 +126,8 @@ async def async_setup_entry(
|
|||||||
"""Set up the Honeywell Lyric climate platform based on a config entry."""
|
"""Set up the Honeywell Lyric climate platform based on a config entry."""
|
||||||
coordinator: DataUpdateCoordinator[Lyric] = hass.data[DOMAIN][entry.entry_id]
|
coordinator: DataUpdateCoordinator[Lyric] = hass.data[DOMAIN][entry.entry_id]
|
||||||
|
|
||||||
entities = []
|
async_add_entities(
|
||||||
|
(
|
||||||
for location in coordinator.data.locations:
|
|
||||||
for device in location.devices:
|
|
||||||
entities.append(
|
|
||||||
LyricClimate(
|
LyricClimate(
|
||||||
coordinator,
|
coordinator,
|
||||||
ClimateEntityDescription(
|
ClimateEntityDescription(
|
||||||
@ -140,10 +137,12 @@ async def async_setup_entry(
|
|||||||
location,
|
location,
|
||||||
device,
|
device,
|
||||||
)
|
)
|
||||||
|
for location in coordinator.data.locations
|
||||||
|
for device in location.devices
|
||||||
|
),
|
||||||
|
True,
|
||||||
)
|
)
|
||||||
|
|
||||||
async_add_entities(entities, True)
|
|
||||||
|
|
||||||
platform = entity_platform.async_get_current_platform()
|
platform = entity_platform.async_get_current_platform()
|
||||||
|
|
||||||
platform.async_register_entity_service(
|
platform.async_register_entity_service(
|
||||||
|
@ -149,7 +149,18 @@ async def async_setup_entry(
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
async_add_entities(entities)
|
async_add_entities(
|
||||||
|
LyricSensor(
|
||||||
|
coordinator,
|
||||||
|
device_sensor,
|
||||||
|
location,
|
||||||
|
device,
|
||||||
|
)
|
||||||
|
for location in coordinator.data.locations
|
||||||
|
for device in location.devices
|
||||||
|
for device_sensor in DEVICE_SENSORS
|
||||||
|
if device_sensor.suitable_fn(device)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class LyricSensor(LyricDeviceEntity, SensorEntity):
|
class LyricSensor(LyricDeviceEntity, SensorEntity):
|
||||||
|
@ -232,16 +232,16 @@ class MailboxPlatformsView(MailboxView):
|
|||||||
|
|
||||||
async def get(self, request: web.Request) -> web.Response:
|
async def get(self, request: web.Request) -> web.Response:
|
||||||
"""Retrieve list of platforms."""
|
"""Retrieve list of platforms."""
|
||||||
platforms: list[dict[str, Any]] = []
|
return self.json(
|
||||||
for mailbox in self.mailboxes:
|
[
|
||||||
platforms.append(
|
|
||||||
{
|
{
|
||||||
"name": mailbox.name,
|
"name": mailbox.name,
|
||||||
"has_media": mailbox.has_media,
|
"has_media": mailbox.has_media,
|
||||||
"can_delete": mailbox.can_delete,
|
"can_delete": mailbox.can_delete,
|
||||||
}
|
}
|
||||||
|
for mailbox in self.mailboxes
|
||||||
|
]
|
||||||
)
|
)
|
||||||
return self.json(platforms)
|
|
||||||
|
|
||||||
|
|
||||||
class MailboxMessageView(MailboxView):
|
class MailboxMessageView(MailboxView):
|
||||||
|
@ -432,9 +432,7 @@ class MatrixBot:
|
|||||||
self, target_rooms: Sequence[RoomAnyID], message_type: str, content: dict
|
self, target_rooms: Sequence[RoomAnyID], message_type: str, content: dict
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Wrap _handle_room_send for multiple target_rooms."""
|
"""Wrap _handle_room_send for multiple target_rooms."""
|
||||||
_tasks = []
|
await asyncio.wait(
|
||||||
for target_room in target_rooms:
|
|
||||||
_tasks.append(
|
|
||||||
self.hass.async_create_task(
|
self.hass.async_create_task(
|
||||||
self._handle_room_send(
|
self._handle_room_send(
|
||||||
target_room=target_room,
|
target_room=target_room,
|
||||||
@ -442,8 +440,8 @@ class MatrixBot:
|
|||||||
content=content,
|
content=content,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
for target_room in target_rooms
|
||||||
)
|
)
|
||||||
await asyncio.wait(_tasks)
|
|
||||||
|
|
||||||
async def _send_image(
|
async def _send_image(
|
||||||
self, image_path: str, target_rooms: Sequence[RoomAnyID]
|
self, image_path: str, target_rooms: Sequence[RoomAnyID]
|
||||||
|
@ -54,13 +54,13 @@ def setup_platform(
|
|||||||
discovery_info: DiscoveryInfoType | None = None,
|
discovery_info: DiscoveryInfoType | None = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Iterate through all MAX! Devices and add thermostats."""
|
"""Iterate through all MAX! Devices and add thermostats."""
|
||||||
devices = []
|
|
||||||
for handler in hass.data[DATA_KEY].values():
|
|
||||||
for device in handler.cube.devices:
|
|
||||||
if device.is_thermostat() or device.is_wallthermostat():
|
|
||||||
devices.append(MaxCubeClimate(handler, device))
|
|
||||||
|
|
||||||
add_entities(devices)
|
add_entities(
|
||||||
|
MaxCubeClimate(handler, device)
|
||||||
|
for handler in hass.data[DATA_KEY].values()
|
||||||
|
for device in handler.cube.devices
|
||||||
|
if device.is_thermostat() or device.is_wallthermostat()
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class MaxCubeClimate(ClimateEntity):
|
class MaxCubeClimate(ClimateEntity):
|
||||||
|
@ -44,13 +44,14 @@ async def async_setup_platform(
|
|||||||
api = hass.data[DATA_MELISSA]
|
api = hass.data[DATA_MELISSA]
|
||||||
devices = (await api.async_fetch_devices()).values()
|
devices = (await api.async_fetch_devices()).values()
|
||||||
|
|
||||||
all_devices = []
|
async_add_entities(
|
||||||
|
(
|
||||||
for device in devices:
|
MelissaClimate(api, device["serial_number"], device)
|
||||||
if device["type"] == "melissa":
|
for device in devices
|
||||||
all_devices.append(MelissaClimate(api, device["serial_number"], device))
|
if device["type"] == "melissa"
|
||||||
|
),
|
||||||
async_add_entities(all_devices, True)
|
True,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class MelissaClimate(ClimateEntity):
|
class MelissaClimate(ClimateEntity):
|
||||||
|
@ -117,14 +117,15 @@ def get_entities_for_valves(
|
|||||||
],
|
],
|
||||||
) -> list[CoordinatorEntity[MelnorDataUpdateCoordinator]]:
|
) -> list[CoordinatorEntity[MelnorDataUpdateCoordinator]]:
|
||||||
"""Get descriptions for valves."""
|
"""Get descriptions for valves."""
|
||||||
entities = []
|
entities: list[CoordinatorEntity[MelnorDataUpdateCoordinator]] = []
|
||||||
|
|
||||||
# This device may not have 4 valves total, but the library will only expose the right number of valves
|
# This device may not have 4 valves total, but the library will only expose the right number of valves
|
||||||
for i in range(1, 5):
|
for i in range(1, 5):
|
||||||
valve = coordinator.data[f"zone{i}"]
|
valve = coordinator.data[f"zone{i}"]
|
||||||
|
|
||||||
if valve is not None:
|
if valve is not None:
|
||||||
for description in descriptions:
|
entities.extend(
|
||||||
entities.append(function(valve, description))
|
function(valve, description) for description in descriptions
|
||||||
|
)
|
||||||
|
|
||||||
return entities
|
return entities
|
||||||
|
@ -56,16 +56,13 @@ async def async_setup_platform(
|
|||||||
api = hass.data[DATA_MICROSOFT_FACE]
|
api = hass.data[DATA_MICROSOFT_FACE]
|
||||||
attributes = config[CONF_ATTRIBUTES]
|
attributes = config[CONF_ATTRIBUTES]
|
||||||
|
|
||||||
entities = []
|
async_add_entities(
|
||||||
for camera in config[CONF_SOURCE]:
|
|
||||||
entities.append(
|
|
||||||
MicrosoftFaceDetectEntity(
|
MicrosoftFaceDetectEntity(
|
||||||
camera[CONF_ENTITY_ID], api, attributes, camera.get(CONF_NAME)
|
camera[CONF_ENTITY_ID], api, attributes, camera.get(CONF_NAME)
|
||||||
)
|
)
|
||||||
|
for camera in config[CONF_SOURCE]
|
||||||
)
|
)
|
||||||
|
|
||||||
async_add_entities(entities)
|
|
||||||
|
|
||||||
|
|
||||||
class MicrosoftFaceDetectEntity(ImageProcessingFaceEntity):
|
class MicrosoftFaceDetectEntity(ImageProcessingFaceEntity):
|
||||||
"""Microsoft Face API entity for identify."""
|
"""Microsoft Face API entity for identify."""
|
||||||
|
@ -38,9 +38,7 @@ async def async_setup_platform(
|
|||||||
face_group = config[CONF_GROUP]
|
face_group = config[CONF_GROUP]
|
||||||
confidence = config[CONF_CONFIDENCE]
|
confidence = config[CONF_CONFIDENCE]
|
||||||
|
|
||||||
entities = []
|
async_add_entities(
|
||||||
for camera in config[CONF_SOURCE]:
|
|
||||||
entities.append(
|
|
||||||
MicrosoftFaceIdentifyEntity(
|
MicrosoftFaceIdentifyEntity(
|
||||||
camera[CONF_ENTITY_ID],
|
camera[CONF_ENTITY_ID],
|
||||||
api,
|
api,
|
||||||
@ -48,10 +46,9 @@ async def async_setup_platform(
|
|||||||
confidence,
|
confidence,
|
||||||
camera.get(CONF_NAME),
|
camera.get(CONF_NAME),
|
||||||
)
|
)
|
||||||
|
for camera in config[CONF_SOURCE]
|
||||||
)
|
)
|
||||||
|
|
||||||
async_add_entities(entities)
|
|
||||||
|
|
||||||
|
|
||||||
class MicrosoftFaceIdentifyEntity(ImageProcessingFaceEntity):
|
class MicrosoftFaceIdentifyEntity(ImageProcessingFaceEntity):
|
||||||
"""Representation of the Microsoft Face API entity for identify."""
|
"""Representation of the Microsoft Face API entity for identify."""
|
||||||
|
@ -140,8 +140,7 @@ class MinecraftServer:
|
|||||||
players_list: list[str] = []
|
players_list: list[str] = []
|
||||||
|
|
||||||
if players := status_response.players.sample:
|
if players := status_response.players.sample:
|
||||||
for player in players:
|
players_list.extend(player.name for player in players)
|
||||||
players_list.append(player.name)
|
|
||||||
players_list.sort()
|
players_list.sort()
|
||||||
|
|
||||||
return MinecraftServerData(
|
return MinecraftServerData(
|
||||||
|
@ -93,10 +93,9 @@ class ModbusBinarySensor(BasePlatform, RestoreEntity, BinarySensorEntity):
|
|||||||
name=name,
|
name=name,
|
||||||
)
|
)
|
||||||
|
|
||||||
slaves: list[SlaveSensor] = []
|
return [
|
||||||
for idx in range(0, slave_count):
|
SlaveSensor(self._coordinator, idx, entry) for idx in range(0, slave_count)
|
||||||
slaves.append(SlaveSensor(self._coordinator, idx, entry))
|
]
|
||||||
return slaves
|
|
||||||
|
|
||||||
async def async_added_to_hass(self) -> None:
|
async def async_added_to_hass(self) -> None:
|
||||||
"""Handle entity which will be added."""
|
"""Handle entity which will be added."""
|
||||||
|
@ -94,10 +94,9 @@ class ModbusRegisterSensor(BaseStructPlatform, RestoreSensor, SensorEntity):
|
|||||||
name=name,
|
name=name,
|
||||||
)
|
)
|
||||||
|
|
||||||
slaves: list[SlaveSensor] = []
|
return [
|
||||||
for idx in range(0, slave_count):
|
SlaveSensor(self._coordinator, idx, entry) for idx in range(0, slave_count)
|
||||||
slaves.append(SlaveSensor(self._coordinator, idx, entry))
|
]
|
||||||
return slaves
|
|
||||||
|
|
||||||
async def async_added_to_hass(self) -> None:
|
async def async_added_to_hass(self) -> None:
|
||||||
"""Handle entity which will be added."""
|
"""Handle entity which will be added."""
|
||||||
|
@ -71,9 +71,8 @@ def setup_platform(
|
|||||||
discovery_info: DiscoveryInfoType | None = None,
|
discovery_info: DiscoveryInfoType | None = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up the MVGLive sensor."""
|
"""Set up the MVGLive sensor."""
|
||||||
sensors = []
|
add_entities(
|
||||||
for nextdeparture in config[CONF_NEXT_DEPARTURE]:
|
(
|
||||||
sensors.append(
|
|
||||||
MVGLiveSensor(
|
MVGLiveSensor(
|
||||||
nextdeparture.get(CONF_STATION),
|
nextdeparture.get(CONF_STATION),
|
||||||
nextdeparture.get(CONF_DESTINATIONS),
|
nextdeparture.get(CONF_DESTINATIONS),
|
||||||
@ -84,8 +83,10 @@ def setup_platform(
|
|||||||
nextdeparture.get(CONF_NUMBER),
|
nextdeparture.get(CONF_NUMBER),
|
||||||
nextdeparture.get(CONF_NAME),
|
nextdeparture.get(CONF_NAME),
|
||||||
)
|
)
|
||||||
|
for nextdeparture in config[CONF_NEXT_DEPARTURE]
|
||||||
|
),
|
||||||
|
True,
|
||||||
)
|
)
|
||||||
add_entities(sensors, True)
|
|
||||||
|
|
||||||
|
|
||||||
class MVGLiveSensor(SensorEntity):
|
class MVGLiveSensor(SensorEntity):
|
||||||
|
@ -52,13 +52,12 @@ async def async_setup_entry(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Set up the myStrom entities."""
|
"""Set up the myStrom entities."""
|
||||||
device: MyStromSwitch = hass.data[DOMAIN][entry.entry_id].device
|
device: MyStromSwitch = hass.data[DOMAIN][entry.entry_id].device
|
||||||
sensors = []
|
|
||||||
|
|
||||||
for description in SENSOR_TYPES:
|
async_add_entities(
|
||||||
if description.value_fn(device) is not None:
|
MyStromSwitchSensor(device, entry.title, description)
|
||||||
sensors.append(MyStromSwitchSensor(device, entry.title, description))
|
for description in SENSOR_TYPES
|
||||||
|
if description.value_fn(device) is not None
|
||||||
async_add_entities(sensors)
|
)
|
||||||
|
|
||||||
|
|
||||||
class MyStromSwitchSensor(SensorEntity):
|
class MyStromSwitchSensor(SensorEntity):
|
||||||
|
@ -25,22 +25,18 @@ async def async_setup_entry(
|
|||||||
async_add_entities: AddEntitiesCallback,
|
async_add_entities: AddEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up update entity."""
|
"""Set up update entity."""
|
||||||
entities: list[UpdateEntity] = []
|
|
||||||
coordinator: MyUplinkDataCoordinator = hass.data[DOMAIN][config_entry.entry_id]
|
coordinator: MyUplinkDataCoordinator = hass.data[DOMAIN][config_entry.entry_id]
|
||||||
|
|
||||||
# Setup update entities
|
async_add_entities(
|
||||||
for device_id in coordinator.data.devices:
|
|
||||||
entities.append(
|
|
||||||
MyUplinkDeviceUpdate(
|
MyUplinkDeviceUpdate(
|
||||||
coordinator=coordinator,
|
coordinator=coordinator,
|
||||||
device_id=device_id,
|
device_id=device_id,
|
||||||
entity_description=UPDATE_DESCRIPTION,
|
entity_description=UPDATE_DESCRIPTION,
|
||||||
unique_id_suffix="upd",
|
unique_id_suffix="upd",
|
||||||
)
|
)
|
||||||
|
for device_id in coordinator.data.devices
|
||||||
)
|
)
|
||||||
|
|
||||||
async_add_entities(entities)
|
|
||||||
|
|
||||||
|
|
||||||
class MyUplinkDeviceUpdate(MyUplinkEntity, UpdateEntity):
|
class MyUplinkDeviceUpdate(MyUplinkEntity, UpdateEntity):
|
||||||
"""Representation of a myUplink device update entity."""
|
"""Representation of a myUplink device update entity."""
|
||||||
|
@ -1399,14 +1399,12 @@ async def test_missing_discover_abbreviations(
|
|||||||
continue
|
continue
|
||||||
with open(fil, encoding="utf-8") as file:
|
with open(fil, encoding="utf-8") as file:
|
||||||
matches = re.findall(regex, file.read())
|
matches = re.findall(regex, file.read())
|
||||||
for match in matches:
|
missing.extend(
|
||||||
if (
|
f"{fil}: no abbreviation for {match[1]} ({match[0]})"
|
||||||
match[1] not in ABBREVIATIONS.values()
|
for match in matches
|
||||||
|
if match[1] not in ABBREVIATIONS.values()
|
||||||
and match[1] not in DEVICE_ABBREVIATIONS.values()
|
and match[1] not in DEVICE_ABBREVIATIONS.values()
|
||||||
and match[0] not in ABBREVIATIONS_WHITE_LIST
|
and match[0] not in ABBREVIATIONS_WHITE_LIST
|
||||||
):
|
|
||||||
missing.append(
|
|
||||||
f"{fil}: no abbreviation for {match[1]} ({match[0]})"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
assert not missing
|
assert not missing
|
||||||
|
Loading…
x
Reference in New Issue
Block a user