1 """Support for Magic Home switches."""
3 from __future__
import annotations
7 from flux_led
import DeviceType
8 from flux_led.aio
import AIOWifiLedBulb
9 from flux_led.const
import MODE_MUSIC
11 from homeassistant
import config_entries
19 CONF_REMOTE_ACCESS_ENABLED,
20 CONF_REMOTE_ACCESS_HOST,
21 CONF_REMOTE_ACCESS_PORT,
24 from .coordinator
import FluxLedUpdateCoordinator
25 from .discovery
import async_clear_discovery_cache
26 from .entity
import FluxBaseEntity, FluxEntity, FluxOnOffEntity
32 async_add_entities: AddEntitiesCallback,
34 """Set up the Flux lights."""
35 coordinator: FluxLedUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
36 entities: list[FluxSwitch | FluxRemoteAccessSwitch | FluxMusicSwitch] = []
37 base_unique_id = entry.unique_id
or entry.entry_id
39 if coordinator.device.device_type == DeviceType.Switch:
40 entities.append(
FluxSwitch(coordinator, base_unique_id,
None))
42 if entry.data.get(CONF_REMOTE_ACCESS_HOST):
45 if coordinator.device.microphone:
52 FluxOnOffEntity, CoordinatorEntity[FluxLedUpdateCoordinator], SwitchEntity
54 """Representation of a Flux switch."""
59 """Turn the device on."""
65 """Representation of a Flux remote access switch."""
67 _attr_entity_category = EntityCategory.CONFIG
68 _attr_translation_key =
"remote_access"
72 device: AIOWifiLedBulb,
75 """Initialize the light."""
77 base_unique_id = entry.unique_id
or entry.entry_id
81 """Turn the remote access on."""
82 await self._device.async_enable_remote_access(
83 self.
entryentry.data[CONF_REMOTE_ACCESS_HOST],
84 self.
entryentry.data[CONF_REMOTE_ACCESS_PORT],
89 """Update the entry with the new state on success."""
91 self.
hasshass.config_entries.async_update_entry(
93 data={**self.
entryentry.data, CONF_REMOTE_ACCESS_ENABLED: new_state},
98 """Turn the remote access off."""
99 await self._device.async_disable_remote_access()
104 """Return true if remote access is enabled."""
105 return bool(self.
entryentry.data[CONF_REMOTE_ACCESS_ENABLED])
109 """Representation of a Flux music switch."""
111 _attr_translation_key =
"music"
114 """Turn the microphone on."""
116 await self._device.async_set_music_mode()
121 """Turn the microphone off."""
122 await self._device.async_set_levels(*self._device.rgb, brightness=255)
128 """Return true if microphone is is on."""
129 return self._device.is_on
and self._device.effect == MODE_MUSIC
None _async_ensure_device_on(self)
None async_turn_on(self, **Any kwargs)
None async_turn_off(self, **Any kwargs)
None async_turn_on(self, **Any kwargs)
None __init__(self, AIOWifiLedBulb device, config_entries.ConfigEntry entry)
None async_turn_off(self, **Any kwargs)
None async_turn_on(self, **Any kwargs)
None _async_update_entry(self, bool new_state)
None _async_turn_on(self, **Any kwargs)
None async_write_ha_state(self)
None async_request_refresh(self)
None async_clear_discovery_cache(HomeAssistant hass, str host)
None async_setup_entry(HomeAssistant hass, config_entries.ConfigEntry entry, AddEntitiesCallback async_add_entities)