1 """Support for Magic Home lights."""
3 from __future__
import annotations
5 from abc
import abstractmethod
8 from flux_led.aiodevice
import AIOWifiLedBulb
10 from homeassistant
import config_entries
29 from .const
import CONF_MINOR_VERSION, DOMAIN, SIGNAL_STATE_UPDATED
30 from .coordinator
import FluxLedUpdateCoordinator
36 version_num = device.version_num
37 if minor_version := entry.data.get(CONF_MINOR_VERSION):
38 sw_version = version_num +
int(hex(minor_version)[2:]) / 100
39 sw_version_str = f
"{sw_version:0.2f}"
41 sw_version_str =
str(device.version_num)
42 device_info: DeviceInfo = {
43 ATTR_IDENTIFIERS: {(DOMAIN, entry.entry_id)},
44 ATTR_MANUFACTURER:
"Zengge",
45 ATTR_MODEL: device.model,
46 ATTR_NAME: entry.data.get(CONF_NAME, entry.title),
47 ATTR_SW_VERSION: sw_version_str,
49 if hw_model := entry.data.get(CONF_MODEL):
50 device_info[ATTR_HW_VERSION] = hw_model
52 device_info[ATTR_CONNECTIONS] = {(dr.CONNECTION_NETWORK_MAC, entry.unique_id)}
57 """Representation of a Flux entity without a coordinator."""
59 _attr_has_entity_name =
True
60 _attr_should_poll =
False
64 device: AIOWifiLedBulb,
67 """Initialize the light."""
68 self._device: AIOWifiLedBulb = device
74 """Representation of a Flux entity with a coordinator."""
76 _attr_has_entity_name =
True
80 coordinator: FluxLedUpdateCoordinator,
84 """Initialize the light."""
86 self._device: AIOWifiLedBulb = coordinator.device
95 """Turn the device on if it needs to be turned on before a command."""
96 if self._device.requires_turn_on
and not self._device.is_on:
101 """Return the attributes."""
102 return {
"ip_address": self._device.ipaddr}
106 """Handle updated data from the coordinator."""
107 if self.coordinator.last_update_success != self.
_responding_responding:
108 self.async_write_ha_state()
109 self.
_responding_responding = self.coordinator.last_update_success
112 """Handle entity which will be added."""
113 self.async_on_remove(
116 SIGNAL_STATE_UPDATED.format(self._device.ipaddr),
117 self.async_write_ha_state,
124 """Representation of a Flux entity that supports on/off."""
128 """Return true if device is on."""
129 return self._device.is_on
132 """Turn the specified device on."""
134 self.async_write_ha_state()
139 """Turn the specified device on."""
142 """Turn the specified device off."""
144 self.async_write_ha_state()
None __init__(self, AIOWifiLedBulb device, config_entries.ConfigEntry entry)
None _handle_coordinator_update(self)
None _async_ensure_device_on(self)
None __init__(self, FluxLedUpdateCoordinator coordinator, str base_unique_id, str|None key)
None async_added_to_hass(self)
dict[str, str] extra_state_attributes(self)
None async_turn_off(self, **Any kwargs)
None async_turn_on(self, **Any kwargs)
None _async_turn_on(self, **Any kwargs)
None async_request_refresh(self)
None async_turn_on(self, **Any kwargs)
DeviceInfo _async_device_info(AIOWifiLedBulb device, config_entries.ConfigEntry entry)
Callable[[], None] async_dispatcher_connect(HomeAssistant hass, str signal, Callable[..., Any] target)