mirror of
https://github.com/gangoke/kobrax-lan-hass-component.git
synced 2026-06-09 20:52:13 +02:00
All entites working - Moved all existing functionality from custom_components/kobrax to custom_components/kobrax_lan. - Updated manifest, const, and configuration flow to reflect the new component structure. - Reimplemented API client, coordinator, entity, and platform files under the new component. - Added support for image entities and binary sensors. - Ensured compatibility with Home Assistant's latest standards and practices.
39 lines
1.3 KiB
Python
39 lines
1.3 KiB
Python
from __future__ import annotations
|
|
|
|
from homeassistant.components.light import ColorMode, LightEntity
|
|
from homeassistant.exceptions import ServiceValidationError
|
|
|
|
from .api import KobraXApiError
|
|
from .const import DOMAIN
|
|
from .entity import KobraXEntity
|
|
|
|
|
|
class KobraXLight(KobraXEntity, LightEntity):
|
|
_attr_color_mode = ColorMode.ONOFF
|
|
_attr_supported_color_modes = {ColorMode.ONOFF}
|
|
|
|
@property
|
|
def is_on(self) -> bool:
|
|
return bool(self.state_data.get("light_on", False))
|
|
|
|
async def async_turn_on(self, **kwargs) -> None:
|
|
api = self.hass.data[DOMAIN][self._entry.entry_id]["api"]
|
|
try:
|
|
await api.async_set_light(True)
|
|
await self.coordinator.async_request_refresh()
|
|
except KobraXApiError as err:
|
|
raise ServiceValidationError(str(err)) from err
|
|
|
|
async def async_turn_off(self, **kwargs) -> None:
|
|
api = self.hass.data[DOMAIN][self._entry.entry_id]["api"]
|
|
try:
|
|
await api.async_set_light(False)
|
|
await self.coordinator.async_request_refresh()
|
|
except KobraXApiError as err:
|
|
raise ServiceValidationError(str(err)) from err
|
|
|
|
|
|
async def async_setup_entry(hass, entry, async_add_entities):
|
|
coordinator = hass.data[DOMAIN][entry.entry_id]["coordinator"]
|
|
async_add_entities([KobraXLight(coordinator, entry, "light", "Light")])
|