4 from typing
import TYPE_CHECKING, Any
6 from aiohttp
import ClientError
7 from nice_go
import ApiError
15 from .
import NiceGOConfigEntry
18 KNOWN_UNSUPPORTED_DEVICE_TYPES,
19 SUPPORTED_DEVICE_TYPES,
20 UNSUPPORTED_DEVICE_WARNING,
22 from .entity
import NiceGOEntity
24 _LOGGER = logging.getLogger(__name__)
29 config_entry: NiceGOConfigEntry,
30 async_add_entities: AddEntitiesCallback,
32 """Set up Nice G.O. light."""
34 coordinator = config_entry.runtime_data
38 for device_id, device_data
in coordinator.data.items():
39 if device_data.type
in SUPPORTED_DEVICE_TYPES[Platform.LIGHT]:
41 elif device_data.type
not in KNOWN_UNSUPPORTED_DEVICE_TYPES[Platform.LIGHT]:
43 UNSUPPORTED_DEVICE_WARNING,
53 """Light for Nice G.O. devices."""
55 _attr_color_mode = ColorMode.ONOFF
56 _attr_supported_color_modes = {ColorMode.ONOFF}
57 _attr_translation_key =
"light"
61 """Return if the light is on or not."""
63 assert self.
datadatadata.light_status
is not None
64 return self.
datadatadata.light_status
67 """Turn on the light."""
70 await self.coordinator.api.light_on(self.
_device_id_device_id)
71 except (ApiError, ClientError)
as error:
73 translation_domain=DOMAIN,
74 translation_key=
"light_on_error",
75 translation_placeholders={
"exception":
str(error)},
79 """Turn off the light."""
82 await self.coordinator.api.light_off(self.
_device_id_device_id)
83 except (ApiError, ClientError)
as error:
85 translation_domain=DOMAIN,
86 translation_key=
"light_off_error",
87 translation_placeholders={
"exception":
str(error)},
None async_turn_on(self, **Any kwargs)
None async_turn_off(self, **Any kwargs)
None async_setup_entry(HomeAssistant hass, NiceGOConfigEntry config_entry, AddEntitiesCallback async_add_entities)