1 """Platform for light integration."""
5 from smarttub
import SpaLight
21 DEFAULT_LIGHT_BRIGHTNESS,
26 from .entity
import SmartTubEntity
27 from .helpers
import get_spa_name
31 hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
33 """Set up entities for any lights in the tub."""
35 controller = hass.data[DOMAIN][entry.entry_id][SMARTTUB_CONTROLLER]
39 for spa
in controller.spas
40 for light
in controller.coordinator.data[spa.id][ATTR_LIGHTS].values()
47 """A light on a spa."""
49 _attr_color_mode = ColorMode.BRIGHTNESS
50 _attr_supported_color_modes = {ColorMode.BRIGHTNESS}
51 _attr_supported_features = LightEntityFeature.EFFECT
54 """Initialize the entity."""
55 super().
__init__(coordinator, light.spa,
"light")
63 """Return the underlying SpaLight object for this entity."""
64 return self.coordinator.data[self.
spaspa.id][ATTR_LIGHTS][self.
light_zonelight_zone]
68 """Return the brightness of this light between 0..255."""
75 if intensity
in (0, 1):
77 return round(intensity * 255 / 100)
81 return round(brightness * 100 / 255)
85 """Return true if the light is on."""
86 return self.
lightlight.mode != SpaLight.LightMode.OFF
90 """Return the current effect."""
91 mode = self.
lightlight.mode.name.lower()
98 """Return the list of supported effects."""
102 if effect
is not None
107 if light_mode == SpaLight.LightMode.OFF:
109 if light_mode == SpaLight.LightMode.HIGH_SPEED_COLOR_WHEEL:
110 return EFFECT_COLORLOOP
112 return light_mode.name.lower()
116 if effect == EFFECT_COLORLOOP:
117 return SpaLight.LightMode.HIGH_SPEED_COLOR_WHEEL
119 return SpaLight.LightMode[effect.upper()]
122 """Turn the light on."""
124 mode = self.
_effect_to_light_mode_effect_to_light_mode(kwargs.get(ATTR_EFFECT, DEFAULT_LIGHT_EFFECT))
126 kwargs.get(ATTR_BRIGHTNESS, DEFAULT_LIGHT_BRIGHTNESS)
129 await self.
lightlight.set_mode(mode, intensity)
130 await self.coordinator.async_request_refresh()
133 """Turn the light off."""
134 await self.
lightlight.set_mode(SpaLight.LightMode.OFF, 0)
135 await self.coordinator.async_request_refresh()
list[str]|None effect_list(self)
def _smarttub_to_hass_brightness(intensity)
def _light_mode_to_effect(SpaLight.LightMode light_mode)
None async_turn_off(self, **Any kwargs)
def _effect_to_light_mode(effect)
def __init__(self, coordinator, light)
def _hass_to_smarttub_brightness(brightness)
None async_turn_on(self, **Any kwargs)
str get_spa_name(smarttub.Spa spa)
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)