Skip to content

Commit

Permalink
music mode for lightstrips (#356)
Browse files Browse the repository at this point in the history
  • Loading branch information
brg468 authored Mar 24, 2022
1 parent 297d61b commit 7a592b5
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions custom_components/wyzeapi/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@
from homeassistant.components.light import (
ATTR_BRIGHTNESS,
ATTR_COLOR_TEMP,
ATTR_EFFECT,
ATTR_HS_COLOR,
SUPPORT_BRIGHTNESS,
SUPPORT_COLOR_TEMP,
SUPPORT_COLOR,
SUPPORT_EFFECT,
LightEntity
)
from homeassistant.config_entries import ConfigEntry
Expand All @@ -31,6 +33,7 @@
_LOGGER = logging.getLogger(__name__)
ATTRIBUTION = "Data provided by Wyze"
SCAN_INTERVAL = timedelta(seconds=30)
EFFECT_MUSIC_MODE = "music mode"


@token_exception_handler
Expand Down Expand Up @@ -131,6 +134,12 @@ async def async_turn_on(self, **kwargs: Any) -> None:
options.append(create_pid_pair(PropertyIDs.COLOR, str(color)))

self._bulb.color = color
if (
kwargs.get(ATTR_EFFECT) == EFFECT_MUSIC_MODE
and self._device_type is DeviceTypes.LIGHTSTRIP
):
_LOGGER.debug("Setting Music Mode")
options.append(create_pid_pair(PropertyIDs.COLOR_MODE, str(3)))

_LOGGER.debug("Turning on light")
self._local_control = self._config_entry.options.get(BULB_LOCAL_CONTROL)
Expand Down Expand Up @@ -197,6 +206,13 @@ def extra_state_attributes(self):
and not self._bulb.cloud_fallback
)

if self._bulb.color_mode == '1':
dev_info["mode"] = "Color"
elif self._bulb.color_mode == '2':
dev_info["mode"] = "White"
elif self._bulb.color_mode == '3':
dev_info["mode"] = "Music"

return dev_info

@property
Expand All @@ -223,18 +239,21 @@ def max_mireds(self) -> int:
def min_mireds(self) -> int:
return color_util.color_temperature_kelvin_to_mired(6500) + 1

@property
def effect_list(self):
return [EFFECT_MUSIC_MODE]

@property
def is_on(self):
"""Return true if light is on."""
return self._bulb.on

@property
def supported_features(self):
if (
self._bulb.type is DeviceTypes.MESH_LIGHT
or self._bulb.type is DeviceTypes.LIGHTSTRIP
):
if self._bulb.type is DeviceTypes.MESH_LIGHT:
return SUPPORT_BRIGHTNESS | SUPPORT_COLOR_TEMP | SUPPORT_COLOR
elif self._bulb.type is DeviceTypes.LIGHTSTRIP:
return SUPPORT_BRIGHTNESS | SUPPORT_COLOR_TEMP | SUPPORT_COLOR | SUPPORT_EFFECT
return SUPPORT_BRIGHTNESS | SUPPORT_COLOR_TEMP

@token_exception_handler
Expand Down

0 comments on commit 7a592b5

Please sign in to comment.