mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 16:57:53 +00:00
Fix lifx service call interference (#77770)
* Fix #77735 by restoring the wait to let state settle Signed-off-by: Avi Miller <me@dje.li> * Skip the asyncio.sleep during testing Signed-off-by: Avi Miller <me@dje.li> * Patch out asyncio.sleep for lifx tests Signed-off-by: Avi Miller <me@dje.li> * Patch out a constant instead of overriding asyncio.sleep directly Signed-off-by: Avi Miller <me@dje.li> Signed-off-by: Avi Miller <me@dje.li>
This commit is contained in:
parent
a9c19e2ffb
commit
0e63a4c091
@ -25,6 +25,7 @@ from .const import (
|
||||
from .util import async_execute_lifx, get_real_mac_addr, lifx_features
|
||||
|
||||
REQUEST_REFRESH_DELAY = 0.35
|
||||
LIFX_IDENTIFY_DELAY = 3.0
|
||||
|
||||
|
||||
class LIFXUpdateCoordinator(DataUpdateCoordinator):
|
||||
@ -92,7 +93,7 @@ class LIFXUpdateCoordinator(DataUpdateCoordinator):
|
||||
# Turn the bulb on first, flash for 3 seconds, then turn off
|
||||
await self.async_set_power(state=True, duration=1)
|
||||
await self.async_set_waveform_optional(value=IDENTIFY_WAVEFORM)
|
||||
await asyncio.sleep(3)
|
||||
await asyncio.sleep(LIFX_IDENTIFY_DELAY)
|
||||
await self.async_set_power(state=False, duration=1)
|
||||
|
||||
async def _async_update_data(self) -> None:
|
||||
|
@ -39,7 +39,7 @@ from .manager import (
|
||||
)
|
||||
from .util import convert_8_to_16, convert_16_to_8, find_hsbk, lifx_features, merge_hsbk
|
||||
|
||||
COLOR_ZONE_POPULATE_DELAY = 0.3
|
||||
LIFX_STATE_SETTLE_DELAY = 0.3
|
||||
|
||||
SERVICE_LIFX_SET_STATE = "set_state"
|
||||
|
||||
@ -231,6 +231,9 @@ class LIFXLight(LIFXEntity, LightEntity):
|
||||
if power_off:
|
||||
await self.set_power(False, duration=fade)
|
||||
|
||||
# Avoid state ping-pong by holding off updates as the state settles
|
||||
await asyncio.sleep(LIFX_STATE_SETTLE_DELAY)
|
||||
|
||||
# Update when the transition starts and ends
|
||||
await self.update_during_transition(fade)
|
||||
|
||||
@ -338,7 +341,7 @@ class LIFXStrip(LIFXColor):
|
||||
# Zone brightness is not reported when powered off
|
||||
if not self.is_on and hsbk[HSBK_BRIGHTNESS] is None:
|
||||
await self.set_power(True)
|
||||
await asyncio.sleep(COLOR_ZONE_POPULATE_DELAY)
|
||||
await asyncio.sleep(LIFX_STATE_SETTLE_DELAY)
|
||||
await self.update_color_zones()
|
||||
await self.set_power(False)
|
||||
|
||||
|
@ -1,5 +1,4 @@
|
||||
"""Tests for the lifx integration."""
|
||||
|
||||
from unittest.mock import AsyncMock, MagicMock, patch
|
||||
|
||||
import pytest
|
||||
|
@ -1,4 +1,8 @@
|
||||
"""Tests for button platform."""
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant.components import lifx
|
||||
from homeassistant.components.button import DOMAIN as BUTTON_DOMAIN
|
||||
from homeassistant.components.lifx.const import DOMAIN
|
||||
@ -21,6 +25,13 @@ from . import (
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def mock_lifx_coordinator_sleep():
|
||||
"""Mock out lifx coordinator sleeps."""
|
||||
with patch("homeassistant.components.lifx.coordinator.LIFX_IDENTIFY_DELAY", 0):
|
||||
yield
|
||||
|
||||
|
||||
async def test_button_restart(hass: HomeAssistant) -> None:
|
||||
"""Test that a bulb can be restarted."""
|
||||
config_entry = MockConfigEntry(
|
||||
|
@ -50,6 +50,13 @@ from . import (
|
||||
from tests.common import MockConfigEntry, async_fire_time_changed
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def patch_lifx_state_settle_delay():
|
||||
"""Set asyncio.sleep for state settles to zero."""
|
||||
with patch("homeassistant.components.lifx.light.LIFX_STATE_SETTLE_DELAY", 0):
|
||||
yield
|
||||
|
||||
|
||||
async def test_light_unique_id(hass: HomeAssistant) -> None:
|
||||
"""Test a light unique id."""
|
||||
already_migrated_config_entry = MockConfigEntry(
|
||||
@ -98,7 +105,6 @@ async def test_light_unique_id_new_firmware(hass: HomeAssistant) -> None:
|
||||
assert device.identifiers == {(DOMAIN, SERIAL)}
|
||||
|
||||
|
||||
@patch("homeassistant.components.lifx.light.COLOR_ZONE_POPULATE_DELAY", 0)
|
||||
async def test_light_strip(hass: HomeAssistant) -> None:
|
||||
"""Test a light strip."""
|
||||
already_migrated_config_entry = MockConfigEntry(
|
||||
|
Loading…
x
Reference in New Issue
Block a user