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:
parent
9cebbf15f3
commit
bf9c4197b9
4 changed files with 80 additions and 1 deletions
|
@ -775,6 +775,7 @@ omit =
|
||||||
homeassistant/components/microbees/const.py
|
homeassistant/components/microbees/const.py
|
||||||
homeassistant/components/microbees/coordinator.py
|
homeassistant/components/microbees/coordinator.py
|
||||||
homeassistant/components/microbees/entity.py
|
homeassistant/components/microbees/entity.py
|
||||||
|
homeassistant/components/microbees/light.py
|
||||||
homeassistant/components/microbees/sensor.py
|
homeassistant/components/microbees/sensor.py
|
||||||
homeassistant/components/microbees/switch.py
|
homeassistant/components/microbees/switch.py
|
||||||
homeassistant/components/microsoft/tts.py
|
homeassistant/components/microsoft/tts.py
|
||||||
|
|
|
@ -5,6 +5,7 @@ DOMAIN = "microbees"
|
||||||
OAUTH2_AUTHORIZE = "https://dev.microbees.com/oauth/authorize"
|
OAUTH2_AUTHORIZE = "https://dev.microbees.com/oauth/authorize"
|
||||||
OAUTH2_TOKEN = "https://dev.microbees.com/oauth/token"
|
OAUTH2_TOKEN = "https://dev.microbees.com/oauth/token"
|
||||||
PLATFORMS = [
|
PLATFORMS = [
|
||||||
|
Platform.LIGHT,
|
||||||
Platform.SENSOR,
|
Platform.SENSOR,
|
||||||
Platform.SWITCH,
|
Platform.SWITCH,
|
||||||
]
|
]
|
||||||
|
|
77
homeassistant/components/microbees/light.py
Normal file
77
homeassistant/components/microbees/light.py
Normal 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}")
|
|
@ -98,7 +98,7 @@ class MBSensor(MicroBeesEntity, SensorEntity):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def native_value(self) -> float | None:
|
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
|
return self.sensor.value
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|
Loading…
Add table
Reference in a new issue