mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 01:08:12 +00:00
Improve lists in integrations [B] (#113069)
This commit is contained in:
parent
1853c2d73a
commit
23ffcaf187
@ -100,10 +100,11 @@ async def async_setup_entry(
|
||||
"""Set up BAF fan sensors."""
|
||||
data: BAFData = hass.data[DOMAIN][entry.entry_id]
|
||||
device = data.device
|
||||
sensors_descriptions: list[BAFSensorDescription] = []
|
||||
for description in DEFINED_ONLY_SENSORS:
|
||||
if getattr(device, description.key):
|
||||
sensors_descriptions.append(description)
|
||||
sensors_descriptions: list[BAFSensorDescription] = [
|
||||
description
|
||||
for description in DEFINED_ONLY_SENSORS
|
||||
if getattr(device, description.key)
|
||||
]
|
||||
if device.has_auto_comfort:
|
||||
sensors_descriptions.extend(AUTO_COMFORT_SENSORS)
|
||||
if device.has_fan:
|
||||
|
@ -313,9 +313,9 @@ class BayesianBinarySensor(BinarySensorEntity):
|
||||
self.hass, observations, text=f"{self._attr_name}/{entity}"
|
||||
)
|
||||
|
||||
all_template_observations: list[Observation] = []
|
||||
for observations in self.observations_by_template.values():
|
||||
all_template_observations.append(observations[0])
|
||||
all_template_observations: list[Observation] = [
|
||||
observations[0] for observations in self.observations_by_template.values()
|
||||
]
|
||||
if len(all_template_observations) == 2:
|
||||
raise_mirrored_entries(
|
||||
self.hass,
|
||||
|
@ -217,13 +217,13 @@ async def async_setup_entry(
|
||||
) -> None:
|
||||
"""Set up Blue Current sensors."""
|
||||
connector: Connector = hass.data[DOMAIN][entry.entry_id]
|
||||
sensor_list: list[SensorEntity] = []
|
||||
for evse_id in connector.charge_points:
|
||||
for sensor in SENSORS:
|
||||
sensor_list.append(ChargePointSensor(connector, sensor, evse_id))
|
||||
sensor_list: list[SensorEntity] = [
|
||||
ChargePointSensor(connector, sensor, evse_id)
|
||||
for evse_id in connector.charge_points
|
||||
for sensor in SENSORS
|
||||
]
|
||||
|
||||
for grid_sensor in GRID_SENSORS:
|
||||
sensor_list.append(GridSensor(connector, grid_sensor))
|
||||
sensor_list.extend(GridSensor(connector, sensor) for sensor in GRID_SENSORS)
|
||||
|
||||
async_add_entities(sensor_list)
|
||||
|
||||
|
@ -686,20 +686,15 @@ class BluesoundPlayer(MediaPlayerEntity):
|
||||
if self._status is None or (self.is_grouped and not self.is_master):
|
||||
return None
|
||||
|
||||
sources = []
|
||||
sources = [source["title"] for source in self._preset_items]
|
||||
|
||||
for source in self._preset_items:
|
||||
sources.append(source["title"])
|
||||
sources.extend(
|
||||
source["title"]
|
||||
for source in self._services_items
|
||||
if source["type"] in ("LocalMusic", "RadioService")
|
||||
)
|
||||
|
||||
for source in [
|
||||
x
|
||||
for x in self._services_items
|
||||
if x["type"] in ("LocalMusic", "RadioService")
|
||||
]:
|
||||
sources.append(source["title"])
|
||||
|
||||
for source in self._capture_items:
|
||||
sources.append(source["title"])
|
||||
sources.extend(source["title"] for source in self._capture_items)
|
||||
|
||||
return sources
|
||||
|
||||
|
@ -249,39 +249,47 @@ class BluetoothMatcherIndexBase(Generic[_T]):
|
||||
|
||||
def match(self, service_info: BluetoothServiceInfoBleak) -> list[_T]:
|
||||
"""Check for a match."""
|
||||
matches = []
|
||||
matches: list[_T] = []
|
||||
if (name := service_info.name) and (
|
||||
local_name_matchers := self.local_name.get(
|
||||
name[:LOCAL_NAME_MIN_MATCH_LENGTH]
|
||||
)
|
||||
):
|
||||
for matcher in local_name_matchers:
|
||||
if ble_device_matches(matcher, service_info):
|
||||
matches.append(matcher)
|
||||
matches.extend(
|
||||
matcher
|
||||
for matcher in local_name_matchers
|
||||
if ble_device_matches(matcher, service_info)
|
||||
)
|
||||
|
||||
if self.service_data_uuid_set and service_info.service_data:
|
||||
for service_data_uuid in self.service_data_uuid_set.intersection(
|
||||
service_info.service_data
|
||||
):
|
||||
for matcher in self.service_data_uuid[service_data_uuid]:
|
||||
if ble_device_matches(matcher, service_info):
|
||||
matches.append(matcher)
|
||||
matches.extend(
|
||||
matcher
|
||||
for service_data_uuid in self.service_data_uuid_set.intersection(
|
||||
service_info.service_data
|
||||
)
|
||||
for matcher in self.service_data_uuid[service_data_uuid]
|
||||
if ble_device_matches(matcher, service_info)
|
||||
)
|
||||
|
||||
if self.manufacturer_id_set and service_info.manufacturer_data:
|
||||
for manufacturer_id in self.manufacturer_id_set.intersection(
|
||||
service_info.manufacturer_data
|
||||
):
|
||||
for matcher in self.manufacturer_id[manufacturer_id]:
|
||||
if ble_device_matches(matcher, service_info):
|
||||
matches.append(matcher)
|
||||
matches.extend(
|
||||
matcher
|
||||
for manufacturer_id in self.manufacturer_id_set.intersection(
|
||||
service_info.manufacturer_data
|
||||
)
|
||||
for matcher in self.manufacturer_id[manufacturer_id]
|
||||
if ble_device_matches(matcher, service_info)
|
||||
)
|
||||
|
||||
if self.service_uuid_set and service_info.service_uuids:
|
||||
for service_uuid in self.service_uuid_set.intersection(
|
||||
service_info.service_uuids
|
||||
):
|
||||
for matcher in self.service_uuid[service_uuid]:
|
||||
if ble_device_matches(matcher, service_info):
|
||||
matches.append(matcher)
|
||||
matches.extend(
|
||||
matcher
|
||||
for service_uuid in self.service_uuid_set.intersection(
|
||||
service_info.service_uuids
|
||||
)
|
||||
for matcher in self.service_uuid[service_uuid]
|
||||
if ble_device_matches(matcher, service_info)
|
||||
)
|
||||
|
||||
return matches
|
||||
|
||||
|
@ -31,17 +31,10 @@ async def async_setup_entry(
|
||||
"""Set up the MyBMW lock from config entry."""
|
||||
coordinator: BMWDataUpdateCoordinator = hass.data[DOMAIN][config_entry.entry_id]
|
||||
|
||||
entities: list[BMWLock] = []
|
||||
|
||||
for vehicle in coordinator.account.vehicles:
|
||||
if not coordinator.read_only:
|
||||
entities.append(
|
||||
BMWLock(
|
||||
coordinator,
|
||||
vehicle,
|
||||
)
|
||||
)
|
||||
async_add_entities(entities)
|
||||
if not coordinator.read_only:
|
||||
async_add_entities(
|
||||
BMWLock(coordinator, vehicle) for vehicle in coordinator.account.vehicles
|
||||
)
|
||||
|
||||
|
||||
class BMWLock(BMWBaseEntity, LockEntity):
|
||||
|
@ -23,39 +23,38 @@ async def async_setup_entry(
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the SHC binary sensor platform."""
|
||||
entities: list[BinarySensorEntity] = []
|
||||
session: SHCSession = hass.data[DOMAIN][config_entry.entry_id][DATA_SESSION]
|
||||
|
||||
for binary_sensor in (
|
||||
session.device_helper.shutter_contacts + session.device_helper.shutter_contacts2
|
||||
):
|
||||
entities.append(
|
||||
ShutterContactSensor(
|
||||
device=binary_sensor,
|
||||
parent_id=session.information.unique_id,
|
||||
entry_id=config_entry.entry_id,
|
||||
)
|
||||
entities: list[BinarySensorEntity] = [
|
||||
ShutterContactSensor(
|
||||
device=binary_sensor,
|
||||
parent_id=session.information.unique_id,
|
||||
entry_id=config_entry.entry_id,
|
||||
)
|
||||
for binary_sensor in (
|
||||
session.device_helper.shutter_contacts
|
||||
+ session.device_helper.shutter_contacts2
|
||||
)
|
||||
]
|
||||
|
||||
for binary_sensor in (
|
||||
session.device_helper.motion_detectors
|
||||
+ session.device_helper.shutter_contacts
|
||||
+ session.device_helper.shutter_contacts2
|
||||
+ session.device_helper.smoke_detectors
|
||||
+ session.device_helper.thermostats
|
||||
+ session.device_helper.twinguards
|
||||
+ session.device_helper.universal_switches
|
||||
+ session.device_helper.wallthermostats
|
||||
+ session.device_helper.water_leakage_detectors
|
||||
):
|
||||
if binary_sensor.supports_batterylevel:
|
||||
entities.append(
|
||||
BatterySensor(
|
||||
device=binary_sensor,
|
||||
parent_id=session.information.unique_id,
|
||||
entry_id=config_entry.entry_id,
|
||||
)
|
||||
)
|
||||
entities.extend(
|
||||
BatterySensor(
|
||||
device=binary_sensor,
|
||||
parent_id=session.information.unique_id,
|
||||
entry_id=config_entry.entry_id,
|
||||
)
|
||||
for binary_sensor in (
|
||||
session.device_helper.motion_detectors
|
||||
+ session.device_helper.shutter_contacts
|
||||
+ session.device_helper.shutter_contacts2
|
||||
+ session.device_helper.smoke_detectors
|
||||
+ session.device_helper.thermostats
|
||||
+ session.device_helper.twinguards
|
||||
+ session.device_helper.universal_switches
|
||||
+ session.device_helper.wallthermostats
|
||||
+ session.device_helper.water_leakage_detectors
|
||||
)
|
||||
)
|
||||
|
||||
async_add_entities(entities)
|
||||
|
||||
|
@ -25,19 +25,16 @@ async def async_setup_entry(
|
||||
) -> None:
|
||||
"""Set up the SHC cover platform."""
|
||||
|
||||
entities = []
|
||||
session: SHCSession = hass.data[DOMAIN][config_entry.entry_id][DATA_SESSION]
|
||||
|
||||
for cover in session.device_helper.shutter_controls:
|
||||
entities.append(
|
||||
ShutterControlCover(
|
||||
device=cover,
|
||||
parent_id=session.information.unique_id,
|
||||
entry_id=config_entry.entry_id,
|
||||
)
|
||||
async_add_entities(
|
||||
ShutterControlCover(
|
||||
device=cover,
|
||||
parent_id=session.information.unique_id,
|
||||
entry_id=config_entry.entry_id,
|
||||
)
|
||||
|
||||
async_add_entities(entities)
|
||||
for cover in session.device_helper.shutter_controls
|
||||
)
|
||||
|
||||
|
||||
class ShutterControlCover(SHCEntity, CoverEntity):
|
||||
|
@ -84,65 +84,66 @@ async def async_setup_entry(
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the SHC switch platform."""
|
||||
entities: list[SwitchEntity] = []
|
||||
session: SHCSession = hass.data[DOMAIN][config_entry.entry_id][DATA_SESSION]
|
||||
|
||||
for switch in session.device_helper.smart_plugs:
|
||||
entities.append(
|
||||
SHCSwitch(
|
||||
device=switch,
|
||||
parent_id=session.information.unique_id,
|
||||
entry_id=config_entry.entry_id,
|
||||
description=SWITCH_TYPES["smartplug"],
|
||||
)
|
||||
)
|
||||
entities.append(
|
||||
SHCRoutingSwitch(
|
||||
device=switch,
|
||||
parent_id=session.information.unique_id,
|
||||
entry_id=config_entry.entry_id,
|
||||
)
|
||||
entities: list[SwitchEntity] = [
|
||||
SHCSwitch(
|
||||
device=switch,
|
||||
parent_id=session.information.unique_id,
|
||||
entry_id=config_entry.entry_id,
|
||||
description=SWITCH_TYPES["smartplug"],
|
||||
)
|
||||
for switch in session.device_helper.smart_plugs
|
||||
]
|
||||
|
||||
for switch in session.device_helper.light_switches_bsm:
|
||||
entities.append(
|
||||
SHCSwitch(
|
||||
device=switch,
|
||||
parent_id=session.information.unique_id,
|
||||
entry_id=config_entry.entry_id,
|
||||
description=SWITCH_TYPES["lightswitch"],
|
||||
)
|
||||
entities.extend(
|
||||
SHCRoutingSwitch(
|
||||
device=switch,
|
||||
parent_id=session.information.unique_id,
|
||||
entry_id=config_entry.entry_id,
|
||||
)
|
||||
for switch in session.device_helper.smart_plugs
|
||||
)
|
||||
|
||||
for switch in session.device_helper.smart_plugs_compact:
|
||||
entities.append(
|
||||
SHCSwitch(
|
||||
device=switch,
|
||||
parent_id=session.information.unique_id,
|
||||
entry_id=config_entry.entry_id,
|
||||
description=SWITCH_TYPES["smartplugcompact"],
|
||||
)
|
||||
entities.extend(
|
||||
SHCSwitch(
|
||||
device=switch,
|
||||
parent_id=session.information.unique_id,
|
||||
entry_id=config_entry.entry_id,
|
||||
description=SWITCH_TYPES["lightswitch"],
|
||||
)
|
||||
for switch in session.device_helper.light_switches_bsm
|
||||
)
|
||||
|
||||
for switch in session.device_helper.camera_eyes:
|
||||
entities.append(
|
||||
SHCSwitch(
|
||||
device=switch,
|
||||
parent_id=session.information.unique_id,
|
||||
entry_id=config_entry.entry_id,
|
||||
description=SWITCH_TYPES["cameraeyes"],
|
||||
)
|
||||
entities.extend(
|
||||
SHCSwitch(
|
||||
device=switch,
|
||||
parent_id=session.information.unique_id,
|
||||
entry_id=config_entry.entry_id,
|
||||
description=SWITCH_TYPES["smartplugcompact"],
|
||||
)
|
||||
for switch in session.device_helper.smart_plugs_compact
|
||||
)
|
||||
|
||||
for switch in session.device_helper.camera_360:
|
||||
entities.append(
|
||||
SHCSwitch(
|
||||
device=switch,
|
||||
parent_id=session.information.unique_id,
|
||||
entry_id=config_entry.entry_id,
|
||||
description=SWITCH_TYPES["camera360"],
|
||||
)
|
||||
entities.extend(
|
||||
SHCSwitch(
|
||||
device=switch,
|
||||
parent_id=session.information.unique_id,
|
||||
entry_id=config_entry.entry_id,
|
||||
description=SWITCH_TYPES["cameraeyes"],
|
||||
)
|
||||
for switch in session.device_helper.camera_eyes
|
||||
)
|
||||
|
||||
entities.extend(
|
||||
SHCSwitch(
|
||||
device=switch,
|
||||
parent_id=session.information.unique_id,
|
||||
entry_id=config_entry.entry_id,
|
||||
description=SWITCH_TYPES["camera360"],
|
||||
)
|
||||
for switch in session.device_helper.camera_360
|
||||
)
|
||||
|
||||
async_add_entities(entities)
|
||||
|
||||
|
@ -339,12 +339,11 @@ async def async_setup_entry(
|
||||
)
|
||||
entity_registry.async_update_entity(entity_id, new_unique_id=new_unique_id)
|
||||
|
||||
sensors = []
|
||||
|
||||
for description in SENSOR_TYPES:
|
||||
if description.value(coordinator.data) is not None:
|
||||
sensors.append(BrotherPrinterSensor(coordinator, description))
|
||||
async_add_entities(sensors, False)
|
||||
async_add_entities(
|
||||
BrotherPrinterSensor(coordinator, description)
|
||||
for description in SENSOR_TYPES
|
||||
if description.value(coordinator.data) is not None
|
||||
)
|
||||
|
||||
|
||||
class BrotherPrinterSensor(
|
||||
|
Loading…
x
Reference in New Issue
Block a user