1 """Support for myStrom Wifi bulbs."""
3 from __future__
import annotations
8 from pymystrom.exceptions
import MyStromConnectionError
23 from .const
import DOMAIN, MANUFACTURER
25 _LOGGER = logging.getLogger(__name__)
27 DEFAULT_NAME =
"myStrom bulb"
29 EFFECT_RAINBOW =
"rainbow"
30 EFFECT_SUNRISE =
"sunrise"
34 hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
36 """Set up the myStrom entities."""
37 info = hass.data[DOMAIN][entry.entry_id].info
38 device = hass.data[DOMAIN][entry.entry_id].device
43 """Representation of the myStrom WiFi bulb."""
45 _attr_has_entity_name =
True
47 _attr_color_mode = ColorMode.HS
48 _attr_supported_color_modes = {ColorMode.HS}
49 _attr_supported_features = LightEntityFeature.EFFECT | LightEntityFeature.FLASH
50 _attr_effect_list = [EFFECT_RAINBOW, EFFECT_SUNRISE]
53 """Initialize the light."""
59 identifiers={(DOMAIN, mac)},
61 manufacturer=MANUFACTURER,
62 sw_version=self.
_bulb_bulb.firmware,
66 """Turn on the light."""
67 brightness = kwargs.get(ATTR_BRIGHTNESS, 255)
68 effect = kwargs.get(ATTR_EFFECT)
70 if ATTR_HS_COLOR
in kwargs:
71 color_h, color_s = kwargs[ATTR_HS_COLOR]
72 elif ATTR_BRIGHTNESS
in kwargs:
74 if self.
hs_colorhs_color
is not None:
75 color_h, color_s = self.
hs_colorhs_color
77 color_h, color_s = 0, 0
79 color_h, color_s = 0, 0
82 if not self.
is_onis_on:
83 await self.
_bulb_bulb.set_on()
84 if brightness
is not None:
85 await self.
_bulb_bulb.set_color_hsv(
86 int(color_h),
int(color_s), round(brightness * 100 / 255)
88 if effect == EFFECT_SUNRISE:
89 await self.
_bulb_bulb.set_sunrise(30)
90 if effect == EFFECT_RAINBOW:
91 await self.
_bulb_bulb.set_rainbow(30)
92 except MyStromConnectionError:
93 _LOGGER.warning(
"No route to myStrom bulb")
96 """Turn off the bulb."""
98 await self.
_bulb_bulb.set_off()
99 except MyStromConnectionError:
100 _LOGGER.warning(
"The myStrom bulb not online")
103 """Fetch new state data for this light."""
108 colors = self.
_bulb_bulb.color
110 color_h, color_s, color_v = colors.split(
";")
112 color_s, color_v = colors.split(
";")
119 except MyStromConnectionError:
120 _LOGGER.warning(
"No route to myStrom bulb")
tuple[float, float]|None hs_color(self)
def __init__(self, bulb, name, mac)
None async_turn_on(self, **Any kwargs)
None async_turn_off(self, **Any kwargs)
str|float get_state(dict[str, float] data, str key)
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)