From efd1ed86ae02e36c70ba4629cb549784a23e6457 Mon Sep 17 00:00:00 2001 From: rlippmann <70883373+rlippmann@users.noreply.github.com> Date: Fri, 23 Feb 2024 17:35:56 -0500 Subject: [PATCH] Code improvements for microbees component (#111208) --- homeassistant/components/microbees/sensor.py | 14 ++++++-------- homeassistant/components/microbees/switch.py | 13 +++++++------ 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/homeassistant/components/microbees/sensor.py b/homeassistant/components/microbees/sensor.py index 4c73f6ef68c..b6fb38db569 100644 --- a/homeassistant/components/microbees/sensor.py +++ b/homeassistant/components/microbees/sensor.py @@ -66,15 +66,13 @@ async def async_setup_entry( ) -> None: """Config entry.""" coordinator = hass.data[DOMAIN][entry.entry_id].coordinator - sensors = [] - for bee_id, bee in coordinator.data.bees.items(): - for sensor in bee.sensors: - if (entity_description := SENSOR_TYPES.get(sensor.device_type)) is not None: - sensors.append( - MBSensor(coordinator, entity_description, bee_id, sensor.id) - ) - async_add_entities(sensors) + async_add_entities( + MBSensor(coordinator, desc, bee_id, sensor.id) + for bee_id, bee in coordinator.data.bees.items() + for sensor in bee.sensors + if (desc := SENSOR_TYPES.get(sensor.device_type)) is not None + ) class MBSensor(MicroBeesEntity, SensorEntity): diff --git a/homeassistant/components/microbees/switch.py b/homeassistant/components/microbees/switch.py index 33db881932e..4a52d95620b 100644 --- a/homeassistant/components/microbees/switch.py +++ b/homeassistant/components/microbees/switch.py @@ -12,6 +12,7 @@ from .coordinator import MicroBeesUpdateCoordinator from .entity import MicroBeesActuatorEntity SOCKET_TRANSLATIONS = {46: "socket_it", 38: "socket_eu"} +SWITCH_PRODUCT_IDS = {25, 26, 27, 35, 38, 46, 63, 64, 65, 86} async def async_setup_entry( @@ -19,13 +20,13 @@ async def async_setup_entry( ) -> None: """Config entry.""" coordinator = hass.data[DOMAIN][entry.entry_id].coordinator - switches = [] - for bee_id, bee in coordinator.data.bees.items(): - if bee.productID in (25, 26, 27, 35, 38, 46, 63, 64, 65, 86): - for switch in bee.actuators: - switches.append(MBSwitch(coordinator, bee_id, switch.id)) - async_add_entities(switches) + async_add_entities( + MBSwitch(coordinator, bee_id, switch.id) + for bee_id, bee in coordinator.data.bees.items() + if bee.productID in SWITCH_PRODUCT_IDS + for switch in bee.actuators + ) class MBSwitch(MicroBeesActuatorEntity, SwitchEntity):