Replace aioclient_mock in Sensibo tests (#134543)

This commit is contained in:
G Johansson 2025-01-04 12:14:58 +01:00 committed by GitHub
parent b3cb2928fc
commit ebeb2ecb09
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 421 additions and 467 deletions

View File

@ -7,7 +7,7 @@ import json
from typing import Any
from unittest.mock import AsyncMock, MagicMock, patch
from pysensibo import APIV1, APIV2, SensiboClient, SensiboData
from pysensibo import SensiboClient, SensiboData
import pytest
from homeassistant.components.sensibo.const import DOMAIN, PLATFORMS
@ -62,17 +62,21 @@ async def load_int(
@pytest.fixture(name="mock_client")
async def get_client(
hass: HomeAssistant,
get_data: tuple[SensiboData, dict[str, Any]],
get_data: tuple[SensiboData, dict[str, Any], dict[str, Any]],
) -> AsyncGenerator[MagicMock]:
"""Mock SensiboClient."""
with patch(
"homeassistant.components.sensibo.coordinator.SensiboClient",
autospec=True,
) as mock_client:
with (
patch(
"homeassistant.components.sensibo.coordinator.SensiboClient",
autospec=True,
) as mock_client,
patch("homeassistant.components.sensibo.util.SensiboClient", new=mock_client),
):
client = mock_client.return_value
client.async_get_devices_data.return_value = get_data[0]
client.async_get_me.return_value = get_data[1]
client.async_get_devices.return_value = get_data[2]
yield client
@ -81,24 +85,23 @@ async def get_data_from_library(
hass: HomeAssistant,
aioclient_mock: AiohttpClientMocker,
load_json: tuple[dict[str, Any], dict[str, Any]],
) -> AsyncGenerator[tuple[SensiboData, dict[str, Any]]]:
) -> AsyncGenerator[tuple[SensiboData, dict[str, Any], dict[str, Any]]]:
"""Get data from api."""
aioclient_mock.request(
"GET",
url=APIV1 + "/users/me",
params={"apiKey": "1234567890"},
json=load_json[1],
)
aioclient_mock.request(
"GET",
url=APIV2 + "/users/me/pods",
params={"apiKey": "1234567890", "fields": "*"},
json=load_json[0],
)
client = SensiboClient("1234567890", aioclient_mock.create_session(hass.loop))
me = await client.async_get_me()
data = await client.async_get_devices_data()
yield (data, me)
with patch.object(
client,
"async_get_me",
return_value=load_json[1],
):
me = await client.async_get_me()
with patch.object(
client,
"async_get_devices",
return_value=load_json[0],
):
data = await client.async_get_devices_data()
raw_data = await client.async_get_devices()
yield (data, me, raw_data)
await client._session.close()

View File

@ -3,11 +3,9 @@
from __future__ import annotations
from datetime import timedelta
from typing import Any
from unittest.mock import patch
from unittest.mock import MagicMock
from freezegun.api import FrozenDateTimeFactory
from pysensibo import SensiboData
import pytest
from syrupy.assertion import SnapshotAssertion
@ -27,8 +25,7 @@ from tests.common import async_fire_time_changed, snapshot_platform
async def test_binary_sensor(
hass: HomeAssistant,
load_int: ConfigEntry,
monkeypatch: pytest.MonkeyPatch,
get_data: tuple[SensiboData, dict[str, Any]],
mock_client: MagicMock,
entity_registry: er.EntityRegistry,
snapshot: SnapshotAssertion,
freezer: FrozenDateTimeFactory,
@ -37,17 +34,13 @@ async def test_binary_sensor(
await snapshot_platform(hass, entity_registry, snapshot, load_int.entry_id)
monkeypatch.setattr(
get_data[0].parsed["ABC999111"].motion_sensors["AABBCC"], "motion", False
)
mock_client.async_get_devices_data.return_value.parsed["ABC999111"].motion_sensors[
"AABBCC"
].motion = False
with patch(
"homeassistant.components.sensibo.coordinator.SensiboClient.async_get_devices_data",
return_value=get_data,
):
freezer.tick(timedelta(minutes=5))
async_fire_time_changed(hass)
await hass.async_block_till_done()
freezer.tick(timedelta(minutes=5))
async_fire_time_changed(hass)
await hass.async_block_till_done()
assert (
hass.states.get("binary_sensor.hallway_motion_sensor_connectivity").state

View File

@ -3,12 +3,10 @@
from __future__ import annotations
from datetime import timedelta
from typing import Any
from unittest.mock import MagicMock
from freezegun import freeze_time
from freezegun.api import FrozenDateTimeFactory
from pysensibo import SensiboData
import pytest
from syrupy.assertion import SnapshotAssertion
@ -54,9 +52,7 @@ async def test_button(
async def test_button_update(
hass: HomeAssistant,
load_int: ConfigEntry,
monkeypatch: pytest.MonkeyPatch,
mock_client: MagicMock,
get_data: tuple[SensiboData, dict[str, Any]],
freezer: FrozenDateTimeFactory,
) -> None:
"""Test the Sensibo button press."""
@ -85,12 +81,12 @@ async def test_button_update(
blocking=True,
)
monkeypatch.setattr(get_data[0].parsed["ABC999111"], "filter_clean", False)
monkeypatch.setattr(
get_data[0].parsed["ABC999111"],
"filter_last_reset",
today,
)
mock_client.async_get_devices_data.return_value.parsed[
"ABC999111"
].filter_clean = False
mock_client.async_get_devices_data.return_value.parsed[
"ABC999111"
].filter_last_reset = today
freezer.tick(timedelta(minutes=5))
async_fire_time_changed(hass)

View File

@ -3,11 +3,9 @@
from __future__ import annotations
from datetime import datetime, timedelta
from typing import Any
from unittest.mock import MagicMock
from freezegun.api import FrozenDateTimeFactory
from pysensibo.model import SensiboData
import pytest
from syrupy.assertion import SnapshotAssertion
from voluptuous import MultipleInvalid
@ -109,9 +107,7 @@ async def test_climate(
async def test_climate_fan(
hass: HomeAssistant,
load_int: ConfigEntry,
monkeypatch: pytest.MonkeyPatch,
mock_client: MagicMock,
get_data: tuple[SensiboData, dict[str, Any]],
freezer: FrozenDateTimeFactory,
) -> None:
"""Test the Sensibo climate fan service."""
@ -119,21 +115,21 @@ async def test_climate_fan(
state = hass.states.get("climate.hallway")
assert state.attributes["fan_mode"] == "high"
monkeypatch.setattr(
get_data[0].parsed["ABC999111"],
"fan_modes",
["quiet", "low", "medium", "not_in_ha"],
)
monkeypatch.setattr(
get_data[0].parsed["ABC999111"],
"fan_modes_translated",
{
"low": "low",
"medium": "medium",
"quiet": "quiet",
"not_in_ha": "not_in_ha",
},
)
mock_client.async_get_devices_data.return_value.parsed["ABC999111"].fan_modes = [
"quiet",
"low",
"medium",
"not_in_ha",
]
mock_client.async_get_devices_data.return_value.parsed[
"ABC999111"
].fan_modes_translated = {
"low": "low",
"medium": "medium",
"quiet": "quiet",
"not_in_ha": "not_in_ha",
}
with pytest.raises(
HomeAssistantError,
match="Climate fan mode not_in_ha is not supported by the integration",
@ -159,19 +155,17 @@ async def test_climate_fan(
state = hass.states.get("climate.hallway")
assert state.attributes["fan_mode"] == "low"
monkeypatch.setattr(
get_data[0].parsed["ABC999111"],
"active_features",
[
"timestamp",
"on",
"mode",
"swing",
"targetTemperature",
"horizontalSwing",
"light",
],
)
mock_client.async_get_devices_data.return_value.parsed[
"ABC999111"
].active_features = [
"timestamp",
"on",
"mode",
"swing",
"targetTemperature",
"horizontalSwing",
"light",
]
freezer.tick(timedelta(minutes=5))
async_fire_time_changed(hass)
@ -192,9 +186,7 @@ async def test_climate_fan(
async def test_climate_swing(
hass: HomeAssistant,
load_int: ConfigEntry,
monkeypatch: pytest.MonkeyPatch,
mock_client: MagicMock,
get_data: tuple[SensiboData, dict[str, Any]],
freezer: FrozenDateTimeFactory,
) -> None:
"""Test the Sensibo climate swing service."""
@ -202,21 +194,21 @@ async def test_climate_swing(
state = hass.states.get("climate.hallway")
assert state.attributes["swing_mode"] == "stopped"
monkeypatch.setattr(
get_data[0].parsed["ABC999111"],
"swing_modes",
["stopped", "fixedtop", "fixedmiddletop", "not_in_ha"],
)
monkeypatch.setattr(
get_data[0].parsed["ABC999111"],
"swing_modes_translated",
{
"fixedmiddletop": "fixedMiddleTop",
"fixedtop": "fixedTop",
"stopped": "stopped",
"not_in_ha": "not_in_ha",
},
)
mock_client.async_get_devices_data.return_value.parsed["ABC999111"].swing_modes = [
"stopped",
"fixedtop",
"fixedmiddletop",
"not_in_ha",
]
mock_client.async_get_devices_data.return_value.parsed[
"ABC999111"
].swing_modes_translated = {
"fixedmiddletop": "fixedMiddleTop",
"fixedtop": "fixedTop",
"stopped": "stopped",
"not_in_ha": "not_in_ha",
}
freezer.tick(timedelta(minutes=5))
async_fire_time_changed(hass)
await hass.async_block_till_done()
@ -246,18 +238,16 @@ async def test_climate_swing(
state = hass.states.get("climate.hallway")
assert state.attributes["swing_mode"] == "fixedtop"
monkeypatch.setattr(
get_data[0].parsed["ABC999111"],
"active_features",
[
"timestamp",
"on",
"mode",
"targetTemperature",
"horizontalSwing",
"light",
],
)
mock_client.async_get_devices_data.return_value.parsed[
"ABC999111"
].active_features = [
"timestamp",
"on",
"mode",
"targetTemperature",
"horizontalSwing",
"light",
]
freezer.tick(timedelta(minutes=5))
async_fire_time_changed(hass)
await hass.async_block_till_done()
@ -277,9 +267,7 @@ async def test_climate_swing(
async def test_climate_temperatures(
hass: HomeAssistant,
load_int: ConfigEntry,
monkeypatch: pytest.MonkeyPatch,
mock_client: MagicMock,
get_data: tuple[SensiboData, dict[str, Any]],
freezer: FrozenDateTimeFactory,
) -> None:
"""Test the Sensibo climate temperature service."""
@ -370,18 +358,16 @@ async def test_climate_temperatures(
state = hass.states.get("climate.hallway")
assert state.attributes["temperature"] == 20
monkeypatch.setattr(
get_data[0].parsed["ABC999111"],
"active_features",
[
"timestamp",
"on",
"mode",
"swing",
"horizontalSwing",
"light",
],
)
mock_client.async_get_devices_data.return_value.parsed[
"ABC999111"
].active_features = [
"timestamp",
"on",
"mode",
"swing",
"horizontalSwing",
"light",
]
freezer.tick(timedelta(minutes=5))
async_fire_time_changed(hass)
@ -402,32 +388,24 @@ async def test_climate_temperatures(
async def test_climate_temperature_is_none(
hass: HomeAssistant,
load_int: ConfigEntry,
monkeypatch: pytest.MonkeyPatch,
mock_client: MagicMock,
get_data: tuple[SensiboData, dict[str, Any]],
freezer: FrozenDateTimeFactory,
) -> None:
"""Test the Sensibo climate temperature service no temperature provided."""
monkeypatch.setattr(
get_data[0].parsed["ABC999111"],
"active_features",
[
"timestamp",
"on",
"mode",
"fanLevel",
"targetTemperature",
"swing",
"horizontalSwing",
"light",
],
)
monkeypatch.setattr(
get_data[0].parsed["ABC999111"],
"target_temp",
25,
)
mock_client.async_get_devices_data.return_value.parsed[
"ABC999111"
].active_features = [
"timestamp",
"on",
"mode",
"fanLevel",
"targetTemperature",
"swing",
"horizontalSwing",
"light",
]
mock_client.async_get_devices_data.return_value.parsed["ABC999111"].target_temp = 25
freezer.tick(timedelta(minutes=5))
async_fire_time_changed(hass)
@ -455,27 +433,23 @@ async def test_climate_temperature_is_none(
async def test_climate_hvac_mode(
hass: HomeAssistant,
load_int: ConfigEntry,
monkeypatch: pytest.MonkeyPatch,
mock_client: MagicMock,
get_data: tuple[SensiboData, dict[str, Any]],
freezer: FrozenDateTimeFactory,
) -> None:
"""Test the Sensibo climate hvac mode service."""
monkeypatch.setattr(
get_data[0].parsed["ABC999111"],
"active_features",
[
"timestamp",
"on",
"mode",
"fanLevel",
"targetTemperature",
"swing",
"horizontalSwing",
"light",
],
)
mock_client.async_get_devices_data.return_value.parsed[
"ABC999111"
].active_features = [
"timestamp",
"on",
"mode",
"fanLevel",
"targetTemperature",
"swing",
"horizontalSwing",
"light",
]
freezer.tick(timedelta(minutes=5))
async_fire_time_changed(hass)
@ -498,7 +472,9 @@ async def test_climate_hvac_mode(
state = hass.states.get("climate.hallway")
assert state.state == HVACMode.OFF
monkeypatch.setattr(get_data[0].parsed["ABC999111"], "device_on", False)
mock_client.async_get_devices_data.return_value.parsed[
"ABC999111"
].device_on = False
freezer.tick(timedelta(minutes=5))
async_fire_time_changed(hass)
@ -518,15 +494,15 @@ async def test_climate_hvac_mode(
async def test_climate_on_off(
hass: HomeAssistant,
load_int: ConfigEntry,
monkeypatch: pytest.MonkeyPatch,
mock_client: MagicMock,
get_data: tuple[SensiboData, dict[str, Any]],
freezer: FrozenDateTimeFactory,
) -> None:
"""Test the Sensibo climate on/off service."""
monkeypatch.setattr(get_data[0].parsed["ABC999111"], "hvac_mode", "heat")
monkeypatch.setattr(get_data[0].parsed["ABC999111"], "device_on", True)
mock_client.async_get_devices_data.return_value.parsed[
"ABC999111"
].hvac_mode = "heat"
mock_client.async_get_devices_data.return_value.parsed["ABC999111"].device_on = True
freezer.tick(timedelta(minutes=5))
async_fire_time_changed(hass)
@ -563,15 +539,15 @@ async def test_climate_on_off(
async def test_climate_service_failed(
hass: HomeAssistant,
load_int: ConfigEntry,
monkeypatch: pytest.MonkeyPatch,
mock_client: MagicMock,
get_data: tuple[SensiboData, dict[str, Any]],
freezer: FrozenDateTimeFactory,
) -> None:
"""Test the Sensibo climate service failed."""
monkeypatch.setattr(get_data[0].parsed["ABC999111"], "hvac_mode", "heat")
monkeypatch.setattr(get_data[0].parsed["ABC999111"], "device_on", True)
mock_client.async_get_devices_data.return_value.parsed[
"ABC999111"
].hvac_mode = "heat"
mock_client.async_get_devices_data.return_value.parsed["ABC999111"].device_on = True
freezer.tick(timedelta(minutes=5))
async_fire_time_changed(hass)
@ -599,15 +575,15 @@ async def test_climate_service_failed(
async def test_climate_assumed_state(
hass: HomeAssistant,
load_int: ConfigEntry,
monkeypatch: pytest.MonkeyPatch,
mock_client: MagicMock,
get_data: tuple[SensiboData, dict[str, Any]],
freezer: FrozenDateTimeFactory,
) -> None:
"""Test the Sensibo climate assumed state service."""
monkeypatch.setattr(get_data[0].parsed["ABC999111"], "hvac_mode", "heat")
monkeypatch.setattr(get_data[0].parsed["ABC999111"], "device_on", True)
mock_client.async_get_devices_data.return_value.parsed[
"ABC999111"
].hvac_mode = "heat"
mock_client.async_get_devices_data.return_value.parsed["ABC999111"].device_on = True
freezer.tick(timedelta(minutes=5))
async_fire_time_changed(hass)
@ -634,8 +610,7 @@ async def test_climate_assumed_state(
async def test_climate_no_fan_no_swing(
hass: HomeAssistant,
load_int: ConfigEntry,
monkeypatch: pytest.MonkeyPatch,
get_data: tuple[SensiboData, dict[str, Any]],
mock_client: MagicMock,
freezer: FrozenDateTimeFactory,
) -> None:
"""Test the Sensibo climate fan."""
@ -644,10 +619,14 @@ async def test_climate_no_fan_no_swing(
assert state.attributes["fan_mode"] == "high"
assert state.attributes["swing_mode"] == "stopped"
monkeypatch.setattr(get_data[0].parsed["ABC999111"], "fan_mode", None)
monkeypatch.setattr(get_data[0].parsed["ABC999111"], "swing_mode", None)
monkeypatch.setattr(get_data[0].parsed["ABC999111"], "fan_modes", None)
monkeypatch.setattr(get_data[0].parsed["ABC999111"], "swing_modes", None)
mock_client.async_get_devices_data.return_value.parsed["ABC999111"].fan_mode = None
mock_client.async_get_devices_data.return_value.parsed[
"ABC999111"
].swing_mode = None
mock_client.async_get_devices_data.return_value.parsed["ABC999111"].fan_modes = None
mock_client.async_get_devices_data.return_value.parsed[
"ABC999111"
].swing_modes = None
freezer.tick(timedelta(minutes=5))
async_fire_time_changed(hass)
@ -664,9 +643,7 @@ async def test_climate_no_fan_no_swing(
async def test_climate_set_timer(
hass: HomeAssistant,
load_int: ConfigEntry,
monkeypatch: pytest.MonkeyPatch,
mock_client: MagicMock,
get_data: tuple[SensiboData, dict[str, Any]],
freezer: FrozenDateTimeFactory,
) -> None:
"""Test the Sensibo climate Set Timer service."""
@ -716,14 +693,16 @@ async def test_climate_set_timer(
blocking=True,
)
monkeypatch.setattr(get_data[0].parsed["ABC999111"], "timer_on", True)
monkeypatch.setattr(get_data[0].parsed["ABC999111"], "timer_id", "SzTGE4oZ4D")
monkeypatch.setattr(get_data[0].parsed["ABC999111"], "timer_state_on", False)
monkeypatch.setattr(
get_data[0].parsed["ABC999111"],
"timer_time",
datetime(2022, 6, 6, 12, 00, 00, tzinfo=dt_util.UTC),
)
mock_client.async_get_devices_data.return_value.parsed["ABC999111"].timer_on = True
mock_client.async_get_devices_data.return_value.parsed[
"ABC999111"
].timer_id = "SzTGE4oZ4D"
mock_client.async_get_devices_data.return_value.parsed[
"ABC999111"
].timer_state_on = False
mock_client.async_get_devices_data.return_value.parsed[
"ABC999111"
].timer_time = datetime(2022, 6, 6, 12, 00, 00, tzinfo=dt_util.UTC)
freezer.tick(timedelta(minutes=5))
async_fire_time_changed(hass)
@ -739,9 +718,7 @@ async def test_climate_set_timer(
async def test_climate_pure_boost(
hass: HomeAssistant,
load_int: ConfigEntry,
monkeypatch: pytest.MonkeyPatch,
mock_client: MagicMock,
get_data: tuple[SensiboData, dict[str, Any]],
freezer: FrozenDateTimeFactory,
) -> None:
"""Test the Sensibo climate pure boost service."""
@ -795,12 +772,18 @@ async def test_climate_pure_boost(
blocking=True,
)
monkeypatch.setattr(get_data[0].parsed["AAZZAAZZ"], "pure_boost_enabled", True)
monkeypatch.setattr(get_data[0].parsed["AAZZAAZZ"], "pure_sensitivity", "s")
monkeypatch.setattr(
get_data[0].parsed["AAZZAAZZ"], "pure_measure_integration", True
)
monkeypatch.setattr(get_data[0].parsed["AAZZAAZZ"], "pure_prime_integration", True)
mock_client.async_get_devices_data.return_value.parsed[
"AAZZAAZZ"
].pure_boost_enabled = True
mock_client.async_get_devices_data.return_value.parsed[
"AAZZAAZZ"
].pure_sensitivity = "s"
mock_client.async_get_devices_data.return_value.parsed[
"AAZZAAZZ"
].pure_measure_integration = True
mock_client.async_get_devices_data.return_value.parsed[
"AAZZAAZZ"
].pure_prime_integration = True
freezer.tick(timedelta(minutes=5))
async_fire_time_changed(hass)
@ -826,9 +809,7 @@ async def test_climate_pure_boost(
async def test_climate_climate_react(
hass: HomeAssistant,
load_int: ConfigEntry,
monkeypatch: pytest.MonkeyPatch,
mock_client: MagicMock,
get_data: tuple[SensiboData, dict[str, Any]],
freezer: FrozenDateTimeFactory,
) -> None:
"""Test the Sensibo climate react custom service."""
@ -917,42 +898,40 @@ async def test_climate_climate_react(
blocking=True,
)
monkeypatch.setattr(get_data[0].parsed["ABC999111"], "smart_on", True)
monkeypatch.setattr(get_data[0].parsed["ABC999111"], "smart_type", "temperature")
monkeypatch.setattr(
get_data[0].parsed["ABC999111"], "smart_low_temp_threshold", 5.5
)
monkeypatch.setattr(
get_data[0].parsed["ABC999111"], "smart_high_temp_threshold", 30.5
)
monkeypatch.setattr(
get_data[0].parsed["ABC999111"],
"smart_low_state",
{
"on": True,
"targetTemperature": 25,
"temperatureUnit": "C",
"mode": "heat",
"fanLevel": "low",
"swing": "stopped",
"horizontalSwing": "stopped",
"light": "on",
},
)
monkeypatch.setattr(
get_data[0].parsed["ABC999111"],
"smart_high_state",
{
"on": True,
"targetTemperature": 15,
"temperatureUnit": "C",
"mode": "cool",
"fanLevel": "high",
"swing": "stopped",
"horizontalSwing": "stopped",
"light": "on",
},
)
mock_client.async_get_devices_data.return_value.parsed["ABC999111"].smart_on = True
mock_client.async_get_devices_data.return_value.parsed[
"ABC999111"
].smart_type = "temperature"
mock_client.async_get_devices_data.return_value.parsed[
"ABC999111"
].smart_low_temp_threshold = 5.5
mock_client.async_get_devices_data.return_value.parsed[
"ABC999111"
].smart_high_temp_threshold = 30.5
mock_client.async_get_devices_data.return_value.parsed[
"ABC999111"
].smart_low_state = {
"on": True,
"targetTemperature": 25,
"temperatureUnit": "C",
"mode": "heat",
"fanLevel": "low",
"swing": "stopped",
"horizontalSwing": "stopped",
"light": "on",
}
mock_client.async_get_devices_data.return_value.parsed[
"ABC999111"
].smart_high_state = {
"on": True,
"targetTemperature": 15,
"temperatureUnit": "C",
"mode": "cool",
"fanLevel": "high",
"swing": "stopped",
"horizontalSwing": "stopped",
"light": "on",
}
freezer.tick(timedelta(minutes=5))
async_fire_time_changed(hass)
@ -974,9 +953,7 @@ async def test_climate_climate_react(
async def test_climate_climate_react_fahrenheit(
hass: HomeAssistant,
load_int: ConfigEntry,
monkeypatch: pytest.MonkeyPatch,
mock_client: MagicMock,
get_data: tuple[SensiboData, dict[str, Any]],
freezer: FrozenDateTimeFactory,
) -> None:
"""Test the Sensibo climate react custom service with fahrenheit."""
@ -1050,40 +1027,40 @@ async def test_climate_climate_react_fahrenheit(
blocking=True,
)
monkeypatch.setattr(get_data[0].parsed["ABC999111"], "smart_on", True)
monkeypatch.setattr(get_data[0].parsed["ABC999111"], "smart_type", "temperature")
monkeypatch.setattr(get_data[0].parsed["ABC999111"], "smart_low_temp_threshold", 0)
monkeypatch.setattr(
get_data[0].parsed["ABC999111"], "smart_high_temp_threshold", 25
)
monkeypatch.setattr(
get_data[0].parsed["ABC999111"],
"smart_low_state",
{
"on": True,
"targetTemperature": 85,
"temperatureUnit": "F",
"mode": "heat",
"fanLevel": "low",
"swing": "stopped",
"horizontalSwing": "stopped",
"light": "on",
},
)
monkeypatch.setattr(
get_data[0].parsed["ABC999111"],
"smart_high_state",
{
"on": True,
"targetTemperature": 65,
"temperatureUnit": "F",
"mode": "cool",
"fanLevel": "high",
"swing": "stopped",
"horizontalSwing": "stopped",
"light": "on",
},
)
mock_client.async_get_devices_data.return_value.parsed["ABC999111"].smart_on = True
mock_client.async_get_devices_data.return_value.parsed[
"ABC999111"
].smart_type = "temperature"
mock_client.async_get_devices_data.return_value.parsed[
"ABC999111"
].smart_low_temp_threshold = 0
mock_client.async_get_devices_data.return_value.parsed[
"ABC999111"
].smart_high_temp_threshold = 25
mock_client.async_get_devices_data.return_value.parsed[
"ABC999111"
].smart_low_state = {
"on": True,
"targetTemperature": 85,
"temperatureUnit": "F",
"mode": "heat",
"fanLevel": "low",
"swing": "stopped",
"horizontalSwing": "stopped",
"light": "on",
}
mock_client.async_get_devices_data.return_value.parsed[
"ABC999111"
].smart_high_state = {
"on": True,
"targetTemperature": 65,
"temperatureUnit": "F",
"mode": "cool",
"fanLevel": "high",
"swing": "stopped",
"horizontalSwing": "stopped",
"light": "on",
}
freezer.tick(timedelta(minutes=5))
async_fire_time_changed(hass)
@ -1105,9 +1082,7 @@ async def test_climate_climate_react_fahrenheit(
async def test_climate_full_ac_state(
hass: HomeAssistant,
load_int: ConfigEntry,
monkeypatch: pytest.MonkeyPatch,
mock_client: MagicMock,
get_data: tuple[SensiboData, dict[str, Any]],
freezer: FrozenDateTimeFactory,
) -> None:
"""Test the Sensibo climate Full AC state service."""
@ -1149,15 +1124,23 @@ async def test_climate_full_ac_state(
blocking=True,
)
monkeypatch.setattr(get_data[0].parsed["ABC999111"], "hvac_mode", "cool")
monkeypatch.setattr(get_data[0].parsed["ABC999111"], "device_on", True)
monkeypatch.setattr(get_data[0].parsed["ABC999111"], "target_temp", 22)
monkeypatch.setattr(get_data[0].parsed["ABC999111"], "fan_mode", "high")
monkeypatch.setattr(get_data[0].parsed["ABC999111"], "swing_mode", "stopped")
monkeypatch.setattr(
get_data[0].parsed["ABC999111"], "horizontal_swing_mode", "stopped"
)
monkeypatch.setattr(get_data[0].parsed["ABC999111"], "light_mode", "on")
mock_client.async_get_devices_data.return_value.parsed[
"ABC999111"
].hvac_mode = "cool"
mock_client.async_get_devices_data.return_value.parsed["ABC999111"].device_on = True
mock_client.async_get_devices_data.return_value.parsed["ABC999111"].target_temp = 22
mock_client.async_get_devices_data.return_value.parsed[
"ABC999111"
].fan_mode = "high"
mock_client.async_get_devices_data.return_value.parsed[
"ABC999111"
].swing_mode = "stopped"
mock_client.async_get_devices_data.return_value.parsed[
"ABC999111"
].horizontal_swing_mode = "stopped"
mock_client.async_get_devices_data.return_value.parsed[
"ABC999111"
].light_mode = "on"
freezer.tick(timedelta(minutes=5))
async_fire_time_changed(hass)

View File

@ -3,9 +3,9 @@
from __future__ import annotations
from typing import Any
from unittest.mock import AsyncMock, MagicMock, patch
from unittest.mock import AsyncMock, MagicMock
from pysensibo import AuthenticationError, SensiboError
from pysensibo import AuthenticationError, SensiboData, SensiboError
import pytest
from homeassistant import config_entries
@ -37,7 +37,6 @@ async def test_basic_setup(
CONF_API_KEY: "1234567890",
},
)
await hass.async_block_till_done()
assert result["type"] is FlowResultType.CREATE_ENTRY
assert result["version"] == 2
@ -69,19 +68,19 @@ async def test_flow_fails(
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == config_entries.SOURCE_USER
with patch(
"homeassistant.components.sensibo.util.SensiboClient.async_get_devices",
side_effect=error_message,
):
result = await hass.config_entries.flow.async_configure(
result["flow_id"],
user_input={
CONF_API_KEY: "1234567890",
},
)
mock_client.async_get_devices.side_effect = error_message
result = await hass.config_entries.flow.async_configure(
result["flow_id"],
user_input={
CONF_API_KEY: "1234567890",
},
)
assert result["errors"] == {"base": p_error}
mock_client.async_get_devices.side_effect = None
result = await hass.config_entries.flow.async_configure(
result["flow_id"],
user_input={
@ -96,7 +95,11 @@ async def test_flow_fails(
}
async def test_flow_get_no_devices(hass: HomeAssistant, mock_client: MagicMock) -> None:
async def test_flow_get_no_devices(
hass: HomeAssistant,
mock_client: MagicMock,
get_data: tuple[SensiboData, dict[str, Any], dict[str, Any]],
) -> None:
"""Test config flow get no devices from api."""
result = await hass.config_entries.flow.async_init(
@ -106,19 +109,19 @@ async def test_flow_get_no_devices(hass: HomeAssistant, mock_client: MagicMock)
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == config_entries.SOURCE_USER
with patch(
"homeassistant.components.sensibo.util.SensiboClient.async_get_devices",
return_value={"result": {}},
):
result = await hass.config_entries.flow.async_configure(
result["flow_id"],
user_input={
CONF_API_KEY: "1234567890",
},
)
mock_client.async_get_devices.return_value = {"result": []}
result = await hass.config_entries.flow.async_configure(
result["flow_id"],
user_input={
CONF_API_KEY: "1234567890",
},
)
assert result["errors"] == {"base": "no_devices"}
mock_client.async_get_devices.return_value = get_data[2]
result = await hass.config_entries.flow.async_configure(
result["flow_id"],
user_input={
@ -134,7 +137,9 @@ async def test_flow_get_no_devices(hass: HomeAssistant, mock_client: MagicMock)
async def test_flow_get_no_username(
hass: HomeAssistant, mock_client: MagicMock
hass: HomeAssistant,
mock_client: MagicMock,
get_data: tuple[SensiboData, dict[str, Any], dict[str, Any]],
) -> None:
"""Test config flow get no username from api."""
@ -145,19 +150,19 @@ async def test_flow_get_no_username(
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == config_entries.SOURCE_USER
with patch(
"homeassistant.components.sensibo.util.SensiboClient.async_get_me",
return_value={"result": {}},
):
result2 = await hass.config_entries.flow.async_configure(
result["flow_id"],
user_input={
CONF_API_KEY: "1234567890",
},
)
mock_client.async_get_me.return_value = {"result": {}}
result2 = await hass.config_entries.flow.async_configure(
result["flow_id"],
user_input={
CONF_API_KEY: "1234567890",
},
)
assert result2["errors"] == {"base": "no_username"}
mock_client.async_get_me.return_value = get_data[1]
result = await hass.config_entries.flow.async_configure(
result["flow_id"],
user_input={
@ -191,7 +196,6 @@ async def test_reauth_flow(hass: HomeAssistant, mock_client: MagicMock) -> None:
result["flow_id"],
{CONF_API_KEY: "1234567890"},
)
await hass.async_block_till_done()
assert result["type"] is FlowResultType.ABORT
assert result["reason"] == "reauth_successful"
@ -219,25 +223,23 @@ async def test_reauth_flow_error(
result = await entry.start_reauth_flow(hass)
with patch(
"homeassistant.components.sensibo.util.SensiboClient.async_get_devices",
side_effect=sideeffect,
):
result = await hass.config_entries.flow.async_configure(
result["flow_id"],
{CONF_API_KEY: "1234567890"},
)
await hass.async_block_till_done()
assert result["step_id"] == "reauth_confirm"
assert result["type"] is FlowResultType.FORM
assert result["errors"] == {"base": p_error}
mock_client.async_get_devices.side_effect = sideeffect
result = await hass.config_entries.flow.async_configure(
result["flow_id"],
{CONF_API_KEY: "1234567890"},
)
assert result["step_id"] == "reauth_confirm"
assert result["type"] is FlowResultType.FORM
assert result["errors"] == {"base": p_error}
mock_client.async_get_devices.side_effect = None
result = await hass.config_entries.flow.async_configure(
result["flow_id"],
{CONF_API_KEY: "1234567890"},
)
await hass.async_block_till_done()
assert result["type"] is FlowResultType.ABORT
assert result["reason"] == "reauth_successful"
@ -270,6 +272,7 @@ async def test_flow_reauth_no_username_or_device(
get_me: dict[str, Any],
p_error: str,
mock_client: MagicMock,
get_data: tuple[SensiboData, dict[str, Any], dict[str, Any]],
) -> None:
"""Test reauth flow with errors from api."""
entry = MockConfigEntry(
@ -285,33 +288,27 @@ async def test_flow_reauth_no_username_or_device(
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "reauth_confirm"
with (
patch(
"homeassistant.components.sensibo.util.SensiboClient.async_get_devices",
return_value=get_devices,
),
patch(
"homeassistant.components.sensibo.util.SensiboClient.async_get_me",
return_value=get_me,
),
):
result = await hass.config_entries.flow.async_configure(
result["flow_id"],
user_input={
CONF_API_KEY: "1234567890",
},
)
await hass.async_block_till_done()
mock_client.async_get_devices.return_value = get_devices
mock_client.async_get_me.return_value = get_me
result = await hass.config_entries.flow.async_configure(
result["flow_id"],
user_input={
CONF_API_KEY: "1234567890",
},
)
assert result["step_id"] == "reauth_confirm"
assert result["type"] is FlowResultType.FORM
assert result["errors"] == {"base": p_error}
mock_client.async_get_devices.return_value = get_data[2]
mock_client.async_get_me.return_value = get_data[1]
result = await hass.config_entries.flow.async_configure(
result["flow_id"],
{CONF_API_KEY: "1234567890"},
)
await hass.async_block_till_done()
assert result["type"] is FlowResultType.ABORT
assert result["reason"] == "reauth_successful"
@ -337,7 +334,6 @@ async def test_reconfigure_flow(hass: HomeAssistant, mock_client: MagicMock) ->
result["flow_id"],
{CONF_API_KEY: "1234567890"},
)
await hass.async_block_till_done()
assert result["type"] is FlowResultType.ABORT
assert result["reason"] == "reconfigure_successful"
@ -352,7 +348,10 @@ async def test_reconfigure_flow(hass: HomeAssistant, mock_client: MagicMock) ->
],
)
async def test_reconfigure_flow_error(
hass: HomeAssistant, sideeffect: Exception, p_error: str, mock_client: MagicMock
hass: HomeAssistant,
sideeffect: Exception,
p_error: str,
mock_client: MagicMock,
) -> None:
"""Test a reconfigure flow with error."""
entry = MockConfigEntry(
@ -365,25 +364,23 @@ async def test_reconfigure_flow_error(
result = await entry.start_reconfigure_flow(hass)
with patch(
"homeassistant.components.sensibo.util.SensiboClient.async_get_devices",
side_effect=sideeffect,
):
result = await hass.config_entries.flow.async_configure(
result["flow_id"],
{CONF_API_KEY: "1234567890"},
)
await hass.async_block_till_done()
assert result["step_id"] == "reconfigure"
assert result["type"] is FlowResultType.FORM
assert result["errors"] == {"base": p_error}
mock_client.async_get_devices.side_effect = sideeffect
result = await hass.config_entries.flow.async_configure(
result["flow_id"],
{CONF_API_KEY: "1234567890"},
)
assert result["step_id"] == "reconfigure"
assert result["type"] is FlowResultType.FORM
assert result["errors"] == {"base": p_error}
mock_client.async_get_devices.side_effect = None
result = await hass.config_entries.flow.async_configure(
result["flow_id"],
{CONF_API_KEY: "1234567890"},
)
await hass.async_block_till_done()
assert result["type"] is FlowResultType.ABORT
assert result["reason"] == "reconfigure_successful"
@ -416,6 +413,7 @@ async def test_flow_reconfigure_no_username_or_device(
get_me: dict[str, Any],
p_error: str,
mock_client: MagicMock,
get_data: tuple[SensiboData, dict[str, Any], dict[str, Any]],
) -> None:
"""Test reconfigure flow with errors from api."""
entry = MockConfigEntry(
@ -431,33 +429,27 @@ async def test_flow_reconfigure_no_username_or_device(
assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "reconfigure"
with (
patch(
"homeassistant.components.sensibo.util.SensiboClient.async_get_devices",
return_value=get_devices,
),
patch(
"homeassistant.components.sensibo.util.SensiboClient.async_get_me",
return_value=get_me,
),
):
result = await hass.config_entries.flow.async_configure(
result["flow_id"],
user_input={
CONF_API_KEY: "1234567890",
},
)
await hass.async_block_till_done()
mock_client.async_get_devices.return_value = get_devices
mock_client.async_get_me.return_value = get_me
result = await hass.config_entries.flow.async_configure(
result["flow_id"],
user_input={
CONF_API_KEY: "1234567890",
},
)
assert result["step_id"] == "reconfigure"
assert result["type"] is FlowResultType.FORM
assert result["errors"] == {"base": p_error}
mock_client.async_get_devices.return_value = get_data[2]
mock_client.async_get_me.return_value = get_data[1]
result = await hass.config_entries.flow.async_configure(
result["flow_id"],
{CONF_API_KEY: "1234567890"},
)
await hass.async_block_till_done()
assert result["type"] is FlowResultType.ABORT
assert result["reason"] == "reconfigure_successful"

View File

@ -9,7 +9,6 @@ from unittest.mock import MagicMock
from freezegun.api import FrozenDateTimeFactory
from pysensibo.exceptions import AuthenticationError, SensiboError
from pysensibo.model import SensiboData
import pytest
from homeassistant.components.climate import HVACMode
from homeassistant.components.sensibo.const import DOMAIN
@ -23,9 +22,8 @@ from tests.common import MockConfigEntry, async_fire_time_changed
async def test_coordinator(
hass: HomeAssistant,
monkeypatch: pytest.MonkeyPatch,
mock_client: MagicMock,
get_data: tuple[SensiboData, dict[str, Any]],
get_data: tuple[SensiboData, dict[str, Any], dict[str, Any]],
freezer: FrozenDateTimeFactory,
) -> None:
"""Test the Sensibo coordinator with errors."""
@ -39,8 +37,10 @@ async def test_coordinator(
config_entry.add_to_hass(hass)
monkeypatch.setattr(get_data[0].parsed["ABC999111"], "hvac_mode", "heat")
monkeypatch.setattr(get_data[0].parsed["ABC999111"], "device_on", True)
mock_client.async_get_devices_data.return_value.parsed[
"ABC999111"
].hvac_mode = "heat"
mock_client.async_get_devices_data.return_value.parsed["ABC999111"].device_on = True
mock_data = mock_client.async_get_devices_data
mock_data.return_value = get_data[0]
@ -70,9 +70,6 @@ async def test_coordinator(
assert state.state == STATE_UNAVAILABLE
mock_data.reset_mock()
monkeypatch.setattr(get_data[0].parsed["ABC999111"], "hvac_mode", "heat")
monkeypatch.setattr(get_data[0].parsed["ABC999111"], "device_on", True)
mock_data.return_value = get_data[0]
mock_data.side_effect = None
freezer.tick(timedelta(minutes=1))

View File

@ -2,7 +2,7 @@
from __future__ import annotations
from unittest.mock import MagicMock, patch
from unittest.mock import MagicMock
from homeassistant.components.sensibo.const import DOMAIN
from homeassistant.components.sensibo.util import NoUsernameError
@ -71,12 +71,10 @@ async def test_migrate_entry_fails(hass: HomeAssistant, mock_client: MagicMock)
)
entry.add_to_hass(hass)
with patch(
"homeassistant.components.sensibo.util.SensiboClient.async_get_me",
side_effect=NoUsernameError("No username returned"),
):
await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
mock_client.async_get_me.side_effect = NoUsernameError("No username returned")
await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
assert entry.state is ConfigEntryState.MIGRATION_ERROR
assert entry.version == 1

View File

@ -3,11 +3,9 @@
from __future__ import annotations
from datetime import timedelta
from typing import Any
from unittest.mock import MagicMock
from freezegun.api import FrozenDateTimeFactory
from pysensibo.model import SensiboData
import pytest
from syrupy.assertion import SnapshotAssertion
@ -33,8 +31,7 @@ from tests.common import async_fire_time_changed, snapshot_platform
async def test_number(
hass: HomeAssistant,
load_int: ConfigEntry,
monkeypatch: pytest.MonkeyPatch,
get_data: tuple[SensiboData, dict[str, Any]],
mock_client: MagicMock,
entity_registry: er.EntityRegistry,
snapshot: SnapshotAssertion,
freezer: FrozenDateTimeFactory,
@ -43,7 +40,9 @@ async def test_number(
await snapshot_platform(hass, entity_registry, snapshot, load_int.entry_id)
monkeypatch.setattr(get_data[0].parsed["ABC999111"], "calibration_temp", 0.2)
mock_client.async_get_devices_data.return_value.parsed[
"ABC999111"
].calibration_temp = 0.2
freezer.tick(timedelta(minutes=5))
async_fire_time_changed(hass)

View File

@ -3,11 +3,9 @@
from __future__ import annotations
from datetime import timedelta
from typing import Any
from unittest.mock import MagicMock
from freezegun.api import FrozenDateTimeFactory
from pysensibo.model import SensiboData
import pytest
from syrupy.assertion import SnapshotAssertion
@ -32,8 +30,7 @@ from tests.common import async_fire_time_changed, snapshot_platform
async def test_select(
hass: HomeAssistant,
load_int: ConfigEntry,
monkeypatch: pytest.MonkeyPatch,
get_data: tuple[SensiboData, dict[str, Any]],
mock_client: MagicMock,
entity_registry: er.EntityRegistry,
snapshot: SnapshotAssertion,
freezer: FrozenDateTimeFactory,
@ -42,9 +39,9 @@ async def test_select(
await snapshot_platform(hass, entity_registry, snapshot, load_int.entry_id)
monkeypatch.setattr(
get_data[0].parsed["ABC999111"], "horizontal_swing_mode", "fixedleft"
)
mock_client.async_get_devices_data.return_value.parsed[
"ABC999111"
].horizontal_swing_mode = "fixedleft"
freezer.tick(timedelta(minutes=5))
async_fire_time_changed(hass)
@ -57,24 +54,20 @@ async def test_select(
async def test_select_set_option(
hass: HomeAssistant,
load_int: ConfigEntry,
monkeypatch: pytest.MonkeyPatch,
mock_client: MagicMock,
get_data: tuple[SensiboData, dict[str, Any]],
freezer: FrozenDateTimeFactory,
) -> None:
"""Test the Sensibo select service."""
monkeypatch.setattr(
get_data[0].parsed["ABC999111"],
"active_features",
[
"timestamp",
"on",
"mode",
"targetTemperature",
"light",
],
)
mock_client.async_get_devices_data.return_value.parsed[
"ABC999111"
].active_features = [
"timestamp",
"on",
"mode",
"targetTemperature",
"light",
]
freezer.tick(timedelta(minutes=5))
async_fire_time_changed(hass)
@ -100,18 +93,16 @@ async def test_select_set_option(
state = hass.states.get("select.hallway_horizontal_swing")
assert state.state == "stopped"
monkeypatch.setattr(
get_data[0].parsed["ABC999111"],
"active_features",
[
"timestamp",
"on",
"mode",
"targetTemperature",
"horizontalSwing",
"light",
],
)
mock_client.async_get_devices_data.return_value.parsed[
"ABC999111"
].active_features = [
"timestamp",
"on",
"mode",
"targetTemperature",
"horizontalSwing",
"light",
]
freezer.tick(timedelta(minutes=5))
async_fire_time_changed(hass)

View File

@ -3,10 +3,10 @@
from __future__ import annotations
from datetime import timedelta
from typing import Any
from unittest.mock import MagicMock
from freezegun.api import FrozenDateTimeFactory
from pysensibo.model import PureAQI, SensiboData
from pysensibo.model import PureAQI
import pytest
from syrupy.assertion import SnapshotAssertion
@ -26,8 +26,7 @@ from tests.common import async_fire_time_changed, snapshot_platform
async def test_sensor(
hass: HomeAssistant,
load_int: ConfigEntry,
monkeypatch: pytest.MonkeyPatch,
get_data: tuple[SensiboData, dict[str, Any]],
mock_client: MagicMock,
entity_registry: er.EntityRegistry,
snapshot: SnapshotAssertion,
freezer: FrozenDateTimeFactory,
@ -36,7 +35,9 @@ async def test_sensor(
await snapshot_platform(hass, entity_registry, snapshot, load_int.entry_id)
monkeypatch.setattr(get_data[0].parsed["AAZZAAZZ"], "pm25_pure", PureAQI(2))
mock_client.async_get_devices_data.return_value.parsed[
"AAZZAAZZ"
].pm25_pure = PureAQI(2)
freezer.tick(timedelta(minutes=5))
async_fire_time_changed(hass)

View File

@ -3,11 +3,9 @@
from __future__ import annotations
from datetime import timedelta
from typing import Any
from unittest.mock import MagicMock
from freezegun.api import FrozenDateTimeFactory
from pysensibo.model import SensiboData
import pytest
from syrupy.assertion import SnapshotAssertion
@ -46,9 +44,7 @@ async def test_switch(
async def test_switch_timer(
hass: HomeAssistant,
load_int: ConfigEntry,
monkeypatch: pytest.MonkeyPatch,
mock_client: MagicMock,
get_data: tuple[SensiboData, dict[str, Any]],
freezer: FrozenDateTimeFactory,
) -> None:
"""Test the Sensibo switch timer."""
@ -72,9 +68,13 @@ async def test_switch_timer(
blocking=True,
)
monkeypatch.setattr(get_data[0].parsed["ABC999111"], "timer_on", True)
monkeypatch.setattr(get_data[0].parsed["ABC999111"], "timer_id", "SzTGE4oZ4D")
monkeypatch.setattr(get_data[0].parsed["ABC999111"], "timer_state_on", False)
mock_client.async_get_devices_data.return_value.parsed["ABC999111"].timer_on = True
mock_client.async_get_devices_data.return_value.parsed[
"ABC999111"
].timer_id = "SzTGE4oZ4D"
mock_client.async_get_devices_data.return_value.parsed[
"ABC999111"
].timer_state_on = False
freezer.tick(timedelta(minutes=5))
async_fire_time_changed(hass)
@ -99,7 +99,7 @@ async def test_switch_timer(
blocking=True,
)
monkeypatch.setattr(get_data[0].parsed["ABC999111"], "timer_on", False)
mock_client.async_get_devices_data.return_value.parsed["ABC999111"].timer_on = False
freezer.tick(timedelta(minutes=5))
async_fire_time_changed(hass)
@ -112,9 +112,7 @@ async def test_switch_timer(
async def test_switch_pure_boost(
hass: HomeAssistant,
load_int: ConfigEntry,
monkeypatch: pytest.MonkeyPatch,
mock_client: MagicMock,
get_data: tuple[SensiboData, dict[str, Any]],
freezer: FrozenDateTimeFactory,
) -> None:
"""Test the Sensibo switch pure boost."""
@ -133,10 +131,12 @@ async def test_switch_pure_boost(
blocking=True,
)
monkeypatch.setattr(get_data[0].parsed["AAZZAAZZ"], "pure_boost_enabled", True)
monkeypatch.setattr(
get_data[0].parsed["AAZZAAZZ"], "pure_measure_integration", None
)
mock_client.async_get_devices_data.return_value.parsed[
"AAZZAAZZ"
].pure_boost_enabled = True
mock_client.async_get_devices_data.return_value.parsed[
"AAZZAAZZ"
].pure_measure_integration = None
freezer.tick(timedelta(minutes=5))
async_fire_time_changed(hass)
@ -154,7 +154,9 @@ async def test_switch_pure_boost(
blocking=True,
)
monkeypatch.setattr(get_data[0].parsed["AAZZAAZZ"], "pure_boost_enabled", False)
mock_client.async_get_devices_data.return_value.parsed[
"AAZZAAZZ"
].pure_boost_enabled = False
freezer.tick(timedelta(minutes=5))
async_fire_time_changed(hass)
@ -203,9 +205,7 @@ async def test_switch_command_failure(
async def test_switch_climate_react(
hass: HomeAssistant,
load_int: ConfigEntry,
monkeypatch: pytest.MonkeyPatch,
mock_client: MagicMock,
get_data: tuple[SensiboData, dict[str, Any]],
freezer: FrozenDateTimeFactory,
) -> None:
"""Test the Sensibo switch for climate react."""
@ -224,7 +224,7 @@ async def test_switch_climate_react(
blocking=True,
)
monkeypatch.setattr(get_data[0].parsed["ABC999111"], "smart_on", True)
mock_client.async_get_devices_data.return_value.parsed["ABC999111"].smart_on = True
freezer.tick(timedelta(minutes=5))
async_fire_time_changed(hass)
@ -242,7 +242,7 @@ async def test_switch_climate_react(
blocking=True,
)
monkeypatch.setattr(get_data[0].parsed["ABC999111"], "smart_on", False)
mock_client.async_get_devices_data.return_value.parsed["ABC999111"].smart_on = False
freezer.tick(timedelta(minutes=5))
async_fire_time_changed(hass)
@ -255,13 +255,14 @@ async def test_switch_climate_react(
async def test_switch_climate_react_no_data(
hass: HomeAssistant,
load_int: ConfigEntry,
monkeypatch: pytest.MonkeyPatch,
get_data: tuple[SensiboData, dict[str, Any]],
mock_client: MagicMock,
freezer: FrozenDateTimeFactory,
) -> None:
"""Test the Sensibo switch for climate react with no data."""
monkeypatch.setattr(get_data[0].parsed["ABC999111"], "smart_type", None)
mock_client.async_get_devices_data.return_value.parsed[
"ABC999111"
].smart_type = None
freezer.tick(timedelta(minutes=5))
async_fire_time_changed(hass)

View File

@ -3,10 +3,9 @@
from __future__ import annotations
from datetime import timedelta
from typing import Any
from unittest.mock import MagicMock
from freezegun.api import FrozenDateTimeFactory
from pysensibo.model import SensiboData
import pytest
from syrupy.assertion import SnapshotAssertion
@ -26,8 +25,7 @@ from tests.common import async_fire_time_changed, snapshot_platform
async def test_update(
hass: HomeAssistant,
load_int: ConfigEntry,
monkeypatch: pytest.MonkeyPatch,
get_data: tuple[SensiboData, dict[str, Any]],
mock_client: MagicMock,
entity_registry: er.EntityRegistry,
snapshot: SnapshotAssertion,
freezer: FrozenDateTimeFactory,
@ -36,7 +34,9 @@ async def test_update(
await snapshot_platform(hass, entity_registry, snapshot, load_int.entry_id)
monkeypatch.setattr(get_data[0].parsed["ABC999111"], "fw_ver", "SKY30048")
mock_client.async_get_devices_data.return_value.parsed[
"ABC999111"
].fw_ver = "SKY30048"
freezer.tick(timedelta(minutes=5))
async_fire_time_changed(hass)