Improve lists in integrations [G-H] (#113168)
This commit is contained in:
parent
d4ae4a9cd0
commit
761933acfe
44 changed files with 392 additions and 433 deletions
|
@ -27,17 +27,11 @@ async def async_setup_entry(
|
|||
"""Defer sensor setup to the shared sensor module."""
|
||||
coordinator = await get_coordinator(hass)
|
||||
|
||||
entities: list[GaragesAmsterdamSensor] = []
|
||||
|
||||
for info_type in SENSORS:
|
||||
if getattr(coordinator.data[config_entry.data["garage_name"]], info_type) != "":
|
||||
entities.append(
|
||||
GaragesAmsterdamSensor(
|
||||
coordinator, config_entry.data["garage_name"], info_type
|
||||
async_add_entities(
|
||||
GaragesAmsterdamSensor(coordinator, config_entry.data["garage_name"], info_type)
|
||||
for info_type in SENSORS
|
||||
if getattr(coordinator.data[config_entry.data["garage_name"]], info_type) != ""
|
||||
)
|
||||
)
|
||||
|
||||
async_add_entities(entities)
|
||||
|
||||
|
||||
class GaragesAmsterdamSensor(GaragesAmsterdamEntity, SensorEntity):
|
||||
|
|
|
@ -62,22 +62,19 @@ async def async_setup_platform(
|
|||
None,
|
||||
)
|
||||
if monitor_config:
|
||||
entities: list[GEMSensor] = []
|
||||
|
||||
channel_configs = monitor_config[CONF_CHANNELS]
|
||||
for sensor in channel_configs:
|
||||
entities.append(
|
||||
entities: list[GEMSensor] = [
|
||||
CurrentSensor(
|
||||
monitor,
|
||||
sensor[CONF_NUMBER],
|
||||
sensor[CONF_NAME],
|
||||
sensor[CONF_NET_METERING],
|
||||
)
|
||||
)
|
||||
for sensor in channel_configs
|
||||
]
|
||||
|
||||
pulse_counter_configs = monitor_config[CONF_PULSE_COUNTERS]
|
||||
for sensor in pulse_counter_configs:
|
||||
entities.append(
|
||||
entities.extend(
|
||||
PulseCounter(
|
||||
monitor,
|
||||
sensor[CONF_NUMBER],
|
||||
|
@ -86,23 +83,24 @@ async def async_setup_platform(
|
|||
sensor[CONF_TIME_UNIT],
|
||||
sensor[CONF_COUNTED_QUANTITY_PER_PULSE],
|
||||
)
|
||||
for sensor in pulse_counter_configs
|
||||
)
|
||||
|
||||
temperature_sensor_configs = monitor_config[CONF_TEMPERATURE_SENSORS]
|
||||
for sensor in temperature_sensor_configs[CONF_SENSORS]:
|
||||
entities.append(
|
||||
entities.extend(
|
||||
TemperatureSensor(
|
||||
monitor,
|
||||
sensor[CONF_NUMBER],
|
||||
sensor[CONF_NAME],
|
||||
temperature_sensor_configs[CONF_TEMPERATURE_UNIT],
|
||||
)
|
||||
for sensor in temperature_sensor_configs[CONF_SENSORS]
|
||||
)
|
||||
|
||||
voltage_sensor_configs = monitor_config[CONF_VOLTAGE_SENSORS]
|
||||
for sensor in voltage_sensor_configs:
|
||||
entities.append(
|
||||
entities.extend(
|
||||
VoltageSensor(monitor, sensor[CONF_NUMBER], sensor[CONF_NAME])
|
||||
for sensor in voltage_sensor_configs
|
||||
)
|
||||
|
||||
async_add_entities(entities)
|
||||
|
|
|
@ -185,13 +185,11 @@ def groups_with_entity(hass: HomeAssistant, entity_id: str) -> list[str]:
|
|||
if DOMAIN not in hass.data:
|
||||
return []
|
||||
|
||||
groups = []
|
||||
|
||||
for group in hass.data[DOMAIN].entities:
|
||||
if entity_id in group.tracking:
|
||||
groups.append(group.entity_id)
|
||||
|
||||
return groups
|
||||
return [
|
||||
group.entity_id
|
||||
for group in hass.data[DOMAIN].entities
|
||||
if entity_id in group.tracking
|
||||
]
|
||||
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
|
|
|
@ -19,11 +19,7 @@ async def async_reproduce_states(
|
|||
reproduce_options: dict[str, Any] | None = None,
|
||||
) -> None:
|
||||
"""Reproduce component states."""
|
||||
states_copy = []
|
||||
for state in states:
|
||||
members = get_entity_ids(hass, state.entity_id)
|
||||
for member in members:
|
||||
states_copy.append(
|
||||
states_copy = [
|
||||
State(
|
||||
member,
|
||||
state.state,
|
||||
|
@ -32,7 +28,9 @@ async def async_reproduce_states(
|
|||
last_updated=state.last_updated,
|
||||
context=state.context,
|
||||
)
|
||||
)
|
||||
for state in states
|
||||
for member in get_entity_ids(hass, state.entity_id)
|
||||
]
|
||||
await async_reproduce_state(
|
||||
hass, states_copy, context=context, reproduce_options=reproduce_options
|
||||
)
|
||||
|
|
|
@ -87,14 +87,16 @@ async def async_setup_entry(
|
|||
) -> None:
|
||||
"""Set up the habitica sensors."""
|
||||
|
||||
entities: list[SensorEntity] = []
|
||||
name = config_entry.data[CONF_NAME]
|
||||
sensor_data = HabitipyData(hass.data[DOMAIN][config_entry.entry_id])
|
||||
await sensor_data.update()
|
||||
for sensor_type in SENSORS_TYPES:
|
||||
entities.append(HabitipySensor(name, sensor_type, sensor_data))
|
||||
for task_type in TASKS_TYPES:
|
||||
entities.append(HabitipyTaskSensor(name, task_type, sensor_data))
|
||||
|
||||
entities: list[SensorEntity] = [
|
||||
HabitipySensor(name, sensor_type, sensor_data) for sensor_type in SENSORS_TYPES
|
||||
]
|
||||
entities.extend(
|
||||
HabitipyTaskSensor(name, task_type, sensor_data) for task_type in TASKS_TYPES
|
||||
)
|
||||
async_add_entities(entities, True)
|
||||
|
||||
|
||||
|
|
|
@ -118,49 +118,47 @@ async def async_setup_entry(
|
|||
|
||||
entities: list[
|
||||
HassioOSSensor | HassioAddonSensor | CoreSensor | SupervisorSensor | HostSensor
|
||||
] = []
|
||||
|
||||
for addon in coordinator.data[DATA_KEY_ADDONS].values():
|
||||
for entity_description in ADDON_ENTITY_DESCRIPTIONS:
|
||||
entities.append(
|
||||
] = [
|
||||
HassioAddonSensor(
|
||||
addon=addon,
|
||||
coordinator=coordinator,
|
||||
entity_description=entity_description,
|
||||
)
|
||||
)
|
||||
for addon in coordinator.data[DATA_KEY_ADDONS].values()
|
||||
for entity_description in ADDON_ENTITY_DESCRIPTIONS
|
||||
]
|
||||
|
||||
for entity_description in CORE_ENTITY_DESCRIPTIONS:
|
||||
entities.append(
|
||||
entities.extend(
|
||||
CoreSensor(
|
||||
coordinator=coordinator,
|
||||
entity_description=entity_description,
|
||||
)
|
||||
for entity_description in CORE_ENTITY_DESCRIPTIONS
|
||||
)
|
||||
|
||||
for entity_description in SUPERVISOR_ENTITY_DESCRIPTIONS:
|
||||
entities.append(
|
||||
entities.extend(
|
||||
SupervisorSensor(
|
||||
coordinator=coordinator,
|
||||
entity_description=entity_description,
|
||||
)
|
||||
for entity_description in SUPERVISOR_ENTITY_DESCRIPTIONS
|
||||
)
|
||||
|
||||
for entity_description in HOST_ENTITY_DESCRIPTIONS:
|
||||
entities.append(
|
||||
entities.extend(
|
||||
HostSensor(
|
||||
coordinator=coordinator,
|
||||
entity_description=entity_description,
|
||||
)
|
||||
for entity_description in HOST_ENTITY_DESCRIPTIONS
|
||||
)
|
||||
|
||||
if coordinator.is_hass_os:
|
||||
for entity_description in OS_ENTITY_DESCRIPTIONS:
|
||||
entities.append(
|
||||
entities.extend(
|
||||
HassioOSSensor(
|
||||
coordinator=coordinator,
|
||||
entity_description=entity_description,
|
||||
)
|
||||
for entity_description in OS_ENTITY_DESCRIPTIONS
|
||||
)
|
||||
|
||||
async_add_entities(entities)
|
||||
|
|
|
@ -67,13 +67,13 @@ async def async_setup_entry(
|
|||
),
|
||||
]
|
||||
|
||||
for addon in coordinator.data[DATA_KEY_ADDONS].values():
|
||||
entities.append(
|
||||
entities.extend(
|
||||
SupervisorAddonUpdateEntity(
|
||||
addon=addon,
|
||||
coordinator=coordinator,
|
||||
entity_description=ENTITY_DESCRIPTION,
|
||||
)
|
||||
for addon in coordinator.data[DATA_KEY_ADDONS].values()
|
||||
)
|
||||
|
||||
if coordinator.is_hass_os:
|
||||
|
|
|
@ -49,11 +49,7 @@ def setup_platform(
|
|||
api_key = config[CONF_API_KEY]
|
||||
data = HaveIBeenPwnedData(emails, api_key)
|
||||
|
||||
devices = []
|
||||
for email in emails:
|
||||
devices.append(HaveIBeenPwnedSensor(data, email))
|
||||
|
||||
add_entities(devices)
|
||||
add_entities(HaveIBeenPwnedSensor(data, email) for email in emails)
|
||||
|
||||
|
||||
class HaveIBeenPwnedSensor(SensorEntity):
|
||||
|
|
|
@ -66,11 +66,7 @@ def setup_platform(
|
|||
if not disks:
|
||||
disks = [next(iter(hddtemp.data)).split("|")[0]]
|
||||
|
||||
dev = []
|
||||
for disk in disks:
|
||||
dev.append(HddTempSensor(name, disk, hddtemp))
|
||||
|
||||
add_entities(dev, True)
|
||||
add_entities((HddTempSensor(name, disk, hddtemp) for disk in disks), True)
|
||||
|
||||
|
||||
class HddTempSensor(SensorEntity):
|
||||
|
|
|
@ -86,16 +86,15 @@ async def async_setup_entry(
|
|||
name = config_entry.data[CONF_NAME]
|
||||
coordinator = hass.data[DOMAIN][entry_id]
|
||||
|
||||
sensors: list[HERETravelTimeSensor] = []
|
||||
for sensor_description in sensor_descriptions(config_entry.data[CONF_MODE]):
|
||||
sensors.append(
|
||||
sensors: list[HERETravelTimeSensor] = [
|
||||
HERETravelTimeSensor(
|
||||
entry_id,
|
||||
name,
|
||||
sensor_description,
|
||||
coordinator,
|
||||
)
|
||||
)
|
||||
for sensor_description in sensor_descriptions(config_entry.data[CONF_MODE])
|
||||
]
|
||||
sensors.append(OriginSensor(entry_id, name, coordinator))
|
||||
sensors.append(DestinationSensor(entry_id, name, coordinator))
|
||||
async_add_entities(sensors)
|
||||
|
|
|
@ -52,13 +52,17 @@ async def async_setup_entry(
|
|||
|
||||
hive = hass.data[DOMAIN][entry.entry_id]
|
||||
devices = hive.session.deviceList.get("binary_sensor")
|
||||
entities = []
|
||||
if devices:
|
||||
for description in BINARY_SENSOR_TYPES:
|
||||
for dev in devices:
|
||||
if dev["hiveType"] == description.key:
|
||||
entities.append(HiveBinarySensorEntity(hive, dev, description))
|
||||
async_add_entities(entities, True)
|
||||
if not devices:
|
||||
return
|
||||
async_add_entities(
|
||||
(
|
||||
HiveBinarySensorEntity(hive, dev, description)
|
||||
for dev in devices
|
||||
for description in BINARY_SENSOR_TYPES
|
||||
if dev["hiveType"] == description.key
|
||||
),
|
||||
True,
|
||||
)
|
||||
|
||||
|
||||
class HiveBinarySensorEntity(HiveEntity, BinarySensorEntity):
|
||||
|
|
|
@ -59,11 +59,8 @@ async def async_setup_entry(
|
|||
|
||||
hive = hass.data[DOMAIN][entry.entry_id]
|
||||
devices = hive.session.deviceList.get("climate")
|
||||
entities = []
|
||||
if devices:
|
||||
for dev in devices:
|
||||
entities.append(HiveClimateEntity(hive, dev))
|
||||
async_add_entities(entities, True)
|
||||
async_add_entities((HiveClimateEntity(hive, dev) for dev in devices), True)
|
||||
|
||||
platform = entity_platform.async_get_current_platform()
|
||||
|
||||
|
|
|
@ -34,11 +34,9 @@ async def async_setup_entry(
|
|||
|
||||
hive: Hive = hass.data[DOMAIN][entry.entry_id]
|
||||
devices = hive.session.deviceList.get("light")
|
||||
entities = []
|
||||
if devices:
|
||||
for dev in devices:
|
||||
entities.append(HiveDeviceLight(hive, dev))
|
||||
async_add_entities(entities, True)
|
||||
if not devices:
|
||||
return
|
||||
async_add_entities((HiveDeviceLight(hive, dev) for dev in devices), True)
|
||||
|
||||
|
||||
class HiveDeviceLight(HiveEntity, LightEntity):
|
||||
|
|
|
@ -54,13 +54,17 @@ async def async_setup_entry(
|
|||
"""Set up Hive thermostat based on a config entry."""
|
||||
hive = hass.data[DOMAIN][entry.entry_id]
|
||||
devices = hive.session.deviceList.get("sensor")
|
||||
entities = []
|
||||
if devices:
|
||||
for description in SENSOR_TYPES:
|
||||
for dev in devices:
|
||||
if dev["hiveType"] == description.key:
|
||||
entities.append(HiveSensorEntity(hive, dev, description))
|
||||
async_add_entities(entities, True)
|
||||
if not devices:
|
||||
return
|
||||
async_add_entities(
|
||||
(
|
||||
HiveSensorEntity(hive, dev, description)
|
||||
for dev in devices
|
||||
for description in SENSOR_TYPES
|
||||
if dev["hiveType"] == description.key
|
||||
),
|
||||
True,
|
||||
)
|
||||
|
||||
|
||||
class HiveSensorEntity(HiveEntity, SensorEntity):
|
||||
|
|
|
@ -36,13 +36,17 @@ async def async_setup_entry(
|
|||
|
||||
hive = hass.data[DOMAIN][entry.entry_id]
|
||||
devices = hive.session.deviceList.get("switch")
|
||||
entities = []
|
||||
if devices:
|
||||
for description in SWITCH_TYPES:
|
||||
for dev in devices:
|
||||
if dev["hiveType"] == description.key:
|
||||
entities.append(HiveSwitch(hive, dev, description))
|
||||
async_add_entities(entities, True)
|
||||
if not devices:
|
||||
return
|
||||
async_add_entities(
|
||||
(
|
||||
HiveSwitch(hive, dev, description)
|
||||
for dev in devices
|
||||
for description in SWITCH_TYPES
|
||||
if dev["hiveType"] == description.key
|
||||
),
|
||||
True,
|
||||
)
|
||||
|
||||
|
||||
class HiveSwitch(HiveEntity, SwitchEntity):
|
||||
|
|
|
@ -49,11 +49,8 @@ async def async_setup_entry(
|
|||
|
||||
hive = hass.data[DOMAIN][entry.entry_id]
|
||||
devices = hive.session.deviceList.get("water_heater")
|
||||
entities = []
|
||||
if devices:
|
||||
for dev in devices:
|
||||
entities.append(HiveWaterHeater(hive, dev))
|
||||
async_add_entities(entities, True)
|
||||
async_add_entities((HiveWaterHeater(hive, dev) for dev in devices), True)
|
||||
|
||||
platform = entity_platform.async_get_current_platform()
|
||||
|
||||
|
|
|
@ -928,13 +928,15 @@ class HomeKit:
|
|||
connection: tuple[str, str],
|
||||
) -> None:
|
||||
"""Purge bridges that exist from failed pairing or manual resets."""
|
||||
devices_to_purge = []
|
||||
for entry in dev_reg.devices.values():
|
||||
if self._entry_id in entry.config_entries and (
|
||||
devices_to_purge = [
|
||||
entry.id
|
||||
for entry in dev_reg.devices.values()
|
||||
if self._entry_id in entry.config_entries
|
||||
and (
|
||||
identifier not in entry.identifiers # type: ignore[comparison-overlap]
|
||||
or connection not in entry.connections
|
||||
):
|
||||
devices_to_purge.append(entry.id)
|
||||
)
|
||||
]
|
||||
|
||||
for device_id in devices_to_purge:
|
||||
dev_reg.async_remove_device(device_id)
|
||||
|
|
|
@ -326,10 +326,7 @@ def validate_media_player_features(state: State, feature_list: str) -> bool:
|
|||
# Auto detected
|
||||
return True
|
||||
|
||||
error_list = []
|
||||
for feature in feature_list:
|
||||
if feature not in supported_modes:
|
||||
error_list.append(feature)
|
||||
error_list = [feature for feature in feature_list if feature not in supported_modes]
|
||||
|
||||
if error_list:
|
||||
_LOGGER.error(
|
||||
|
|
|
@ -160,7 +160,7 @@ def enumerate_stateless_switch_group(service: Service) -> list[dict[str, Any]]:
|
|||
)
|
||||
)
|
||||
|
||||
results = []
|
||||
results: list[dict[str, Any]] = []
|
||||
for idx, switch in enumerate(switches):
|
||||
char = switch[CharacteristicsTypes.INPUT_EVENT]
|
||||
|
||||
|
@ -168,14 +168,14 @@ def enumerate_stateless_switch_group(service: Service) -> list[dict[str, Any]]:
|
|||
# manufacturer might not - clamp options to what they say.
|
||||
all_values = clamp_enum_to_char(InputEventValues, char)
|
||||
|
||||
for event_type in all_values:
|
||||
results.append(
|
||||
results.extend(
|
||||
{
|
||||
"characteristic": char.iid,
|
||||
"value": event_type,
|
||||
"type": f"button{idx + 1}",
|
||||
"subtype": HK_TO_HA_INPUT_EVENT_VALUES[event_type],
|
||||
}
|
||||
for event_type in all_values
|
||||
)
|
||||
return results
|
||||
|
||||
|
@ -188,17 +188,15 @@ def enumerate_doorbell(service: Service) -> list[dict[str, Any]]:
|
|||
# manufacturer might not - clamp options to what they say.
|
||||
all_values = clamp_enum_to_char(InputEventValues, input_event)
|
||||
|
||||
results = []
|
||||
for event_type in all_values:
|
||||
results.append(
|
||||
return [
|
||||
{
|
||||
"characteristic": input_event.iid,
|
||||
"value": event_type,
|
||||
"type": "doorbell",
|
||||
"subtype": HK_TO_HA_INPUT_EVENT_VALUES[event_type],
|
||||
}
|
||||
)
|
||||
return results
|
||||
for event_type in all_values
|
||||
]
|
||||
|
||||
|
||||
TRIGGER_FINDERS = {
|
||||
|
|
|
@ -118,11 +118,10 @@ async def async_setup_entry(
|
|||
)
|
||||
)
|
||||
|
||||
for switch in switches:
|
||||
# The Apple docs say that if we number the buttons ourselves
|
||||
# We do it in service label index order. `switches` is already in
|
||||
# that order.
|
||||
entities.append(
|
||||
entities.extend(
|
||||
HomeKitEventEntity(
|
||||
conn,
|
||||
switch,
|
||||
|
@ -132,6 +131,7 @@ async def async_setup_entry(
|
|||
translation_key="button",
|
||||
),
|
||||
)
|
||||
for switch in switches
|
||||
)
|
||||
|
||||
elif service.type == ServicesTypes.STATELESS_PROGRAMMABLE_SWITCH:
|
||||
|
|
|
@ -259,9 +259,7 @@ def setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||
hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, hass.data[DATA_HOMEMATIC].stop)
|
||||
|
||||
# Init homematic hubs
|
||||
entity_hubs = []
|
||||
for hub_name in conf[CONF_HOSTS]:
|
||||
entity_hubs.append(HMHub(hass, homematic, hub_name))
|
||||
entity_hubs = [HMHub(hass, homematic, hub_name) for hub_name in conf[CONF_HOSTS]]
|
||||
|
||||
def _hm_service_virtualkey(service: ServiceCall) -> None:
|
||||
"""Service to handle virtualkey servicecalls."""
|
||||
|
|
|
@ -113,11 +113,7 @@ class HMThermostat(HMDevice, ClimateEntity):
|
|||
@property
|
||||
def preset_modes(self):
|
||||
"""Return a list of available preset modes."""
|
||||
preset_modes = []
|
||||
for mode in self._hmdevice.ACTIONNODE:
|
||||
if mode in HM_PRESET_MAP:
|
||||
preset_modes.append(HM_PRESET_MAP[mode])
|
||||
return preset_modes
|
||||
return [HM_PRESET_MAP[mode] for mode in self._hmdevice.ACTIONNODE]
|
||||
|
||||
@property
|
||||
def current_humidity(self):
|
||||
|
|
|
@ -23,11 +23,7 @@ def setup_platform(
|
|||
if discovery_info is None:
|
||||
return
|
||||
|
||||
devices = []
|
||||
for conf in discovery_info[ATTR_DISCOVER_DEVICES]:
|
||||
devices.append(HMLock(conf))
|
||||
|
||||
add_entities(devices, True)
|
||||
add_entities((HMLock(conf) for conf in discovery_info[ATTR_DISCOVER_DEVICES]), True)
|
||||
|
||||
|
||||
class HMLock(HMDevice, LockEntity):
|
||||
|
|
|
@ -86,14 +86,14 @@ async def async_setup_entry(
|
|||
if isinstance(device, AsyncTiltVibrationSensor):
|
||||
entities.append(HomematicipTiltVibrationSensor(hap, device))
|
||||
if isinstance(device, AsyncWiredInput32):
|
||||
for channel in range(1, 33):
|
||||
entities.append(
|
||||
entities.extend(
|
||||
HomematicipMultiContactInterface(hap, device, channel=channel)
|
||||
for channel in range(1, 33)
|
||||
)
|
||||
elif isinstance(device, AsyncFullFlushContactInterface6):
|
||||
for channel in range(1, 7):
|
||||
entities.append(
|
||||
entities.extend(
|
||||
HomematicipMultiContactInterface(hap, device, channel=channel)
|
||||
for channel in range(1, 7)
|
||||
)
|
||||
elif isinstance(
|
||||
device, (AsyncContactInterface, AsyncFullFlushContactInterface)
|
||||
|
|
|
@ -20,13 +20,12 @@ async def async_setup_entry(
|
|||
) -> None:
|
||||
"""Set up the HomematicIP button from a config entry."""
|
||||
hap = hass.data[HMIPC_DOMAIN][config_entry.unique_id]
|
||||
entities: list[HomematicipGenericEntity] = []
|
||||
for device in hap.home.devices:
|
||||
if isinstance(device, AsyncWallMountedGarageDoorController):
|
||||
entities.append(HomematicipGarageDoorControllerButton(hap, device))
|
||||
|
||||
if entities:
|
||||
async_add_entities(entities)
|
||||
async_add_entities(
|
||||
HomematicipGarageDoorControllerButton(hap, device)
|
||||
for device in hap.home.devices
|
||||
if isinstance(device, AsyncWallMountedGarageDoorController)
|
||||
)
|
||||
|
||||
|
||||
class HomematicipGarageDoorControllerButton(HomematicipGenericEntity, ButtonEntity):
|
||||
|
|
|
@ -51,12 +51,12 @@ async def async_setup_entry(
|
|||
) -> None:
|
||||
"""Set up the HomematicIP climate from a config entry."""
|
||||
hap = hass.data[HMIPC_DOMAIN][config_entry.unique_id]
|
||||
entities = []
|
||||
for device in hap.home.groups:
|
||||
if isinstance(device, AsyncHeatingGroup):
|
||||
entities.append(HomematicipHeatingGroup(hap, device))
|
||||
|
||||
async_add_entities(entities)
|
||||
async_add_entities(
|
||||
HomematicipHeatingGroup(hap, device)
|
||||
for device in hap.home.groups
|
||||
if isinstance(device, AsyncHeatingGroup)
|
||||
)
|
||||
|
||||
|
||||
class HomematicipHeatingGroup(HomematicipGenericEntity, ClimateEntity):
|
||||
|
|
|
@ -41,14 +41,18 @@ async def async_setup_entry(
|
|||
) -> None:
|
||||
"""Set up the HomematicIP cover from a config entry."""
|
||||
hap = hass.data[HMIPC_DOMAIN][config_entry.unique_id]
|
||||
entities: list[HomematicipGenericEntity] = []
|
||||
entities: list[HomematicipGenericEntity] = [
|
||||
HomematicipCoverShutterGroup(hap, group)
|
||||
for group in hap.home.groups
|
||||
if isinstance(group, AsyncExtendedLinkedShutterGroup)
|
||||
]
|
||||
for device in hap.home.devices:
|
||||
if isinstance(device, AsyncBlindModule):
|
||||
entities.append(HomematicipBlindModule(hap, device))
|
||||
elif isinstance(device, AsyncDinRailBlind4):
|
||||
for channel in range(1, 5):
|
||||
entities.append(
|
||||
entities.extend(
|
||||
HomematicipMultiCoverSlats(hap, device, channel=channel)
|
||||
for channel in range(1, 5)
|
||||
)
|
||||
elif isinstance(device, AsyncFullFlushBlind):
|
||||
entities.append(HomematicipCoverSlats(hap, device))
|
||||
|
@ -59,10 +63,6 @@ async def async_setup_entry(
|
|||
):
|
||||
entities.append(HomematicipGarageDoorModule(hap, device))
|
||||
|
||||
for group in hap.home.groups:
|
||||
if isinstance(group, AsyncExtendedLinkedShutterGroup):
|
||||
entities.append(HomematicipCoverShutterGroup(hap, group))
|
||||
|
||||
async_add_entities(entities)
|
||||
|
||||
|
||||
|
|
|
@ -56,8 +56,10 @@ async def async_setup_entry(
|
|||
)
|
||||
)
|
||||
elif isinstance(device, (AsyncWiredDimmer3, AsyncDinRailDimmer3)):
|
||||
for channel in range(1, 4):
|
||||
entities.append(HomematicipMultiDimmer(hap, device, channel=channel))
|
||||
entities.extend(
|
||||
HomematicipMultiDimmer(hap, device, channel=channel)
|
||||
for channel in range(1, 4)
|
||||
)
|
||||
elif isinstance(
|
||||
device,
|
||||
(AsyncDimmer, AsyncPluggableDimmer, AsyncBrandDimmer, AsyncFullFlushDimmer),
|
||||
|
|
|
@ -39,7 +39,11 @@ async def async_setup_entry(
|
|||
) -> None:
|
||||
"""Set up the HomematicIP switch from a config entry."""
|
||||
hap = hass.data[HMIPC_DOMAIN][config_entry.unique_id]
|
||||
entities: list[HomematicipGenericEntity] = []
|
||||
entities: list[HomematicipGenericEntity] = [
|
||||
HomematicipGroupSwitch(hap, group)
|
||||
for group in hap.home.groups
|
||||
if isinstance(group, (AsyncExtendedLinkedSwitchingGroup, AsyncSwitchingGroup))
|
||||
]
|
||||
for device in hap.home.devices:
|
||||
if isinstance(device, AsyncBrandSwitchMeasuring):
|
||||
# BrandSwitchMeasuring inherits PlugableSwitchMeasuring
|
||||
|
@ -51,13 +55,17 @@ async def async_setup_entry(
|
|||
):
|
||||
entities.append(HomematicipSwitchMeasuring(hap, device))
|
||||
elif isinstance(device, AsyncWiredSwitch8):
|
||||
for channel in range(1, 9):
|
||||
entities.append(HomematicipMultiSwitch(hap, device, channel=channel))
|
||||
entities.extend(
|
||||
HomematicipMultiSwitch(hap, device, channel=channel)
|
||||
for channel in range(1, 9)
|
||||
)
|
||||
elif isinstance(device, AsyncDinRailSwitch):
|
||||
entities.append(HomematicipMultiSwitch(hap, device, channel=1))
|
||||
elif isinstance(device, AsyncDinRailSwitch4):
|
||||
for channel in range(1, 5):
|
||||
entities.append(HomematicipMultiSwitch(hap, device, channel=channel))
|
||||
entities.extend(
|
||||
HomematicipMultiSwitch(hap, device, channel=channel)
|
||||
for channel in range(1, 5)
|
||||
)
|
||||
elif isinstance(
|
||||
device,
|
||||
(
|
||||
|
@ -68,8 +76,10 @@ async def async_setup_entry(
|
|||
):
|
||||
entities.append(HomematicipSwitch(hap, device))
|
||||
elif isinstance(device, AsyncOpenCollector8Module):
|
||||
for channel in range(1, 9):
|
||||
entities.append(HomematicipMultiSwitch(hap, device, channel=channel))
|
||||
entities.extend(
|
||||
HomematicipMultiSwitch(hap, device, channel=channel)
|
||||
for channel in range(1, 9)
|
||||
)
|
||||
elif isinstance(
|
||||
device,
|
||||
(
|
||||
|
@ -79,12 +89,10 @@ async def async_setup_entry(
|
|||
AsyncMultiIOBox,
|
||||
),
|
||||
):
|
||||
for channel in range(1, 3):
|
||||
entities.append(HomematicipMultiSwitch(hap, device, channel=channel))
|
||||
|
||||
for group in hap.home.groups:
|
||||
if isinstance(group, (AsyncExtendedLinkedSwitchingGroup, AsyncSwitchingGroup)):
|
||||
entities.append(HomematicipGroupSwitch(hap, group))
|
||||
entities.extend(
|
||||
HomematicipMultiSwitch(hap, device, channel=channel)
|
||||
for channel in range(1, 3)
|
||||
)
|
||||
|
||||
async_add_entities(entities)
|
||||
|
||||
|
|
|
@ -86,14 +86,13 @@ async def async_setup_entry(
|
|||
) -> None:
|
||||
"""Set up the Honeywell thermostat."""
|
||||
data: HoneywellData = hass.data[DOMAIN][config_entry.entry_id]
|
||||
sensors = []
|
||||
|
||||
for device in data.devices.values():
|
||||
for description in SENSOR_TYPES:
|
||||
if getattr(device, description.key) is not None:
|
||||
sensors.append(HoneywellSensor(device, description))
|
||||
|
||||
async_add_entities(sensors)
|
||||
async_add_entities(
|
||||
HoneywellSensor(device, description)
|
||||
for device in data.devices.values()
|
||||
for description in SENSOR_TYPES
|
||||
if getattr(device, description.key) is not None
|
||||
)
|
||||
|
||||
|
||||
class HoneywellSensor(SensorEntity):
|
||||
|
|
|
@ -674,8 +674,7 @@ async def async_setup_entry(
|
|||
items = filter(key_meta.include.search, items)
|
||||
if key_meta.exclude:
|
||||
items = [x for x in items if not key_meta.exclude.search(x)]
|
||||
for item in items:
|
||||
sensors.append(
|
||||
sensors.extend(
|
||||
HuaweiLteSensor(
|
||||
router,
|
||||
key,
|
||||
|
@ -684,6 +683,7 @@ async def async_setup_entry(
|
|||
item, HuaweiSensorEntityDescription(key=item)
|
||||
),
|
||||
)
|
||||
for item in items
|
||||
)
|
||||
|
||||
async_add_entities(sensors, True)
|
||||
|
|
|
@ -81,12 +81,12 @@ class HueButtonEventEntity(HueBaseEntity, EventEntity):
|
|||
# fill the event types based on the features the switch supports
|
||||
hue_dev_id = self.controller.get_device(self.resource.id).id
|
||||
model_id = self.bridge.api.devices[hue_dev_id].product_data.product_name
|
||||
event_types: list[str] = []
|
||||
self._attr_event_types: list[str] = [
|
||||
event_type.value
|
||||
for event_type in DEVICE_SPECIFIC_EVENT_TYPES.get(
|
||||
model_id, DEFAULT_BUTTON_EVENT_TYPES
|
||||
):
|
||||
event_types.append(event_type.value)
|
||||
self._attr_event_types = event_types
|
||||
)
|
||||
]
|
||||
self._attr_translation_placeholders = {
|
||||
"button_id": self.resource.metadata.control_id
|
||||
}
|
||||
|
|
|
@ -90,16 +90,13 @@ def async_get_triggers(
|
|||
# Get Hue device id from device identifier
|
||||
hue_dev_id = get_hue_device_id(device_entry)
|
||||
# extract triggers from all button resources of this Hue device
|
||||
triggers = []
|
||||
triggers: list[dict[str, Any]] = []
|
||||
model_id = api.devices[hue_dev_id].product_data.product_name
|
||||
|
||||
for resource in api.devices.get_sensors(hue_dev_id):
|
||||
# button triggers
|
||||
if resource.type == ResourceTypes.BUTTON:
|
||||
for event_type in DEVICE_SPECIFIC_EVENT_TYPES.get(
|
||||
model_id, DEFAULT_BUTTON_EVENT_TYPES
|
||||
):
|
||||
triggers.append(
|
||||
triggers.extend(
|
||||
{
|
||||
CONF_DEVICE_ID: device_entry.id,
|
||||
CONF_DOMAIN: DOMAIN,
|
||||
|
@ -108,12 +105,13 @@ def async_get_triggers(
|
|||
CONF_SUBTYPE: resource.metadata.control_id,
|
||||
CONF_UNIQUE_ID: resource.id,
|
||||
}
|
||||
for event_type in DEVICE_SPECIFIC_EVENT_TYPES.get(
|
||||
model_id, DEFAULT_BUTTON_EVENT_TYPES
|
||||
)
|
||||
)
|
||||
# relative_rotary triggers
|
||||
elif resource.type == ResourceTypes.RELATIVE_ROTARY:
|
||||
for event_type in DEFAULT_ROTARY_EVENT_TYPES:
|
||||
for sub_type in DEFAULT_ROTARY_EVENT_SUBTYPES:
|
||||
triggers.append(
|
||||
triggers.extend(
|
||||
{
|
||||
CONF_DEVICE_ID: device_entry.id,
|
||||
CONF_DOMAIN: DOMAIN,
|
||||
|
@ -122,6 +120,8 @@ def async_get_triggers(
|
|||
CONF_SUBTYPE: sub_type.value,
|
||||
CONF_UNIQUE_ID: resource.id,
|
||||
}
|
||||
for event_type in DEFAULT_ROTARY_EVENT_TYPES
|
||||
for sub_type in DEFAULT_ROTARY_EVENT_SUBTYPES
|
||||
)
|
||||
return triggers
|
||||
|
||||
|
|
|
@ -85,9 +85,7 @@ async def async_setup_entry(
|
|||
entities: list[ButtonEntity] = []
|
||||
for shade in pv_entry.shade_data.values():
|
||||
room_name = getattr(pv_entry.room_data.get(shade.room_id), ATTR_NAME, "")
|
||||
for description in BUTTONS_SHADE:
|
||||
if description.create_entity_fn(shade):
|
||||
entities.append(
|
||||
entities.extend(
|
||||
PowerviewShadeButton(
|
||||
pv_entry.coordinator,
|
||||
pv_entry.device_info,
|
||||
|
@ -96,8 +94,9 @@ async def async_setup_entry(
|
|||
shade.name,
|
||||
description,
|
||||
)
|
||||
for description in BUTTONS_SHADE
|
||||
if description.create_entity_fn(shade)
|
||||
)
|
||||
|
||||
async_add_entities(entities)
|
||||
|
||||
|
||||
|
|
|
@ -66,9 +66,7 @@ async def async_setup_entry(
|
|||
entities: list[PowerViewNumber] = []
|
||||
for shade in pv_entry.shade_data.values():
|
||||
room_name = getattr(pv_entry.room_data.get(shade.room_id), ATTR_NAME, "")
|
||||
for description in NUMBERS:
|
||||
if description.create_entity_fn(shade):
|
||||
entities.append(
|
||||
entities.extend(
|
||||
PowerViewNumber(
|
||||
pv_entry.coordinator,
|
||||
pv_entry.device_info,
|
||||
|
@ -77,8 +75,9 @@ async def async_setup_entry(
|
|||
shade.name,
|
||||
description,
|
||||
)
|
||||
for description in NUMBERS
|
||||
if description.create_entity_fn(shade)
|
||||
)
|
||||
|
||||
async_add_entities(entities)
|
||||
|
||||
|
||||
|
|
|
@ -68,9 +68,7 @@ async def async_setup_entry(
|
|||
if not shade.has_battery_info():
|
||||
continue
|
||||
room_name = getattr(pv_entry.room_data.get(shade.room_id), ATTR_NAME, "")
|
||||
for description in DROPDOWNS:
|
||||
if description.create_entity_fn(shade):
|
||||
entities.append(
|
||||
entities.extend(
|
||||
PowerViewSelect(
|
||||
pv_entry.coordinator,
|
||||
pv_entry.device_info,
|
||||
|
@ -79,8 +77,9 @@ async def async_setup_entry(
|
|||
shade.name,
|
||||
description,
|
||||
)
|
||||
for description in DROPDOWNS
|
||||
if description.create_entity_fn(shade)
|
||||
)
|
||||
|
||||
async_add_entities(entities)
|
||||
|
||||
|
||||
|
|
|
@ -88,9 +88,7 @@ async def async_setup_entry(
|
|||
entities: list[PowerViewSensor] = []
|
||||
for shade in pv_entry.shade_data.values():
|
||||
room_name = getattr(pv_entry.room_data.get(shade.room_id), ATTR_NAME, "")
|
||||
for description in SENSORS:
|
||||
if description.create_entity_fn(shade):
|
||||
entities.append(
|
||||
entities.extend(
|
||||
PowerViewSensor(
|
||||
pv_entry.coordinator,
|
||||
pv_entry.device_info,
|
||||
|
@ -99,8 +97,9 @@ async def async_setup_entry(
|
|||
shade.name,
|
||||
description,
|
||||
)
|
||||
for description in SENSORS
|
||||
if description.create_entity_fn(shade)
|
||||
)
|
||||
|
||||
async_add_entities(entities)
|
||||
|
||||
|
||||
|
|
|
@ -75,10 +75,10 @@ async def async_setup_entry(
|
|||
entities.append(
|
||||
HydrawiseBinarySensor(coordinator, BINARY_SENSOR_STATUS, controller)
|
||||
)
|
||||
for zone in controller.zones:
|
||||
for description in BINARY_SENSOR_TYPES:
|
||||
entities.append(
|
||||
entities.extend(
|
||||
HydrawiseBinarySensor(coordinator, description, controller, zone)
|
||||
for zone in controller.zones
|
||||
for description in BINARY_SENSOR_TYPES
|
||||
)
|
||||
async_add_entities(entities)
|
||||
|
||||
|
|
|
@ -100,18 +100,16 @@ async def async_setup_entry(
|
|||
def instance_add(instance_num: int, instance_name: str) -> None:
|
||||
"""Add entities for a new Hyperion instance."""
|
||||
assert server_id
|
||||
switches = []
|
||||
for component in COMPONENT_SWITCHES:
|
||||
switches.append(
|
||||
async_add_entities(
|
||||
HyperionComponentSwitch(
|
||||
server_id,
|
||||
instance_num,
|
||||
instance_name,
|
||||
component,
|
||||
entry_data[CONF_INSTANCE_CLIENTS][instance_num],
|
||||
),
|
||||
)
|
||||
async_add_entities(switches)
|
||||
for component in COMPONENT_SWITCHES
|
||||
)
|
||||
|
||||
@callback
|
||||
def instance_remove(instance_num: int) -> None:
|
||||
|
|
|
@ -241,9 +241,7 @@ def test_get_significant_states_only(hass_history) -> None:
|
|||
return hass.states.get(entity_id)
|
||||
|
||||
start = dt_util.utcnow() - timedelta(minutes=4)
|
||||
points = []
|
||||
for i in range(1, 4):
|
||||
points.append(start + timedelta(minutes=i))
|
||||
points = [start + timedelta(minutes=i) for i in range(1, 4)]
|
||||
|
||||
states = []
|
||||
with freeze_time(start) as freezer:
|
||||
|
|
|
@ -257,9 +257,7 @@ def test_get_significant_states_only(legacy_hass_history) -> None:
|
|||
return hass.states.get(entity_id)
|
||||
|
||||
start = dt_util.utcnow() - timedelta(minutes=4)
|
||||
points = []
|
||||
for i in range(1, 4):
|
||||
points.append(start + timedelta(minutes=i))
|
||||
points = [start + timedelta(minutes=i) for i in range(1, 4)]
|
||||
|
||||
states = []
|
||||
with freeze_time(start) as freezer:
|
||||
|
|
|
@ -116,9 +116,7 @@ async def test_enumerate_remote(
|
|||
},
|
||||
]
|
||||
|
||||
for button in ("button1", "button2", "button3", "button4"):
|
||||
for subtype in ("single_press", "double_press", "long_press"):
|
||||
expected.append(
|
||||
expected.extend(
|
||||
{
|
||||
"device_id": device.id,
|
||||
"domain": "homekit_controller",
|
||||
|
@ -127,6 +125,8 @@ async def test_enumerate_remote(
|
|||
"subtype": subtype,
|
||||
"metadata": {},
|
||||
}
|
||||
for button in ("button1", "button2", "button3", "button4")
|
||||
for subtype in ("single_press", "double_press", "long_press")
|
||||
)
|
||||
|
||||
triggers = await async_get_device_automations(
|
||||
|
@ -167,8 +167,7 @@ async def test_enumerate_button(
|
|||
},
|
||||
]
|
||||
|
||||
for subtype in ("single_press", "double_press", "long_press"):
|
||||
expected.append(
|
||||
expected.extend(
|
||||
{
|
||||
"device_id": device.id,
|
||||
"domain": "homekit_controller",
|
||||
|
@ -177,6 +176,7 @@ async def test_enumerate_button(
|
|||
"subtype": subtype,
|
||||
"metadata": {},
|
||||
}
|
||||
for subtype in ("single_press", "double_press", "long_press")
|
||||
)
|
||||
|
||||
triggers = await async_get_device_automations(
|
||||
|
@ -217,8 +217,7 @@ async def test_enumerate_doorbell(
|
|||
},
|
||||
]
|
||||
|
||||
for subtype in ("single_press", "double_press", "long_press"):
|
||||
expected.append(
|
||||
expected.extend(
|
||||
{
|
||||
"device_id": device.id,
|
||||
"domain": "homekit_controller",
|
||||
|
@ -227,6 +226,7 @@ async def test_enumerate_doorbell(
|
|||
"subtype": subtype,
|
||||
"metadata": {},
|
||||
}
|
||||
for subtype in ("single_press", "double_press", "long_press")
|
||||
)
|
||||
|
||||
triggers = await async_get_device_automations(
|
||||
|
|
|
@ -171,15 +171,9 @@ class HomeTemplate(Home):
|
|||
|
||||
def _generate_mocks(self):
|
||||
"""Generate mocks for groups and devices."""
|
||||
mock_devices = []
|
||||
for device in self.devices:
|
||||
mock_devices.append(_get_mock(device))
|
||||
self.devices = mock_devices
|
||||
self.devices = [_get_mock(device) for device in self.devices]
|
||||
|
||||
mock_groups = []
|
||||
for group in self.groups:
|
||||
mock_groups.append(_get_mock(group))
|
||||
self.groups = mock_groups
|
||||
self.groups = [_get_mock(group) for group in self.groups]
|
||||
|
||||
def download_configuration(self):
|
||||
"""Return the initial json config."""
|
||||
|
|
|
@ -49,10 +49,7 @@ async def test_sync_turn_off(hass: HomeAssistant) -> None:
|
|||
|
||||
|
||||
def _create_tuples(enum: Enum, constant_prefix: str) -> list[tuple[Enum, str]]:
|
||||
result = []
|
||||
for enum in enum:
|
||||
result.append((enum, constant_prefix))
|
||||
return result
|
||||
return [(enum_field, constant_prefix) for enum_field in enum]
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue