mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 16:57:53 +00:00
Improve lists in integrations [I-K] (#113221)
This commit is contained in:
parent
dbb07c98e2
commit
7e0aac3feb
@ -25,10 +25,10 @@ async def async_setup_entry(
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up discovered binary sensors."""
|
||||
devs = []
|
||||
for dev in hass.data[AQUALINK_DOMAIN][DOMAIN]:
|
||||
devs.append(HassAqualinkBinarySensor(dev))
|
||||
async_add_entities(devs, True)
|
||||
async_add_entities(
|
||||
(HassAqualinkBinarySensor(dev) for dev in hass.data[AQUALINK_DOMAIN][DOMAIN]),
|
||||
True,
|
||||
)
|
||||
|
||||
|
||||
class HassAqualinkBinarySensor(AqualinkEntity, BinarySensorEntity):
|
||||
|
@ -33,10 +33,13 @@ async def async_setup_entry(
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up discovered switches."""
|
||||
devs = []
|
||||
for dev in hass.data[AQUALINK_DOMAIN][CLIMATE_DOMAIN]:
|
||||
devs.append(HassAqualinkThermostat(dev))
|
||||
async_add_entities(devs, True)
|
||||
async_add_entities(
|
||||
(
|
||||
HassAqualinkThermostat(dev)
|
||||
for dev in hass.data[AQUALINK_DOMAIN][CLIMATE_DOMAIN]
|
||||
),
|
||||
True,
|
||||
)
|
||||
|
||||
|
||||
class HassAqualinkThermostat(AqualinkEntity, ClimateEntity):
|
||||
|
@ -31,10 +31,9 @@ async def async_setup_entry(
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up discovered lights."""
|
||||
devs = []
|
||||
for dev in hass.data[AQUALINK_DOMAIN][DOMAIN]:
|
||||
devs.append(HassAqualinkLight(dev))
|
||||
async_add_entities(devs, True)
|
||||
async_add_entities(
|
||||
(HassAqualinkLight(dev) for dev in hass.data[AQUALINK_DOMAIN][DOMAIN]), True
|
||||
)
|
||||
|
||||
|
||||
class HassAqualinkLight(AqualinkEntity, LightEntity):
|
||||
|
@ -22,10 +22,9 @@ async def async_setup_entry(
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up discovered sensors."""
|
||||
devs = []
|
||||
for dev in hass.data[AQUALINK_DOMAIN][DOMAIN]:
|
||||
devs.append(HassAqualinkSensor(dev))
|
||||
async_add_entities(devs, True)
|
||||
async_add_entities(
|
||||
(HassAqualinkSensor(dev) for dev in hass.data[AQUALINK_DOMAIN][DOMAIN]), True
|
||||
)
|
||||
|
||||
|
||||
class HassAqualinkSensor(AqualinkEntity, SensorEntity):
|
||||
|
@ -24,10 +24,9 @@ async def async_setup_entry(
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up discovered switches."""
|
||||
devs = []
|
||||
for dev in hass.data[AQUALINK_DOMAIN][DOMAIN]:
|
||||
devs.append(HassAqualinkSwitch(dev))
|
||||
async_add_entities(devs, True)
|
||||
async_add_entities(
|
||||
(HassAqualinkSwitch(dev) for dev in hass.data[AQUALINK_DOMAIN][DOMAIN]), True
|
||||
)
|
||||
|
||||
|
||||
class HassAqualinkSwitch(AqualinkEntity, SwitchEntity):
|
||||
|
@ -319,11 +319,12 @@ class IcloudAccount:
|
||||
|
||||
def get_devices_with_name(self, name: str) -> list[Any]:
|
||||
"""Get devices by name."""
|
||||
result = []
|
||||
name_slug = slugify(name.replace(" ", "", 99))
|
||||
for device in self.devices.values():
|
||||
if slugify(device.name.replace(" ", "", 99)) == name_slug:
|
||||
result.append(device)
|
||||
result = [
|
||||
device
|
||||
for device in self.devices.values()
|
||||
if slugify(device.name.replace(" ", "", 99)) == name_slug
|
||||
]
|
||||
if not result:
|
||||
raise ValueError(f"No device with name {name}")
|
||||
return result
|
||||
|
@ -84,10 +84,11 @@ def _remove_override(address, options):
|
||||
new_options = {}
|
||||
if options.get(CONF_X10):
|
||||
new_options[CONF_X10] = options.get(CONF_X10)
|
||||
new_overrides = []
|
||||
for override in options[CONF_OVERRIDE]:
|
||||
if override[CONF_ADDRESS] != address:
|
||||
new_overrides.append(override)
|
||||
new_overrides = [
|
||||
override
|
||||
for override in options[CONF_OVERRIDE]
|
||||
if override[CONF_ADDRESS] != address
|
||||
]
|
||||
if new_overrides:
|
||||
new_options[CONF_OVERRIDE] = new_overrides
|
||||
return new_options
|
||||
@ -100,13 +101,14 @@ def _remove_x10(device, options):
|
||||
new_options = {}
|
||||
if options.get(CONF_OVERRIDE):
|
||||
new_options[CONF_OVERRIDE] = options.get(CONF_OVERRIDE)
|
||||
new_x10 = []
|
||||
for existing_device in options[CONF_X10]:
|
||||
new_x10 = [
|
||||
existing_device
|
||||
for existing_device in options[CONF_X10]
|
||||
if (
|
||||
existing_device[CONF_HOUSECODE].lower() != housecode
|
||||
or existing_device[CONF_UNITCODE] != unitcode
|
||||
):
|
||||
new_x10.append(existing_device)
|
||||
)
|
||||
]
|
||||
if new_x10:
|
||||
new_options[CONF_X10] = new_x10
|
||||
return new_options, housecode, unitcode
|
||||
|
@ -103,17 +103,18 @@ def add_device_override(config_data, new_override):
|
||||
except ValueError as err:
|
||||
raise ValueError("Incorrect values") from err
|
||||
|
||||
overrides = []
|
||||
|
||||
for override in config_data.get(CONF_OVERRIDE, []):
|
||||
if override[CONF_ADDRESS] != address:
|
||||
overrides.append(override)
|
||||
|
||||
curr_override = {}
|
||||
curr_override[CONF_ADDRESS] = address
|
||||
curr_override[CONF_CAT] = cat
|
||||
curr_override[CONF_SUBCAT] = subcat
|
||||
overrides.append(curr_override)
|
||||
overrides = [
|
||||
override
|
||||
for override in config_data.get(CONF_OVERRIDE, [])
|
||||
if override[CONF_ADDRESS] != address
|
||||
]
|
||||
overrides.append(
|
||||
{
|
||||
CONF_ADDRESS: address,
|
||||
CONF_CAT: cat,
|
||||
CONF_SUBCAT: subcat,
|
||||
}
|
||||
)
|
||||
|
||||
new_config = {}
|
||||
if config_data.get(CONF_X10):
|
||||
@ -124,21 +125,20 @@ def add_device_override(config_data, new_override):
|
||||
|
||||
def add_x10_device(config_data, new_x10):
|
||||
"""Add a new X10 device to X10 device list."""
|
||||
x10_devices = []
|
||||
for x10_device in config_data.get(CONF_X10, []):
|
||||
if (
|
||||
x10_device[CONF_HOUSECODE] != new_x10[CONF_HOUSECODE]
|
||||
or x10_device[CONF_UNITCODE] != new_x10[CONF_UNITCODE]
|
||||
):
|
||||
x10_devices.append(x10_device)
|
||||
|
||||
curr_device = {}
|
||||
curr_device[CONF_HOUSECODE] = new_x10[CONF_HOUSECODE]
|
||||
curr_device[CONF_UNITCODE] = new_x10[CONF_UNITCODE]
|
||||
curr_device[CONF_PLATFORM] = new_x10[CONF_PLATFORM]
|
||||
curr_device[CONF_DIM_STEPS] = new_x10[CONF_DIM_STEPS]
|
||||
x10_devices.append(curr_device)
|
||||
|
||||
x10_devices = [
|
||||
x10_device
|
||||
for x10_device in config_data.get(CONF_X10, [])
|
||||
if x10_device[CONF_HOUSECODE] != new_x10[CONF_HOUSECODE]
|
||||
or x10_device[CONF_UNITCODE] != new_x10[CONF_UNITCODE]
|
||||
]
|
||||
x10_devices.append(
|
||||
{
|
||||
CONF_HOUSECODE: new_x10[CONF_HOUSECODE],
|
||||
CONF_UNITCODE: new_x10[CONF_UNITCODE],
|
||||
CONF_PLATFORM: new_x10[CONF_PLATFORM],
|
||||
CONF_DIM_STEPS: new_x10[CONF_DIM_STEPS],
|
||||
}
|
||||
)
|
||||
new_config = {}
|
||||
if config_data.get(CONF_OVERRIDE):
|
||||
new_config[CONF_OVERRIDE] = config_data[CONF_OVERRIDE]
|
||||
@ -223,17 +223,14 @@ def build_hub_schema(
|
||||
|
||||
def build_remove_override_schema(data):
|
||||
"""Build the schema to remove device overrides in config flow options."""
|
||||
selection = []
|
||||
for override in data:
|
||||
selection.append(override[CONF_ADDRESS])
|
||||
selection = [override[CONF_ADDRESS] for override in data]
|
||||
return vol.Schema({vol.Required(CONF_ADDRESS): vol.In(selection)})
|
||||
|
||||
|
||||
def build_remove_x10_schema(data):
|
||||
"""Build the schema to remove an X10 device in config flow options."""
|
||||
selection = []
|
||||
for device in data:
|
||||
housecode = device[CONF_HOUSECODE].upper()
|
||||
unitcode = device[CONF_UNITCODE]
|
||||
selection.append(f"Housecode: {housecode}, Unitcode: {unitcode}")
|
||||
selection = [
|
||||
f"Housecode: {device[CONF_HOUSECODE].upper()}, Unitcode: {device[CONF_UNITCODE]}"
|
||||
for device in data
|
||||
]
|
||||
return vol.Schema({vol.Required(CONF_DEVICE): vol.In(selection)})
|
||||
|
@ -38,7 +38,15 @@ async def async_setup_entry(
|
||||
ISYNodeQueryButtonEntity
|
||||
| ISYNodeBeepButtonEntity
|
||||
| ISYNetworkResourceButtonEntity
|
||||
] = []
|
||||
] = [
|
||||
ISYNetworkResourceButtonEntity(
|
||||
node=node,
|
||||
name=node.name,
|
||||
unique_id=isy_data.uid_base(node),
|
||||
device_info=device_info[CONF_NETWORK],
|
||||
)
|
||||
for node in isy_data.net_resources
|
||||
]
|
||||
|
||||
for node in isy_data.root_nodes[Platform.BUTTON]:
|
||||
entities.append(
|
||||
@ -61,16 +69,6 @@ async def async_setup_entry(
|
||||
)
|
||||
)
|
||||
|
||||
for node in isy_data.net_resources:
|
||||
entities.append(
|
||||
ISYNetworkResourceButtonEntity(
|
||||
node=node,
|
||||
name=node.name,
|
||||
unique_id=isy_data.uid_base(node),
|
||||
device_info=device_info[CONF_NETWORK],
|
||||
)
|
||||
)
|
||||
|
||||
# Add entity to query full system
|
||||
entities.append(
|
||||
ISYNodeQueryButtonEntity(
|
||||
|
@ -64,14 +64,14 @@ async def async_setup_entry(
|
||||
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
||||
) -> None:
|
||||
"""Set up the ISY thermostat platform."""
|
||||
entities = []
|
||||
|
||||
isy_data: IsyData = hass.data[DOMAIN][entry.entry_id]
|
||||
devices: dict[str, DeviceInfo] = isy_data.devices
|
||||
for node in isy_data.nodes[Platform.CLIMATE]:
|
||||
entities.append(ISYThermostatEntity(node, devices.get(node.primary_node)))
|
||||
|
||||
async_add_entities(entities)
|
||||
async_add_entities(
|
||||
ISYThermostatEntity(node, devices.get(node.primary_node))
|
||||
for node in isy_data.nodes[Platform.CLIMATE]
|
||||
)
|
||||
|
||||
|
||||
class ISYThermostatEntity(ISYNodeEntity, ClimateEntity):
|
||||
|
@ -27,13 +27,16 @@ async def async_setup_entry(
|
||||
) -> None:
|
||||
"""Set up the ISY cover platform."""
|
||||
isy_data: IsyData = hass.data[DOMAIN][entry.entry_id]
|
||||
entities: list[ISYCoverEntity | ISYCoverProgramEntity] = []
|
||||
devices: dict[str, DeviceInfo] = isy_data.devices
|
||||
for node in isy_data.nodes[Platform.COVER]:
|
||||
entities.append(ISYCoverEntity(node, devices.get(node.primary_node)))
|
||||
entities: list[ISYCoverEntity | ISYCoverProgramEntity] = [
|
||||
ISYCoverEntity(node, devices.get(node.primary_node))
|
||||
for node in isy_data.nodes[Platform.COVER]
|
||||
]
|
||||
|
||||
for name, status, actions in isy_data.programs[Platform.COVER]:
|
||||
entities.append(ISYCoverProgramEntity(name, status, actions))
|
||||
entities.extend(
|
||||
ISYCoverProgramEntity(name, status, actions)
|
||||
for name, status, actions in isy_data.programs[Platform.COVER]
|
||||
)
|
||||
|
||||
async_add_entities(entities)
|
||||
|
||||
|
@ -32,13 +32,15 @@ async def async_setup_entry(
|
||||
"""Set up the ISY fan platform."""
|
||||
isy_data: IsyData = hass.data[DOMAIN][entry.entry_id]
|
||||
devices: dict[str, DeviceInfo] = isy_data.devices
|
||||
entities: list[ISYFanEntity | ISYFanProgramEntity] = []
|
||||
entities: list[ISYFanEntity | ISYFanProgramEntity] = [
|
||||
ISYFanEntity(node, devices.get(node.primary_node))
|
||||
for node in isy_data.nodes[Platform.FAN]
|
||||
]
|
||||
|
||||
for node in isy_data.nodes[Platform.FAN]:
|
||||
entities.append(ISYFanEntity(node, devices.get(node.primary_node)))
|
||||
|
||||
for name, status, actions in isy_data.programs[Platform.FAN]:
|
||||
entities.append(ISYFanProgramEntity(name, status, actions))
|
||||
entities.extend(
|
||||
ISYFanProgramEntity(name, status, actions)
|
||||
for name, status, actions in isy_data.programs[Platform.FAN]
|
||||
)
|
||||
|
||||
async_add_entities(entities)
|
||||
|
||||
|
@ -32,13 +32,10 @@ async def async_setup_entry(
|
||||
isy_options = entry.options
|
||||
restore_light_state = isy_options.get(CONF_RESTORE_LIGHT_STATE, False)
|
||||
|
||||
entities = []
|
||||
for node in isy_data.nodes[Platform.LIGHT]:
|
||||
entities.append(
|
||||
ISYLightEntity(node, restore_light_state, devices.get(node.primary_node))
|
||||
)
|
||||
|
||||
async_add_entities(entities)
|
||||
async_add_entities(
|
||||
ISYLightEntity(node, restore_light_state, devices.get(node.primary_node))
|
||||
for node in isy_data.nodes[Platform.LIGHT]
|
||||
)
|
||||
|
||||
|
||||
class ISYLightEntity(ISYNodeEntity, LightEntity, RestoreEntity):
|
||||
|
@ -53,12 +53,15 @@ async def async_setup_entry(
|
||||
"""Set up the ISY lock platform."""
|
||||
isy_data: IsyData = hass.data[DOMAIN][entry.entry_id]
|
||||
devices: dict[str, DeviceInfo] = isy_data.devices
|
||||
entities: list[ISYLockEntity | ISYLockProgramEntity] = []
|
||||
for node in isy_data.nodes[Platform.LOCK]:
|
||||
entities.append(ISYLockEntity(node, devices.get(node.primary_node)))
|
||||
entities: list[ISYLockEntity | ISYLockProgramEntity] = [
|
||||
ISYLockEntity(node, devices.get(node.primary_node))
|
||||
for node in isy_data.nodes[Platform.LOCK]
|
||||
]
|
||||
|
||||
for name, status, actions in isy_data.programs[Platform.LOCK]:
|
||||
entities.append(ISYLockProgramEntity(name, status, actions))
|
||||
entities.extend(
|
||||
ISYLockProgramEntity(name, status, actions)
|
||||
for name, status, actions in isy_data.programs[Platform.LOCK]
|
||||
)
|
||||
|
||||
async_add_entities(entities)
|
||||
async_setup_lock_services(hass)
|
||||
|
@ -17,14 +17,13 @@ async def async_setup_entry(
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the JuiceNet switches."""
|
||||
entities = []
|
||||
juicenet_data = hass.data[DOMAIN][config_entry.entry_id]
|
||||
api = juicenet_data[JUICENET_API]
|
||||
coordinator = juicenet_data[JUICENET_COORDINATOR]
|
||||
|
||||
for device in api.devices:
|
||||
entities.append(JuiceNetChargeNowSwitch(device, coordinator))
|
||||
async_add_entities(entities)
|
||||
async_add_entities(
|
||||
JuiceNetChargeNowSwitch(device, coordinator) for device in api.devices
|
||||
)
|
||||
|
||||
|
||||
class JuiceNetChargeNowSwitch(JuiceNetDevice, SwitchEntity):
|
||||
|
@ -204,10 +204,10 @@ class KNXClimate(KnxEntity, ClimateEntity):
|
||||
"""Return the list of available operation/controller modes."""
|
||||
ha_controller_modes: list[HVACMode | None] = []
|
||||
if self._device.mode is not None:
|
||||
for knx_controller_mode in self._device.mode.controller_modes:
|
||||
ha_controller_modes.append(
|
||||
CONTROLLER_MODES.get(knx_controller_mode.value)
|
||||
)
|
||||
ha_controller_modes.extend(
|
||||
CONTROLLER_MODES.get(knx_controller_mode.value)
|
||||
for knx_controller_mode in self._device.mode.controller_modes
|
||||
)
|
||||
|
||||
if self._device.supports_on_off:
|
||||
if not ha_controller_modes:
|
||||
|
@ -597,17 +597,17 @@ class KNXCommonFlow(ABC, ConfigEntryBaseFlow):
|
||||
value=CONF_KNX_AUTOMATIC, label=CONF_KNX_AUTOMATIC.capitalize()
|
||||
)
|
||||
]
|
||||
for endpoint in self._tunnel_endpoints:
|
||||
tunnel_endpoint_options.append(
|
||||
selector.SelectOptionDict(
|
||||
value=str(endpoint.individual_address),
|
||||
label=(
|
||||
f"{endpoint.individual_address} "
|
||||
f"{'🔐 ' if endpoint.user_id else ''}"
|
||||
f"(Data Secure GAs: {len(endpoint.group_addresses)})"
|
||||
),
|
||||
)
|
||||
tunnel_endpoint_options.extend(
|
||||
selector.SelectOptionDict(
|
||||
value=str(endpoint.individual_address),
|
||||
label=(
|
||||
f"{endpoint.individual_address} "
|
||||
f"{'🔐 ' if endpoint.user_id else ''}"
|
||||
f"(Data Secure GAs: {len(endpoint.group_addresses)})"
|
||||
),
|
||||
)
|
||||
for endpoint in self._tunnel_endpoints
|
||||
)
|
||||
return self.async_show_form(
|
||||
step_id="knxkeys_tunnel_select",
|
||||
data_schema=vol.Schema(
|
||||
|
@ -28,21 +28,16 @@ async def async_get_service(
|
||||
if platform_config := hass.data[DATA_KNX_CONFIG].get(NotifySchema.PLATFORM):
|
||||
xknx: XKNX = hass.data[DOMAIN].xknx
|
||||
|
||||
notification_devices = []
|
||||
for device_config in platform_config:
|
||||
notification_devices.append(
|
||||
XknxNotification(
|
||||
xknx,
|
||||
name=device_config[CONF_NAME],
|
||||
group_address=device_config[KNX_ADDRESS],
|
||||
value_type=device_config[CONF_TYPE],
|
||||
)
|
||||
notification_devices = [
|
||||
XknxNotification(
|
||||
xknx,
|
||||
name=device_config[CONF_NAME],
|
||||
group_address=device_config[KNX_ADDRESS],
|
||||
value_type=device_config[CONF_TYPE],
|
||||
)
|
||||
return (
|
||||
KNXNotificationService(notification_devices)
|
||||
if notification_devices
|
||||
else None
|
||||
)
|
||||
for device_config in platform_config
|
||||
]
|
||||
return KNXNotificationService(notification_devices)
|
||||
|
||||
return None
|
||||
|
||||
|
@ -125,9 +125,7 @@ def _make_v2_resultset(*args):
|
||||
|
||||
def _make_v2_buckets_resultset():
|
||||
"""Create a mock V2 'buckets()' resultset."""
|
||||
records = []
|
||||
for name in [DEFAULT_BUCKET, "bucket2"]:
|
||||
records.append(Record({"name": name}))
|
||||
records = [Record({"name": name}) for name in [DEFAULT_BUCKET, "bucket2"]]
|
||||
|
||||
return [Table(records)]
|
||||
|
||||
|
@ -16,8 +16,7 @@ DEVICES = []
|
||||
|
||||
def add_entities(devices):
|
||||
"""Mock add devices."""
|
||||
for device in devices:
|
||||
DEVICES.append(device)
|
||||
DEVICES.extend(devices)
|
||||
|
||||
|
||||
def test_service_call(hass: HomeAssistant) -> None:
|
||||
|
@ -14,8 +14,7 @@ DEVICES = []
|
||||
|
||||
def add_entities(devices):
|
||||
"""Mock add devices."""
|
||||
for device in devices:
|
||||
DEVICES.append(device)
|
||||
DEVICES.extend(devices)
|
||||
|
||||
|
||||
@patch("homeassistant.components.kira.sensor.KiraReceiver.schedule_update_ha_state")
|
||||
|
Loading…
x
Reference in New Issue
Block a user