1 """Support for the Opple light."""
3 from __future__
import annotations
8 from pyoppleio.OppleLightDevice
import OppleLightDevice
9 import voluptuous
as vol
14 PLATFORM_SCHEMA
as LIGHT_PLATFORM_SCHEMA,
24 color_temperature_kelvin_to_mired
as kelvin_to_mired,
25 color_temperature_mired_to_kelvin
as mired_to_kelvin,
28 _LOGGER = logging.getLogger(__name__)
30 DEFAULT_NAME =
"opple light"
32 PLATFORM_SCHEMA = LIGHT_PLATFORM_SCHEMA.extend(
34 vol.Required(CONF_HOST): cv.string,
35 vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
43 add_entities: AddEntitiesCallback,
44 discovery_info: DiscoveryInfoType |
None =
None,
46 """Set up the Opple light platform."""
47 name = config[CONF_NAME]
48 host = config[CONF_HOST]
53 _LOGGER.debug(
"Init light %s %s", host, entity.unique_id)
57 """Opple light device."""
59 _attr_color_mode = ColorMode.COLOR_TEMP
60 _attr_supported_color_modes = {ColorMode.COLOR_TEMP}
63 """Initialize an Opple light."""
65 self.
_device_device = OppleLightDevice(host)
74 """Return True if light is available."""
75 return self.
_device_device.is_online
79 """Return unique ID for light."""
84 """Return the display name of this light."""
85 return self.
_name_name
89 """Return true if light is on."""
94 """Return the brightness of the light."""
99 """Return the color temperature of this light."""
100 return kelvin_to_mired(self.
_color_temp_color_temp)
104 """Return minimum supported color temperature."""
109 """Return maximum supported color temperature."""
113 """Instruct the light to turn on."""
114 _LOGGER.debug(
"Turn on light %s %s", self.
_device_device.ip, kwargs)
116 self.
_device_device.power_on =
True
118 if ATTR_BRIGHTNESS
in kwargs
and self.
brightnessbrightnessbrightness != kwargs[ATTR_BRIGHTNESS]:
119 self.
_device_device.brightness = kwargs[ATTR_BRIGHTNESS]
121 if ATTR_COLOR_TEMP
in kwargs
and self.
color_tempcolor_tempcolor_temp != kwargs[ATTR_COLOR_TEMP]:
122 color_temp = mired_to_kelvin(kwargs[ATTR_COLOR_TEMP])
123 self.
_device_device.color_temperature = color_temp
126 """Instruct the light to turn off."""
127 self.
_device_device.power_on =
False
128 _LOGGER.debug(
"Turn off light %s", self.
_device_device.ip)
131 """Synchronize state with light."""
144 _LOGGER.debug(
"Light %s is offline", self.
_device_device.ip)
152 _LOGGER.debug(
"Update light %s success: power off", self.
_device_device.ip)
155 "Update light %s success: power on brightness %s color temperature %s",
int|None brightness(self)
int|None color_temp(self)
None turn_off(self, **Any kwargs)
def __init__(self, name, host)
None turn_on(self, **Any kwargs)
None add_entities(AsusWrtRouter router, AddEntitiesCallback async_add_entities, set[str] tracked)
None setup_platform(HomeAssistant hass, ConfigType config, AddEntitiesCallback add_entities, DiscoveryInfoType|None discovery_info=None)