1 """Support for Magic Home select."""
3 from __future__
import annotations
7 from flux_led.aio
import AIOWifiLedBulb
8 from flux_led.base_device
import DeviceType
9 from flux_led.const
import (
10 DEFAULT_WHITE_CHANNEL_TYPE,
14 from flux_led.protocol
import PowerRestoreState, RemoteConfig
16 from homeassistant
import config_entries
22 from .const
import CONF_WHITE_CHANNEL_TYPE, DOMAIN, FLUX_COLOR_MODE_RGBW
23 from .coordinator
import FluxLedUpdateCoordinator
24 from .entity
import FluxBaseEntity, FluxEntity
25 from .util
import _human_readable_option
27 NAME_TO_POWER_RESTORE_STATE = {
35 """Reload after making a change that will effect the operation of the device."""
36 await asyncio.sleep(STATE_CHANGE_LATENCY)
37 hass.async_create_task(hass.config_entries.async_reload(entry.entry_id))
43 async_add_entities: AddEntitiesCallback,
45 """Set up the Flux selects."""
46 coordinator: FluxLedUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
47 device = coordinator.device
50 | FluxOperatingModesSelect
53 | FluxRemoteConfigSelect
54 | FluxWhiteChannelSelect
56 entry.data.get(CONF_NAME, entry.title)
57 base_unique_id = entry.unique_id
or entry.entry_id
59 if device.device_type == DeviceType.Switch:
61 if device.operating_modes:
65 if device.wirings
and device.wiring
is not None:
69 if device.remote_config:
73 if FLUX_COLOR_MODE_RGBW
in device.color_modes:
80 """Representation of a flux config entity that only updates at start or change."""
82 _attr_entity_category = EntityCategory.CONFIG
86 """Representation of a flux config entity that updates."""
88 _attr_entity_category = EntityCategory.CONFIG
92 """Representation of a Flux power restore state option."""
94 _attr_translation_key =
"power_restored"
95 _attr_options =
list(NAME_TO_POWER_RESTORE_STATE)
99 device: AIOWifiLedBulb,
102 """Initialize the power state select."""
104 base_unique_id = entry.unique_id
or entry.entry_id
110 """Set the option from the current power state."""
111 restore_states = self._device.power_restore_states
112 assert restore_states
is not None
113 assert restore_states.channel1
is not None
117 """Change the power state."""
118 await self._device.async_set_power_restore(
119 channel1=NAME_TO_POWER_RESTORE_STATE[option]
126 """Representation of Flux ic type."""
128 _attr_translation_key =
"ic_type"
132 """Return the available ic types."""
133 assert self._device.ic_types
is not None
134 return self._device.ic_types
138 """Return the current ic type."""
139 return self._device.ic_type
142 """Change the ic type."""
143 await self._device.async_set_device_config(ic_type=option)
148 """Representation of Flux wirings."""
150 _attr_translation_key =
"wiring"
154 """Return the available wiring options based on the strip protocol."""
155 assert self._device.wirings
is not None
156 return self._device.wirings
160 """Return the current wiring."""
161 return self._device.wiring
164 """Change the wiring."""
165 await self._device.async_set_device_config(wiring=option)
169 """Representation of Flux operating modes."""
171 _attr_translation_key =
"operating_mode"
175 """Return the current operating mode."""
176 assert self._device.operating_modes
is not None
177 return self._device.operating_modes
181 """Return the current operating mode."""
182 return self._device.operating_mode
185 """Change the ic type."""
186 await self._device.async_set_device_config(operating_mode=option)
191 """Representation of Flux remote config type."""
193 _attr_translation_key =
"remote_config"
197 coordinator: FluxLedUpdateCoordinator,
201 """Initialize the remote config type select."""
202 super().
__init__(coordinator, base_unique_id, key)
203 assert self._device.remote_config
is not None
211 """Return the current remote config."""
212 assert self._device.remote_config
is not None
216 """Change the remote config setting."""
217 remote_config: RemoteConfig = self.
_name_to_state_name_to_state[option]
218 await self._device.async_config_remotes(remote_config)
222 """Representation of Flux white channel."""
224 _attr_translation_key =
"white_channel"
230 device: AIOWifiLedBulb,
233 """Initialize the white channel select."""
235 base_unique_id = entry.unique_id
or entry.entry_id
240 """Return the current white channel type."""
242 self.
entryentry.data.get(
243 CONF_WHITE_CHANNEL_TYPE, DEFAULT_WHITE_CHANNEL_TYPE.name
248 """Change the white channel type."""
249 self.
hasshass.config_entries.async_update_entry(
251 data={**self.
entryentry.data, CONF_WHITE_CHANNEL_TYPE: option.lower()},
None async_select_option(self, str option)
str|None current_option(self)
None async_select_option(self, str option)
str|None current_option(self)
None __init__(self, AIOWifiLedBulb device, config_entries.ConfigEntry entry)
None async_select_option(self, str option)
None _async_set_current_option_from_device(self)
None __init__(self, FluxLedUpdateCoordinator coordinator, str base_unique_id, str key)
str|None current_option(self)
None async_select_option(self, str option)
None async_select_option(self, str option)
None __init__(self, AIOWifiLedBulb device, config_entries.ConfigEntry entry)
str|None current_option(self)
None async_select_option(self, str option)
str|None current_option(self)
None async_write_ha_state(self)
None async_setup_entry(HomeAssistant hass, config_entries.ConfigEntry entry, AddEntitiesCallback async_add_entities)
None _async_delayed_reload(HomeAssistant hass, config_entries.ConfigEntry entry)
str _human_readable_option(str const_option)