Add light platform to microBees and change docstring in sensor (#111093)

* Add light platform to microBees and change docstring in sensor

* update .coveragerc

* fixes review

* fixes review

* fixes async_add_entities
This commit is contained in:
Federico D'Amico 2024-02-24 20:07:04 +01:00 committed by GitHub
parent 9cebbf15f3
commit bf9c4197b9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 80 additions and 1 deletions

View file

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

View file

@ -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,
]

View file

@ -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}")

View file

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