diff --git a/.coveragerc b/.coveragerc index fd8dee9dc694..c882215e294c 100644 --- a/.coveragerc +++ b/.coveragerc @@ -775,6 +775,7 @@ omit = homeassistant/components/microbees/const.py homeassistant/components/microbees/coordinator.py homeassistant/components/microbees/entity.py + homeassistant/components/microbees/light.py homeassistant/components/microbees/sensor.py homeassistant/components/microbees/switch.py homeassistant/components/microsoft/tts.py diff --git a/homeassistant/components/microbees/const.py b/homeassistant/components/microbees/const.py index 025fa09cd14c..ab5a883034de 100644 --- a/homeassistant/components/microbees/const.py +++ b/homeassistant/components/microbees/const.py @@ -5,6 +5,7 @@ DOMAIN = "microbees" OAUTH2_AUTHORIZE = "https://dev.microbees.com/oauth/authorize" OAUTH2_TOKEN = "https://dev.microbees.com/oauth/token" PLATFORMS = [ + Platform.LIGHT, Platform.SENSOR, Platform.SWITCH, ] diff --git a/homeassistant/components/microbees/light.py b/homeassistant/components/microbees/light.py new file mode 100644 index 000000000000..7616cba41b0e --- /dev/null +++ b/homeassistant/components/microbees/light.py @@ -0,0 +1,77 @@ +"""Light integration microBees.""" +from typing import Any + +from homeassistant.components.light import ATTR_RGBW_COLOR, ColorMode, LightEntity +from homeassistant.config_entries import ConfigEntry +from homeassistant.core import HomeAssistant +from homeassistant.exceptions import HomeAssistantError +from homeassistant.helpers.entity_platform import AddEntitiesCallback + +from .const import DOMAIN +from .coordinator import MicroBeesUpdateCoordinator +from .entity import MicroBeesActuatorEntity + + +async def async_setup_entry( + hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback +) -> None: + """Config entry.""" + coordinator: MicroBeesUpdateCoordinator = hass.data[DOMAIN][ + entry.entry_id + ].coordinator + async_add_entities( + MBLight(coordinator, bee_id, light.id) + for bee_id, bee in coordinator.data.bees.items() + if bee.productID in (31, 79) + for light in bee.actuators + ) + + +class MBLight(MicroBeesActuatorEntity, LightEntity): + """Representation of a microBees light.""" + + _attr_supported_color_modes = {ColorMode.RGBW} + + def __init__( + self, + coordinator: MicroBeesUpdateCoordinator, + bee_id: int, + actuator_id: int, + ) -> None: + """Initialize the microBees light.""" + super().__init__(coordinator, bee_id, actuator_id) + self._attr_rgbw_color = self.actuator.configuration.color + + @property + def name(self) -> str: + """Name of the cover.""" + return self.actuator.name + + @property + def is_on(self) -> bool: + """Status of the light.""" + return self.actuator.value + + async def async_turn_on(self, **kwargs: Any) -> None: + """Turn on the light.""" + if ATTR_RGBW_COLOR in kwargs: + self._attr_rgbw_color = kwargs[ATTR_RGBW_COLOR] + sendCommand = await self.coordinator.microbees.sendCommand( + self.actuator_id, 1, color=self._attr_rgbw_color + ) + if sendCommand: + self.actuator.value = True + self.async_write_ha_state() + else: + raise HomeAssistantError(f"Failed to turn on {self.name}") + + async def async_turn_off(self, **kwargs: Any) -> None: + """Turn off the light.""" + sendCommand = await self.coordinator.microbees.sendCommand( + self.actuator_id, 0, color=self._attr_rgbw_color + ) + if sendCommand: + self.actuator.value = False + self.async_write_ha_state() + else: + raise HomeAssistantError(f"Failed to turn off {self.name}") diff --git a/homeassistant/components/microbees/sensor.py b/homeassistant/components/microbees/sensor.py index b6fb38db5697..56db4c00ee36 100644 --- a/homeassistant/components/microbees/sensor.py +++ b/homeassistant/components/microbees/sensor.py @@ -98,7 +98,7 @@ class MBSensor(MicroBeesEntity, SensorEntity): @property def native_value(self) -> float | None: - """Return the value reported by the sensor, or None if the relevant sensor can't produce a current measurement.""" + """Return the state of the sensor.""" return self.sensor.value @property