Code improvements for microbees component (#111208)

This commit is contained in:
rlippmann 2024-02-23 17:35:56 -05:00 committed by GitHub
parent d9addc45f9
commit efd1ed86ae
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 13 additions and 14 deletions

View file

@ -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):

View file

@ -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):