Files
kobrax-lan-hass-component/custom_components/kobrax_lan/light.py
Gangoke 279995ba13 Refactor Kobra X integration into kobrax_lan component
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.
2026-05-16 23:32:07 -10:00

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")])