Fix Yeelight Music Mode Rate Limits (#64891)

This commit is contained in:
Alex Yao 2022-02-06 16:34:27 -05:00 committed by GitHub
parent c6aa526469
commit 88309a26b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 25 additions and 22 deletions

View File

@ -1090,8 +1090,8 @@ homeassistant/components/yamaha_musiccast/* @vigonotion @micha91
tests/components/yamaha_musiccast/* @vigonotion @micha91 tests/components/yamaha_musiccast/* @vigonotion @micha91
homeassistant/components/yandex_transport/* @rishatik92 @devbis homeassistant/components/yandex_transport/* @rishatik92 @devbis
tests/components/yandex_transport/* @rishatik92 @devbis tests/components/yandex_transport/* @rishatik92 @devbis
homeassistant/components/yeelight/* @zewelor @shenxn @starkillerOG homeassistant/components/yeelight/* @zewelor @shenxn @starkillerOG @alexyao2015
tests/components/yeelight/* @zewelor @shenxn @starkillerOG tests/components/yeelight/* @zewelor @shenxn @starkillerOG @alexyao2015
homeassistant/components/yeelightsunflower/* @lindsaymarkward homeassistant/components/yeelightsunflower/* @lindsaymarkward
homeassistant/components/yi/* @bachya homeassistant/components/yi/* @bachya
homeassistant/components/youless/* @gjong homeassistant/components/youless/* @gjong

View File

@ -7,7 +7,8 @@ import math
import voluptuous as vol import voluptuous as vol
import yeelight import yeelight
from yeelight import Bulb, Flow, RGBTransition, SleepTransition, flows from yeelight import Flow, RGBTransition, SleepTransition, flows
from yeelight.aio import AsyncBulb
from yeelight.enums import BulbType, LightType, PowerMode, SceneClass from yeelight.enums import BulbType, LightType, PowerMode, SceneClass
from yeelight.main import BulbException from yeelight.main import BulbException
@ -549,7 +550,7 @@ class YeelightGenericLight(YeelightEntity, LightEntity):
return self._effect if self.device.is_color_flow_enabled else None return self._effect if self.device.is_color_flow_enabled else None
@property @property
def _bulb(self) -> Bulb: def _bulb(self) -> AsyncBulb:
return self.device.bulb return self.device.bulb
@property @property
@ -608,8 +609,10 @@ class YeelightGenericLight(YeelightEntity, LightEntity):
async def _async_set_music_mode(self, music_mode) -> None: async def _async_set_music_mode(self, music_mode) -> None:
"""Set the music mode on or off wrapped with _async_cmd.""" """Set the music mode on or off wrapped with _async_cmd."""
bulb = self._bulb bulb = self._bulb
method = bulb.stop_music if not music_mode else bulb.start_music if music_mode:
await self.hass.async_add_executor_job(method) await bulb.async_start_music()
else:
await bulb.async_stop_music()
@_async_cmd @_async_cmd
async def async_set_brightness(self, brightness, duration) -> None: async def async_set_brightness(self, brightness, duration) -> None:

View File

@ -2,8 +2,8 @@
"domain": "yeelight", "domain": "yeelight",
"name": "Yeelight", "name": "Yeelight",
"documentation": "https://www.home-assistant.io/integrations/yeelight", "documentation": "https://www.home-assistant.io/integrations/yeelight",
"requirements": ["yeelight==0.7.8", "async-upnp-client==0.23.4"], "requirements": ["yeelight==0.7.9", "async-upnp-client==0.23.4"],
"codeowners": ["@zewelor", "@shenxn", "@starkillerOG"], "codeowners": ["@zewelor", "@shenxn", "@starkillerOG", "@alexyao2015"],
"config_flow": true, "config_flow": true,
"dependencies": ["network"], "dependencies": ["network"],
"quality_scale": "platinum", "quality_scale": "platinum",

View File

@ -2516,7 +2516,7 @@ yalesmartalarmclient==0.3.7
yalexs==1.1.20 yalexs==1.1.20
# homeassistant.components.yeelight # homeassistant.components.yeelight
yeelight==0.7.8 yeelight==0.7.9
# homeassistant.components.yeelightsunflower # homeassistant.components.yeelightsunflower
yeelightsunflower==0.0.10 yeelightsunflower==0.0.10

View File

@ -1550,7 +1550,7 @@ yalesmartalarmclient==0.3.7
yalexs==1.1.20 yalexs==1.1.20
# homeassistant.components.yeelight # homeassistant.components.yeelight
yeelight==0.7.8 yeelight==0.7.9
# homeassistant.components.youless # homeassistant.components.youless
youless-api==0.16 youless-api==0.16

View File

@ -153,7 +153,7 @@ def _mocked_bulb(cannot_connect=False):
bulb.async_set_power_mode = AsyncMock() bulb.async_set_power_mode = AsyncMock()
bulb.async_set_scene = AsyncMock() bulb.async_set_scene = AsyncMock()
bulb.async_set_default = AsyncMock() bulb.async_set_default = AsyncMock()
bulb.start_music = MagicMock() bulb.async_start_music = AsyncMock()
return bulb return bulb

View File

@ -219,8 +219,8 @@ async def test_services(hass: HomeAssistant, caplog):
power_mode=PowerMode.NORMAL, power_mode=PowerMode.NORMAL,
) )
mocked_bulb.async_turn_on.reset_mock() mocked_bulb.async_turn_on.reset_mock()
mocked_bulb.start_music.assert_called_once() mocked_bulb.async_start_music.assert_called_once()
mocked_bulb.start_music.reset_mock() mocked_bulb.async_start_music.reset_mock()
mocked_bulb.async_set_brightness.assert_called_once_with( mocked_bulb.async_set_brightness.assert_called_once_with(
brightness / 255 * 100, duration=transition * 1000, light_type=LightType.Main brightness / 255 * 100, duration=transition * 1000, light_type=LightType.Main
) )
@ -261,8 +261,8 @@ async def test_services(hass: HomeAssistant, caplog):
power_mode=PowerMode.NORMAL, power_mode=PowerMode.NORMAL,
) )
mocked_bulb.async_turn_on.reset_mock() mocked_bulb.async_turn_on.reset_mock()
mocked_bulb.start_music.assert_called_once() mocked_bulb.async_start_music.assert_called_once()
mocked_bulb.start_music.reset_mock() mocked_bulb.async_start_music.reset_mock()
mocked_bulb.async_set_brightness.assert_called_once_with( mocked_bulb.async_set_brightness.assert_called_once_with(
brightness / 255 * 100, duration=transition * 1000, light_type=LightType.Main brightness / 255 * 100, duration=transition * 1000, light_type=LightType.Main
) )
@ -304,7 +304,7 @@ async def test_services(hass: HomeAssistant, caplog):
power_mode=PowerMode.NORMAL, power_mode=PowerMode.NORMAL,
) )
mocked_bulb.async_turn_on.reset_mock() mocked_bulb.async_turn_on.reset_mock()
mocked_bulb.start_music.assert_called_once() mocked_bulb.async_start_music.assert_called_once()
mocked_bulb.async_set_brightness.assert_called_once_with( mocked_bulb.async_set_brightness.assert_called_once_with(
brightness / 255 * 100, duration=transition * 1000, light_type=LightType.Main brightness / 255 * 100, duration=transition * 1000, light_type=LightType.Main
) )
@ -322,7 +322,7 @@ async def test_services(hass: HomeAssistant, caplog):
brightness = 100 brightness = 100
color_temp = 200 color_temp = 200
transition = 1 transition = 1
mocked_bulb.start_music.reset_mock() mocked_bulb.async_start_music.reset_mock()
mocked_bulb.async_set_brightness.reset_mock() mocked_bulb.async_set_brightness.reset_mock()
mocked_bulb.async_set_color_temp.reset_mock() mocked_bulb.async_set_color_temp.reset_mock()
mocked_bulb.async_start_flow.reset_mock() mocked_bulb.async_start_flow.reset_mock()
@ -348,7 +348,7 @@ async def test_services(hass: HomeAssistant, caplog):
power_mode=PowerMode.NORMAL, power_mode=PowerMode.NORMAL,
) )
mocked_bulb.async_turn_on.reset_mock() mocked_bulb.async_turn_on.reset_mock()
mocked_bulb.start_music.assert_called_once() mocked_bulb.async_start_music.assert_called_once()
mocked_bulb.async_set_brightness.assert_called_once_with( mocked_bulb.async_set_brightness.assert_called_once_with(
brightness / 255 * 100, duration=transition * 1000, light_type=LightType.Main brightness / 255 * 100, duration=transition * 1000, light_type=LightType.Main
) )
@ -452,7 +452,7 @@ async def test_services(hass: HomeAssistant, caplog):
) )
# set_music_mode failure enable # set_music_mode failure enable
mocked_bulb.start_music = MagicMock(side_effect=AssertionError) mocked_bulb.async_start_music = MagicMock(side_effect=AssertionError)
assert "Unable to turn on music mode, consider disabling it" not in caplog.text assert "Unable to turn on music mode, consider disabling it" not in caplog.text
await hass.services.async_call( await hass.services.async_call(
DOMAIN, DOMAIN,
@ -460,14 +460,14 @@ async def test_services(hass: HomeAssistant, caplog):
{ATTR_ENTITY_ID: ENTITY_LIGHT, ATTR_MODE_MUSIC: "true"}, {ATTR_ENTITY_ID: ENTITY_LIGHT, ATTR_MODE_MUSIC: "true"},
blocking=True, blocking=True,
) )
assert mocked_bulb.start_music.mock_calls == [call()] assert mocked_bulb.async_start_music.mock_calls == [call()]
assert "Unable to turn on music mode, consider disabling it" in caplog.text assert "Unable to turn on music mode, consider disabling it" in caplog.text
# set_music_mode disable # set_music_mode disable
await _async_test_service( await _async_test_service(
SERVICE_SET_MUSIC_MODE, SERVICE_SET_MUSIC_MODE,
{ATTR_ENTITY_ID: ENTITY_LIGHT, ATTR_MODE_MUSIC: "false"}, {ATTR_ENTITY_ID: ENTITY_LIGHT, ATTR_MODE_MUSIC: "false"},
"stop_music", "async_stop_music",
failure_side_effect=None, failure_side_effect=None,
) )
@ -475,7 +475,7 @@ async def test_services(hass: HomeAssistant, caplog):
await _async_test_service( await _async_test_service(
SERVICE_SET_MUSIC_MODE, SERVICE_SET_MUSIC_MODE,
{ATTR_ENTITY_ID: ENTITY_LIGHT, ATTR_MODE_MUSIC: "true"}, {ATTR_ENTITY_ID: ENTITY_LIGHT, ATTR_MODE_MUSIC: "true"},
"start_music", "async_start_music",
failure_side_effect=None, failure_side_effect=None,
) )
# test _cmd wrapper error handler # test _cmd wrapper error handler