mirror of
https://github.com/home-assistant/core.git
synced 2026-05-08 17:49:37 +01:00
Fix flaky airtouch5 test for Python 3.14.3 (#168366)
This commit is contained in:
committed by
GitHub
parent
8eef269ce3
commit
e1d38fa237
@@ -1,6 +1,5 @@
|
||||
"""Tests for the Airtouch5 cover platform."""
|
||||
|
||||
from collections.abc import Callable
|
||||
from unittest.mock import AsyncMock, patch
|
||||
|
||||
from airtouch5py.packets.zone_status import (
|
||||
@@ -28,6 +27,7 @@ from . import setup_integration
|
||||
from tests.common import MockConfigEntry, snapshot_platform
|
||||
|
||||
COVER_ENTITY_ID = "cover.zone_1_damper"
|
||||
COVER_ZONE_2_ENTITY_ID = "cover.zone_2_damper"
|
||||
|
||||
|
||||
async def test_all_entities(
|
||||
@@ -91,13 +91,14 @@ async def test_cover_callbacks(
|
||||
|
||||
await setup_integration(hass, mock_config_entry)
|
||||
|
||||
# We find the callback method on the mock client
|
||||
zone_status_callback: Callable[[dict[int, ZoneStatusZone]], None] = (
|
||||
mock_airtouch5_client.zone_status_callbacks[2]
|
||||
)
|
||||
# Capture initial state of zone 2 cover to verify it's unaffected
|
||||
zone_2_initial = hass.states.get(COVER_ZONE_2_ENTITY_ID)
|
||||
assert zone_2_initial
|
||||
zone_2_initial_state = zone_2_initial.state
|
||||
zone_2_initial_position = zone_2_initial.attributes.get(ATTR_CURRENT_POSITION)
|
||||
|
||||
# Define a method to simply call it
|
||||
async def _call_zone_status_callback(open_percentage: int) -> None:
|
||||
# Define a method to call all zone_status_callbacks, as the real client would
|
||||
async def _call_zone_status_callback(open_percentage: float) -> None:
|
||||
zsz = ZoneStatusZone(
|
||||
zone_power_state=ZonePowerState.ON,
|
||||
zone_number=1,
|
||||
@@ -109,7 +110,9 @@ async def test_cover_callbacks(
|
||||
spill_active=False,
|
||||
is_low_battery=False,
|
||||
)
|
||||
zone_status_callback({1: zsz})
|
||||
data = {1: zsz}
|
||||
for callback in mock_airtouch5_client.zone_status_callbacks:
|
||||
callback(data)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
# And call it to effectively launch the callback as the server would do
|
||||
@@ -120,6 +123,9 @@ async def test_cover_callbacks(
|
||||
assert state
|
||||
assert state.state == CoverState.OPEN
|
||||
assert state.attributes.get(ATTR_CURRENT_POSITION) == 70
|
||||
zone_2 = hass.states.get(COVER_ZONE_2_ENTITY_ID)
|
||||
assert zone_2 and zone_2.state == zone_2_initial_state
|
||||
assert zone_2.attributes.get(ATTR_CURRENT_POSITION) == zone_2_initial_position
|
||||
|
||||
# Fully open
|
||||
await _call_zone_status_callback(1)
|
||||
@@ -127,6 +133,9 @@ async def test_cover_callbacks(
|
||||
assert state
|
||||
assert state.state == CoverState.OPEN
|
||||
assert state.attributes.get(ATTR_CURRENT_POSITION) == 100
|
||||
zone_2 = hass.states.get(COVER_ZONE_2_ENTITY_ID)
|
||||
assert zone_2 and zone_2.state == zone_2_initial_state
|
||||
assert zone_2.attributes.get(ATTR_CURRENT_POSITION) == zone_2_initial_position
|
||||
|
||||
# Fully closed
|
||||
await _call_zone_status_callback(0.0)
|
||||
@@ -134,6 +143,9 @@ async def test_cover_callbacks(
|
||||
assert state
|
||||
assert state.state == CoverState.CLOSED
|
||||
assert state.attributes.get(ATTR_CURRENT_POSITION) == 0
|
||||
zone_2 = hass.states.get(COVER_ZONE_2_ENTITY_ID)
|
||||
assert zone_2 and zone_2.state == zone_2_initial_state
|
||||
assert zone_2.attributes.get(ATTR_CURRENT_POSITION) == zone_2_initial_position
|
||||
|
||||
# Partly reopened
|
||||
await _call_zone_status_callback(0.3)
|
||||
@@ -141,3 +153,6 @@ async def test_cover_callbacks(
|
||||
assert state
|
||||
assert state.state == CoverState.OPEN
|
||||
assert state.attributes.get(ATTR_CURRENT_POSITION) == 30
|
||||
zone_2 = hass.states.get(COVER_ZONE_2_ENTITY_ID)
|
||||
assert zone_2 and zone_2.state == zone_2_initial_state
|
||||
assert zone_2.attributes.get(ATTR_CURRENT_POSITION) == zone_2_initial_position
|
||||
|
||||
Reference in New Issue
Block a user