1 """Govee light local."""
3 from __future__
import annotations
8 from govee_local_api
import GoveeDevice, GoveeLightCapability
12 ATTR_COLOR_TEMP_KELVIN,
16 filter_supported_color_modes,
23 from .const
import DOMAIN, MANUFACTURER
24 from .coordinator
import GoveeLocalApiCoordinator, GoveeLocalConfigEntry
26 _LOGGER = logging.getLogger(__name__)
31 config_entry: GoveeLocalConfigEntry,
32 async_add_entities: AddEntitiesCallback,
34 """Govee light setup."""
36 coordinator = config_entry.runtime_data
38 def discovery_callback(device: GoveeDevice, is_new: bool) -> bool:
44 GoveeLight(coordinator, device)
for device
in coordinator.devices
47 await coordinator.set_discovery_callback(discovery_callback)
53 _attr_has_entity_name =
True
55 _attr_supported_color_modes: set[ColorMode]
56 _fixed_color_mode: ColorMode |
None =
None
60 coordinator: GoveeLocalApiCoordinator,
63 """Govee Light constructor."""
71 capabilities = device.capabilities
72 color_modes = {ColorMode.ONOFF}
74 if GoveeLightCapability.COLOR_RGB
in capabilities:
75 color_modes.add(ColorMode.RGB)
76 if GoveeLightCapability.COLOR_KELVIN_TEMPERATURE
in capabilities:
77 color_modes.add(ColorMode.COLOR_TEMP)
80 if GoveeLightCapability.BRIGHTNESS
in capabilities:
81 color_modes.add(ColorMode.BRIGHTNESS)
91 (DOMAIN, device.fingerprint)
94 manufacturer=MANUFACTURER,
96 serial_number=device.fingerprint,
101 """Return true if device is on (brightness above 0)."""
106 """Return the brightness of this light between 0..255."""
107 return int((self.
_device_device.brightness / 100.0) * 255.0)
111 """Return the color temperature in Kelvin."""
112 return self.
_device_device.temperature_color
116 """Return the rgb color."""
117 return self.
_device_device.rgb_color
121 """Return the color mode."""
129 self.
_device_device.temperature_color
is not None
130 and self.
_device_device.temperature_color > 0
132 return ColorMode.COLOR_TEMP
136 """Turn the device on."""
140 if ATTR_BRIGHTNESS
in kwargs:
141 brightness: int =
int((
float(kwargs[ATTR_BRIGHTNESS]) / 255.0) * 100.0)
144 if ATTR_RGB_COLOR
in kwargs:
146 red, green, blue = kwargs[ATTR_RGB_COLOR]
148 elif ATTR_COLOR_TEMP_KELVIN
in kwargs:
150 temperature: float = kwargs[ATTR_COLOR_TEMP_KELVIN]
155 """Turn the device off."""
None set_brightness(self, GoveeDevice device, int brightness)
None set_temperature(self, GoveeDevice device, int temperature)
None turn_off(self, GoveeDevice device)
None set_rgb_color(self, GoveeDevice device, int red, int green, int blue)
None turn_on(self, GoveeDevice device)
tuple[int, int, int]|None rgb_color(self)
None async_turn_on(self, **Any kwargs)
None _update_callback(self, GoveeDevice device)
_attr_max_color_temp_kelvin
int|None color_temp_kelvin(self)
_attr_min_color_temp_kelvin
_attr_supported_color_modes
None async_turn_off(self, **Any kwargs)
None __init__(self, GoveeLocalApiCoordinator coordinator, GoveeDevice device)
ColorMode|str|None color_mode(self)
None async_write_ha_state(self)
None async_setup_entry(HomeAssistant hass, GoveeLocalConfigEntry config_entry, AddEntitiesCallback async_add_entities)
set[ColorMode] filter_supported_color_modes(Iterable[ColorMode] color_modes)