Sensibo test data adjustment from late review (#71482)

* Sensibo test data

* Separate pytest fixture for json load

* Scope to session
This commit is contained in:
G Johansson 2022-05-11 19:36:30 +02:00 committed by GitHub
parent 554f079b02
commit 49491bcda5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 688 additions and 102 deletions

View File

@ -1,8 +1,12 @@
"""Fixtures for the Sensibo integration."""
from __future__ import annotations
import json
from typing import Any
from unittest.mock import patch
from pysensibo import SensiboClient
from pysensibo.model import SensiboData
import pytest
from homeassistant.components.sensibo.const import DOMAIN
@ -10,13 +14,13 @@ from homeassistant.config_entries import SOURCE_USER
from homeassistant.core import HomeAssistant
from . import ENTRY_CONFIG
from .response import DATA_FROM_API
from tests.common import MockConfigEntry
from tests.common import MockConfigEntry, load_fixture
from tests.test_util.aiohttp import AiohttpClientMocker
@pytest.fixture
async def load_int(hass: HomeAssistant) -> MockConfigEntry:
async def load_int(hass: HomeAssistant, get_data: SensiboData) -> MockConfigEntry:
"""Set up the Sensibo integration in Home Assistant."""
config_entry = MockConfigEntry(
domain=DOMAIN,
@ -31,7 +35,7 @@ async def load_int(hass: HomeAssistant) -> MockConfigEntry:
with patch(
"homeassistant.components.sensibo.coordinator.SensiboClient.async_get_devices_data",
return_value=DATA_FROM_API,
return_value=get_data,
), patch(
"homeassistant.components.sensibo.util.SensiboClient.async_get_devices",
return_value={"result": [{"id": "xyzxyz"}, {"id": "abcabc"}]},
@ -43,3 +47,25 @@ async def load_int(hass: HomeAssistant) -> MockConfigEntry:
await hass.async_block_till_done()
return config_entry
@pytest.fixture(name="get_data")
async def get_data_from_library(
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker, load_json: dict[str, Any]
) -> SensiboData:
"""Retrieve data from upstream Sensibo library."""
client = SensiboClient("123467890", aioclient_mock.create_session(hass.loop))
with patch("pysensibo.SensiboClient.async_get_devices", return_value=load_json):
output = await client.async_get_devices_data()
await client._session.close() # pylint: disable=protected-access
return output
@pytest.fixture(name="load_json", scope="session")
def load_json_from_fixture() -> SensiboData:
"""Load fixture with json data and return."""
data_fixture = load_fixture("data.json", "sensibo")
json_data: dict[str, Any] = json.loads(data_fixture)
return json_data

View File

@ -0,0 +1,551 @@
{
"status": "success",
"result": [
{
"isGeofenceOnEnterEnabledForThisUser": false,
"isClimateReactGeofenceOnEnterEnabledForThisUser": false,
"isMotionGeofenceOnEnterEnabled": false,
"isOwner": true,
"id": "ABC999111",
"qrId": "AAAAAAAAAA",
"temperatureUnit": "C",
"room": {
"uid": "99TT99TT",
"name": "Hallway",
"icon": "Lounge"
},
"acState": {
"timestamp": {
"time": "2022-04-30T11:23:30.019722Z",
"secondsAgo": -1
},
"on": true,
"mode": "heat",
"fanLevel": "high",
"targetTemperature": 25,
"swing": "stopped",
"horizontalSwing": "stopped",
"light": "on"
},
"lastStateChange": {
"time": "2022-04-30T11:21:30Z",
"secondsAgo": 119
},
"lastStateChangeToOn": {
"time": "2022-04-30T11:20:28Z",
"secondsAgo": 181
},
"lastStateChangeToOff": {
"time": "2022-04-30T11:21:30Z",
"secondsAgo": 119
},
"location": {
"id": "ZZZZZZZZZZZZ",
"name": "Home",
"latLon": [58.9806976, 20.5864297],
"address": ["Sealand 99", "Some county"],
"country": "United Country",
"createTime": {
"time": "2020-03-21T15:44:15Z",
"secondsAgo": 66543240
}
},
"connectionStatus": {
"isAlive": true,
"lastSeen": {
"time": "2022-04-30T11:22:57.894846Z",
"secondsAgo": 32
}
},
"firmwareVersion": "SKY30046",
"firmwareType": "esp8266ex",
"productModel": "skyv2",
"configGroup": "stable",
"currentlyAvailableFirmwareVersion": "SKY30046",
"cleanFiltersNotificationEnabled": false,
"shouldShowFilterCleaningNotification": false,
"isGeofenceOnExitEnabled": false,
"isClimateReactGeofenceOnExitEnabled": false,
"isMotionGeofenceOnExitEnabled": false,
"serial": "1234567890",
"sensorsCalibration": {
"temperature": 0.1,
"humidity": 0.0
},
"motionSensors": [
{
"configGroup": "stable",
"connectionStatus": {
"isAlive": true,
"lastSeen": {
"secondsAgo": 86,
"time": "2022-01-01T18:59:48.665878Z"
}
},
"firmwareType": "nrf52",
"firmwareVersion": "V17",
"id": "AABBCC",
"isMainSensor": true,
"macAddress": "00:04:00:B6:00:00",
"measurements": {
"batteryVoltage": 3000,
"humidity": 57,
"motion": true,
"rssi": -72,
"temperature": 23.9,
"time": {
"secondsAgo": 86,
"time": "2022-01-01T18:59:48.665878Z"
}
},
"parentDeviceUid": "ABC999111",
"productModel": "motion_sensor",
"qrId": "AAZZAAZZ",
"serial": "12123434"
}
],
"tags": [],
"timer": null,
"schedules": [
{
"id": "11",
"isEnabled": false,
"acState": {
"on": false,
"targetTemperature": 21,
"temperatureUnit": "C",
"mode": "heat",
"fanLevel": "low",
"swing": "stopped",
"extra": {
"scheduler": {
"climate_react": null,
"motion": null,
"on": false,
"climate_react_settings": null,
"pure_boost": null
}
},
"horizontalSwing": "stopped",
"light": "on"
},
"createTime": "2022-04-17T15:41:05",
"createTimeSecondsAgo": 1107745,
"recurringDays": ["Wednesday", "Thursday"],
"targetTimeLocal": "17:40",
"timezone": "Europe/Stockholm",
"podUid": "ABC999111",
"nextTime": "2022-05-04T15:40:00",
"nextTimeSecondsFromNow": 360989
}
],
"motionConfig": {
"enabled": true,
"onEnterACChange": false,
"onEnterACState": null,
"onEnterCRChange": true,
"onExitACChange": true,
"onExitACState": null,
"onExitCRChange": true,
"onExitDelayMinutes": 20
},
"filtersCleaning": {
"acOnSecondsSinceLastFiltersClean": 667991,
"filtersCleanSecondsThreshold": 1080000,
"lastFiltersCleanTime": {
"time": "2022-03-12T15:24:26Z",
"secondsAgo": 4219143
},
"shouldCleanFilters": false
},
"serviceSubscriptions": [],
"roomIsOccupied": true,
"mainMeasurementsSensor": {
"configGroup": "stable",
"connectionStatus": {
"isAlive": true,
"lastSeen": {
"secondsAgo": 86,
"time": "2022-01-01T18:59:48.665878Z"
}
},
"firmwareType": "nrf52",
"firmwareVersion": "V17",
"id": "AABBCC",
"isMainSensor": true,
"macAddress": "00:04:00:B6:00:00",
"measurements": {
"batteryVoltage": 3000,
"humidity": 32.9,
"motion": false,
"rssi": -72,
"temperature": 21.2,
"time": {
"secondsAgo": 86,
"time": "2022-01-01T18:59:48.665878Z"
}
},
"parentDeviceUid": "ABC999111",
"productModel": "motion_sensor",
"qrId": "AAZZAAZZ",
"serial": "12123434"
},
"pureBoostConfig": null,
"warrantyEligible": "no",
"warrantyEligibleUntil": {
"time": "2020-04-18T15:43:08Z",
"secondsAgo": 64093221
},
"features": ["softShowPlus", "optimusTrial"],
"runningHealthcheck": null,
"lastHealthcheck": null,
"lastACStateChange": {
"id": "11",
"time": {
"time": "2022-04-30T11:21:29Z",
"secondsAgo": 120
},
"status": "Success",
"acState": {
"timestamp": {
"time": "2022-04-30T11:23:30.062645Z",
"secondsAgo": -1
},
"on": false,
"mode": "fan",
"fanLevel": "high",
"swing": "stopped",
"horizontalSwing": "stopped",
"light": "on"
},
"resultingAcState": {
"timestamp": {
"time": "2022-04-30T11:23:30.062688Z",
"secondsAgo": -1
},
"on": false,
"mode": "fan",
"fanLevel": "high",
"swing": "stopped",
"horizontalSwing": "stopped",
"light": "on"
},
"changedProperties": ["on"],
"reason": "UserRequest",
"failureReason": null,
"resolveTime": {
"time": "2022-04-30T11:21:30Z",
"secondsAgo": 119
},
"causedByScheduleId": null,
"causedByScheduleType": null
},
"homekitSupported": false,
"remoteCapabilities": {
"modes": {
"cool": {
"temperatures": {
"F": {
"isNative": false,
"values": [64, 66, 68]
},
"C": {
"isNative": true,
"values": [18, 19, 20]
}
},
"fanLevels": ["quiet", "low", "medium"],
"swing": ["stopped", "fixedTop", "fixedMiddleTop"],
"horizontalSwing": ["stopped", "fixedLeft", "fixedCenterLeft"],
"light": ["on", "off"]
},
"heat": {
"temperatures": {
"F": {
"isNative": false,
"values": [63, 64, 66]
},
"C": {
"isNative": true,
"values": [17, 18, 19, 20]
}
},
"fanLevels": ["quiet", "low", "medium"],
"swing": ["stopped", "fixedTop", "fixedMiddleTop"],
"horizontalSwing": ["stopped", "fixedLeft", "fixedCenterLeft"],
"light": ["on", "off"]
},
"dry": {
"temperatures": {
"F": {
"isNative": false,
"values": [64, 66, 68]
},
"C": {
"isNative": true,
"values": [18, 19, 20]
}
},
"swing": ["stopped", "fixedTop", "fixedMiddleTop"],
"horizontalSwing": ["stopped", "fixedLeft", "fixedCenterLeft"],
"light": ["on", "off"]
},
"auto": {
"temperatures": {
"F": {
"isNative": false,
"values": [64, 66, 68]
},
"C": {
"isNative": true,
"values": [18, 19, 20, 21]
}
},
"fanLevels": ["quiet", "low", "medium"],
"swing": ["stopped", "fixedTop", "fixedMiddleTop"],
"horizontalSwing": ["stopped", "fixedLeft", "fixedCenterLeft"],
"light": ["on", "off"]
},
"fan": {
"temperatures": {},
"fanLevels": ["quiet", "low", "medium"],
"swing": ["stopped", "fixedTop", "fixedMiddleTop"],
"horizontalSwing": ["stopped", "fixedLeft", "fixedCenterLeft"],
"light": ["on", "off"]
}
}
},
"remote": {
"toggle": false,
"window": false
},
"remoteFlavor": "Curious Sea Cucumber",
"remoteAlternatives": ["_mitsubishi2_night_heat"],
"smartMode": {
"enabled": false,
"type": "temperature",
"deviceUid": "ABC999111",
"lowTemperatureThreshold": 0.0,
"highTemperatureThreshold": 27.5,
"lowTemperatureState": {
"on": true,
"targetTemperature": 21,
"temperatureUnit": "C",
"mode": "heat",
"fanLevel": "low",
"swing": "stopped",
"horizontalSwing": "stopped",
"light": "on"
},
"highTemperatureState": {
"on": true,
"targetTemperature": 21,
"temperatureUnit": "C",
"mode": "cool",
"fanLevel": "high",
"swing": "stopped",
"horizontalSwing": "stopped",
"light": "on"
},
"lowTemperatureWebhook": null,
"highTemperatureWebhook": null
},
"measurements": {
"time": {
"time": "2022-04-30T11:22:57.894846Z",
"secondsAgo": 32
},
"temperature": 21.2,
"humidity": 32.9,
"motion": true,
"roomIsOccupied": true,
"feelsLike": 21.2,
"rssi": -45
},
"accessPoint": {
"ssid": "Sensibo-1234567890",
"password": null
},
"macAddress": "00:02:00:B6:00:00",
"autoOffMinutes": null,
"autoOffEnabled": false,
"antiMoldTimer": null,
"antiMoldConfig": null
},
{
"isGeofenceOnEnterEnabledForThisUser": false,
"isClimateReactGeofenceOnEnterEnabledForThisUser": false,
"isMotionGeofenceOnEnterEnabled": false,
"isOwner": true,
"id": "AAZZAAZZ",
"qrId": "AAAAAAAABB",
"temperatureUnit": "C",
"room": {
"uid": "99TT99ZZ",
"name": "Kitchen",
"icon": "Diningroom"
},
"acState": {
"timestamp": {
"time": "2022-04-30T11:23:30.067312Z",
"secondsAgo": -1
},
"on": false,
"mode": "fan",
"fanLevel": "low",
"light": "on"
},
"lastStateChange": {
"time": "2022-04-30T11:21:41Z",
"secondsAgo": 108
},
"lastStateChangeToOn": {
"time": "2022-04-30T09:43:26Z",
"secondsAgo": 6003
},
"lastStateChangeToOff": {
"time": "2022-04-30T11:21:37Z",
"secondsAgo": 112
},
"location": {
"id": "ZZZZZZZZZZZZ",
"name": "Home",
"latLon": [58.9806976, 20.5864297],
"address": ["Sealand 99", "Some county"],
"country": "United Country",
"createTime": {
"time": "2020-03-21T15:44:15Z",
"secondsAgo": 66543240
}
},
"connectionStatus": {
"isAlive": true,
"lastSeen": {
"time": "2022-04-30T11:23:20.642798Z",
"secondsAgo": 9
}
},
"firmwareVersion": "PUR00111",
"firmwareType": "pure-esp32",
"productModel": "pure",
"configGroup": "stable",
"currentlyAvailableFirmwareVersion": "PUR00111",
"cleanFiltersNotificationEnabled": false,
"shouldShowFilterCleaningNotification": false,
"isGeofenceOnExitEnabled": false,
"isClimateReactGeofenceOnExitEnabled": false,
"isMotionGeofenceOnExitEnabled": false,
"serial": "0987654321",
"sensorsCalibration": {
"temperature": 0.0,
"humidity": 0.0
},
"motionSensors": [],
"tags": [],
"timer": null,
"schedules": [],
"motionConfig": null,
"filtersCleaning": {
"acOnSecondsSinceLastFiltersClean": 415560,
"filtersCleanSecondsThreshold": 14256000,
"lastFiltersCleanTime": {
"time": "2022-04-23T15:58:45Z",
"secondsAgo": 588284
},
"shouldCleanFilters": false
},
"serviceSubscriptions": [],
"roomIsOccupied": null,
"mainMeasurementsSensor": null,
"pureBoostConfig": {
"enabled": false,
"sensitivity": "N",
"measurements_integration": true,
"ac_integration": false,
"geo_integration": false,
"prime_integration": false
},
"warrantyEligible": "no",
"warrantyEligibleUntil": {
"time": "2022-04-10T09:58:58Z",
"secondsAgo": 1733071
},
"features": ["optimusTrial", "softShowPlus"],
"runningHealthcheck": null,
"lastHealthcheck": null,
"lastACStateChange": {
"id": "AA22",
"time": {
"time": "2022-04-30T11:21:37Z",
"secondsAgo": 112
},
"status": "Success",
"acState": {
"timestamp": {
"time": "2022-04-30T11:23:30.090144Z",
"secondsAgo": -1
},
"on": false,
"mode": "fan",
"fanLevel": "low",
"light": "on"
},
"resultingAcState": {
"timestamp": {
"time": "2022-04-30T11:23:30.090185Z",
"secondsAgo": -1
},
"on": false,
"mode": "fan",
"fanLevel": "low",
"light": "on"
},
"changedProperties": ["on"],
"reason": "UserRequest",
"failureReason": null,
"resolveTime": {
"time": "2022-04-30T11:21:37Z",
"secondsAgo": 112
},
"causedByScheduleId": null,
"causedByScheduleType": null
},
"homekitSupported": true,
"remoteCapabilities": {
"modes": {
"fan": {
"temperatures": {},
"fanLevels": ["low", "high"],
"light": ["on", "dim", "off"]
}
}
},
"remote": {
"toggle": false,
"window": false
},
"remoteFlavor": "Eccentric Eagle",
"remoteAlternatives": [],
"smartMode": null,
"measurements": {
"time": {
"time": "2022-04-30T11:23:20.642798Z",
"secondsAgo": 9
},
"rssi": -58,
"pm25": 1,
"motion": false,
"roomIsOccupied": null
},
"accessPoint": {
"ssid": "Sensibo-09876",
"password": null
},
"macAddress": "00:01:00:01:00:01",
"autoOffMinutes": null,
"autoOffEnabled": false,
"antiMoldTimer": null,
"antiMoldConfig": null
}
]
}

View File

@ -4,19 +4,21 @@ from __future__ import annotations
from datetime import timedelta
from unittest.mock import patch
from pysensibo.model import SensiboData
from pytest import MonkeyPatch
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.util import dt
from .response import DATA_FROM_API
from tests.common import async_fire_time_changed
async def test_binary_sensor(
hass: HomeAssistant, load_int: ConfigEntry, monkeypatch: MonkeyPatch
hass: HomeAssistant,
load_int: ConfigEntry,
monkeypatch: MonkeyPatch,
get_data: SensiboData,
) -> None:
"""Test the Sensibo binary sensor."""
@ -30,15 +32,15 @@ async def test_binary_sensor(
assert state4.state == "on"
monkeypatch.setattr(
DATA_FROM_API.parsed["ABC999111"].motion_sensors["AABBCC"], "alive", False
get_data.parsed["ABC999111"].motion_sensors["AABBCC"], "alive", False
)
monkeypatch.setattr(
DATA_FROM_API.parsed["ABC999111"].motion_sensors["AABBCC"], "motion", False
get_data.parsed["ABC999111"].motion_sensors["AABBCC"], "motion", False
)
with patch(
"homeassistant.components.sensibo.coordinator.SensiboClient.async_get_devices_data",
return_value=DATA_FROM_API,
return_value=get_data,
):
async_fire_time_changed(
hass,

View File

@ -4,6 +4,7 @@ from __future__ import annotations
from datetime import timedelta
from unittest.mock import patch
from pysensibo.model import SensiboData
import pytest
from voluptuous import MultipleInvalid
@ -33,12 +34,12 @@ from homeassistant.core import HomeAssistant
from homeassistant.exceptions import HomeAssistantError
from homeassistant.util import dt
from .response import DATA_FROM_API
from tests.common import async_fire_time_changed
async def test_climate(hass: HomeAssistant, load_int: ConfigEntry) -> None:
async def test_climate(
hass: HomeAssistant, load_int: ConfigEntry, get_data: SensiboData
) -> None:
"""Test the Sensibo climate."""
state1 = hass.states.get("climate.hallway")
@ -54,7 +55,7 @@ async def test_climate(hass: HomeAssistant, load_int: ConfigEntry) -> None:
"fan_only",
"off",
],
"min_temp": 18,
"min_temp": 17,
"max_temp": 20,
"target_temp_step": 1,
"fan_modes": ["quiet", "low", "medium"],
@ -63,9 +64,9 @@ async def test_climate(hass: HomeAssistant, load_int: ConfigEntry) -> None:
"fixedTop",
"fixedMiddleTop",
],
"current_temperature": 22.4,
"current_temperature": 21.2,
"temperature": 25,
"current_humidity": 38,
"current_humidity": 32.9,
"fan_mode": "high",
"swing_mode": "stopped",
"friendly_name": "Hallway",
@ -76,7 +77,10 @@ async def test_climate(hass: HomeAssistant, load_int: ConfigEntry) -> None:
async def test_climate_fan(
hass: HomeAssistant, load_int: ConfigEntry, monkeypatch: pytest.MonkeyPatch
hass: HomeAssistant,
load_int: ConfigEntry,
monkeypatch: pytest.MonkeyPatch,
get_data: SensiboData,
) -> None:
"""Test the Sensibo climate fan service."""
@ -99,7 +103,7 @@ async def test_climate_fan(
assert state2.attributes["fan_mode"] == "low"
monkeypatch.setattr(
DATA_FROM_API.parsed["ABC999111"],
get_data.parsed["ABC999111"],
"active_features",
[
"timestamp",
@ -113,7 +117,7 @@ async def test_climate_fan(
)
with patch(
"homeassistant.components.sensibo.coordinator.SensiboClient.async_get_devices_data",
return_value=DATA_FROM_API,
return_value=get_data,
):
async_fire_time_changed(
hass,
@ -138,7 +142,10 @@ async def test_climate_fan(
async def test_climate_swing(
hass: HomeAssistant, load_int: ConfigEntry, monkeypatch: pytest.MonkeyPatch
hass: HomeAssistant,
load_int: ConfigEntry,
monkeypatch: pytest.MonkeyPatch,
get_data: SensiboData,
) -> None:
"""Test the Sensibo climate swing service."""
@ -161,7 +168,7 @@ async def test_climate_swing(
assert state2.attributes["swing_mode"] == "fixedTop"
monkeypatch.setattr(
DATA_FROM_API.parsed["ABC999111"],
get_data.parsed["ABC999111"],
"active_features",
[
"timestamp",
@ -174,7 +181,7 @@ async def test_climate_swing(
)
with patch(
"homeassistant.components.sensibo.coordinator.SensiboClient.async_get_devices_data",
return_value=DATA_FROM_API,
return_value=get_data,
):
async_fire_time_changed(
hass,
@ -199,7 +206,10 @@ async def test_climate_swing(
async def test_climate_temperatures(
hass: HomeAssistant, load_int: ConfigEntry, monkeypatch: pytest.MonkeyPatch
hass: HomeAssistant,
load_int: ConfigEntry,
monkeypatch: pytest.MonkeyPatch,
get_data: SensiboData,
) -> None:
"""Test the Sensibo climate temperature service."""
@ -234,7 +244,7 @@ async def test_climate_temperatures(
await hass.async_block_till_done()
state2 = hass.states.get("climate.hallway")
assert state2.attributes["temperature"] == 18
assert state2.attributes["temperature"] == 17
with patch(
"homeassistant.components.sensibo.util.SensiboClient.async_set_ac_state_property",
@ -250,7 +260,7 @@ async def test_climate_temperatures(
await hass.async_block_till_done()
state2 = hass.states.get("climate.hallway")
assert state2.attributes["temperature"] == 18
assert state2.attributes["temperature"] == 17
with patch(
"homeassistant.components.sensibo.util.SensiboClient.async_set_ac_state_property",
@ -299,7 +309,7 @@ async def test_climate_temperatures(
assert state2.attributes["temperature"] == 20
monkeypatch.setattr(
DATA_FROM_API.parsed["ABC999111"],
get_data.parsed["ABC999111"],
"active_features",
[
"timestamp",
@ -312,7 +322,7 @@ async def test_climate_temperatures(
)
with patch(
"homeassistant.components.sensibo.coordinator.SensiboClient.async_get_devices_data",
return_value=DATA_FROM_API,
return_value=get_data,
):
async_fire_time_changed(
hass,
@ -338,12 +348,15 @@ async def test_climate_temperatures(
async def test_climate_temperature_is_none(
hass: HomeAssistant, load_int: ConfigEntry, monkeypatch: pytest.MonkeyPatch
hass: HomeAssistant,
load_int: ConfigEntry,
monkeypatch: pytest.MonkeyPatch,
get_data: SensiboData,
) -> None:
"""Test the Sensibo climate temperature service no temperature provided."""
monkeypatch.setattr(
DATA_FROM_API.parsed["ABC999111"],
get_data.parsed["ABC999111"],
"active_features",
[
"timestamp",
@ -357,13 +370,13 @@ async def test_climate_temperature_is_none(
],
)
monkeypatch.setattr(
DATA_FROM_API.parsed["ABC999111"],
get_data.parsed["ABC999111"],
"target_temp",
25,
)
with patch(
"homeassistant.components.sensibo.coordinator.SensiboClient.async_get_devices_data",
return_value=DATA_FROM_API,
return_value=get_data,
):
async_fire_time_changed(
hass,
@ -395,12 +408,15 @@ async def test_climate_temperature_is_none(
async def test_climate_hvac_mode(
hass: HomeAssistant, load_int: ConfigEntry, monkeypatch: pytest.MonkeyPatch
hass: HomeAssistant,
load_int: ConfigEntry,
monkeypatch: pytest.MonkeyPatch,
get_data: SensiboData,
) -> None:
"""Test the Sensibo climate hvac mode service."""
monkeypatch.setattr(
DATA_FROM_API.parsed["ABC999111"],
get_data.parsed["ABC999111"],
"active_features",
[
"timestamp",
@ -415,7 +431,7 @@ async def test_climate_hvac_mode(
)
with patch(
"homeassistant.components.sensibo.coordinator.SensiboClient.async_get_devices_data",
return_value=DATA_FROM_API,
return_value=get_data,
):
async_fire_time_changed(
hass,
@ -428,7 +444,7 @@ async def test_climate_hvac_mode(
with patch(
"homeassistant.components.sensibo.util.SensiboClient.async_get_devices_data",
return_value=DATA_FROM_API,
return_value=get_data,
), patch(
"homeassistant.components.sensibo.util.SensiboClient.async_set_ac_state_property",
return_value={"result": {"status": "Success"}},
@ -444,10 +460,10 @@ async def test_climate_hvac_mode(
state2 = hass.states.get("climate.hallway")
assert state2.state == "off"
monkeypatch.setattr(DATA_FROM_API.parsed["ABC999111"], "device_on", False)
monkeypatch.setattr(get_data.parsed["ABC999111"], "device_on", False)
with patch(
"homeassistant.components.sensibo.coordinator.SensiboClient.async_get_devices_data",
return_value=DATA_FROM_API,
return_value=get_data,
):
async_fire_time_changed(
hass,
@ -457,7 +473,7 @@ async def test_climate_hvac_mode(
with patch(
"homeassistant.components.sensibo.util.SensiboClient.async_get_devices_data",
return_value=DATA_FROM_API,
return_value=get_data,
), patch(
"homeassistant.components.sensibo.util.SensiboClient.async_set_ac_state_property",
return_value={"result": {"status": "Success"}},
@ -475,15 +491,18 @@ async def test_climate_hvac_mode(
async def test_climate_on_off(
hass: HomeAssistant, load_int: ConfigEntry, monkeypatch: pytest.MonkeyPatch
hass: HomeAssistant,
load_int: ConfigEntry,
monkeypatch: pytest.MonkeyPatch,
get_data: SensiboData,
) -> None:
"""Test the Sensibo climate on/off service."""
monkeypatch.setattr(DATA_FROM_API.parsed["ABC999111"], "hvac_mode", "heat")
monkeypatch.setattr(DATA_FROM_API.parsed["ABC999111"], "device_on", True)
monkeypatch.setattr(get_data.parsed["ABC999111"], "hvac_mode", "heat")
monkeypatch.setattr(get_data.parsed["ABC999111"], "device_on", True)
with patch(
"homeassistant.components.sensibo.coordinator.SensiboClient.async_get_devices_data",
return_value=DATA_FROM_API,
return_value=get_data,
):
async_fire_time_changed(
hass,
@ -526,15 +545,18 @@ async def test_climate_on_off(
async def test_climate_service_failed(
hass: HomeAssistant, load_int: ConfigEntry, monkeypatch: pytest.MonkeyPatch
hass: HomeAssistant,
load_int: ConfigEntry,
monkeypatch: pytest.MonkeyPatch,
get_data: SensiboData,
) -> None:
"""Test the Sensibo climate service failed."""
monkeypatch.setattr(DATA_FROM_API.parsed["ABC999111"], "hvac_mode", "heat")
monkeypatch.setattr(DATA_FROM_API.parsed["ABC999111"], "device_on", True)
monkeypatch.setattr(get_data.parsed["ABC999111"], "hvac_mode", "heat")
monkeypatch.setattr(get_data.parsed["ABC999111"], "device_on", True)
with patch(
"homeassistant.components.sensibo.coordinator.SensiboClient.async_get_devices_data",
return_value=DATA_FROM_API,
return_value=get_data,
):
async_fire_time_changed(
hass,
@ -563,15 +585,18 @@ async def test_climate_service_failed(
async def test_climate_assumed_state(
hass: HomeAssistant, load_int: ConfigEntry, monkeypatch: pytest.MonkeyPatch
hass: HomeAssistant,
load_int: ConfigEntry,
monkeypatch: pytest.MonkeyPatch,
get_data: SensiboData,
) -> None:
"""Test the Sensibo climate assumed state service."""
monkeypatch.setattr(DATA_FROM_API.parsed["ABC999111"], "hvac_mode", "heat")
monkeypatch.setattr(DATA_FROM_API.parsed["ABC999111"], "device_on", True)
monkeypatch.setattr(get_data.parsed["ABC999111"], "hvac_mode", "heat")
monkeypatch.setattr(get_data.parsed["ABC999111"], "device_on", True)
with patch(
"homeassistant.components.sensibo.coordinator.SensiboClient.async_get_devices_data",
return_value=DATA_FROM_API,
return_value=get_data,
):
async_fire_time_changed(
hass,
@ -584,7 +609,7 @@ async def test_climate_assumed_state(
with patch(
"homeassistant.components.sensibo.util.SensiboClient.async_get_devices_data",
return_value=DATA_FROM_API,
return_value=get_data,
), patch(
"homeassistant.components.sensibo.util.SensiboClient.async_set_ac_state_property",
return_value={"result": {"status": "Success"}},

View File

@ -15,13 +15,12 @@ from homeassistant.core import HomeAssistant
from homeassistant.util import dt
from . import ENTRY_CONFIG
from .response import DATA_FROM_API
from tests.common import MockConfigEntry, async_fire_time_changed
async def test_coordinator(
hass: HomeAssistant, monkeypatch: pytest.MonkeyPatch
hass: HomeAssistant, monkeypatch: pytest.MonkeyPatch, get_data: SensiboData
) -> None:
"""Test the Sensibo coordinator with errors."""
config_entry = MockConfigEntry(
@ -44,9 +43,9 @@ async def test_coordinator(
"homeassistant.components.sensibo.util.SensiboClient.async_get_me",
return_value={"result": {"username": "username"}},
):
monkeypatch.setattr(DATA_FROM_API.parsed["ABC999111"], "hvac_mode", "heat")
monkeypatch.setattr(DATA_FROM_API.parsed["ABC999111"], "device_on", True)
mock_data.return_value = DATA_FROM_API
monkeypatch.setattr(get_data.parsed["ABC999111"], "hvac_mode", "heat")
monkeypatch.setattr(get_data.parsed["ABC999111"], "device_on", True)
mock_data.return_value = get_data
await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done()
mock_data.assert_called_once()
@ -71,10 +70,10 @@ async def test_coordinator(
assert state.state == STATE_UNAVAILABLE
mock_data.reset_mock()
monkeypatch.setattr(DATA_FROM_API.parsed["ABC999111"], "hvac_mode", "heat")
monkeypatch.setattr(DATA_FROM_API.parsed["ABC999111"], "device_on", True)
monkeypatch.setattr(get_data.parsed["ABC999111"], "hvac_mode", "heat")
monkeypatch.setattr(get_data.parsed["ABC999111"], "device_on", True)
mock_data.return_value = DATA_FROM_API
mock_data.return_value = get_data
mock_data.side_effect = None
async_fire_time_changed(hass, dt.utcnow() + timedelta(minutes=5))
await hass.async_block_till_done()

View File

@ -17,32 +17,10 @@ async def test_diagnostics(
diag = await get_diagnostics_for_config_entry(hass, hass_client, entry)
assert diag == {
"status": "success",
"result": [
{
"id": "**REDACTED**",
"qrId": "**REDACTED**",
"room": {"uid": "**REDACTED**", "name": "Hallway", "icon": "Lounge"},
"acState": {
"timestamp": {
"time": "2022-04-30T19:58:15.544787Z",
"secondsAgo": 0,
},
"on": False,
"mode": "fan",
"fanLevel": "high",
"swing": "stopped",
"horizontalSwing": "stopped",
"light": "on",
},
"location": "**REDACTED**",
"accessPoint": {"ssid": "**REDACTED**", "password": None},
"macAddress": "**REDACTED**",
"autoOffMinutes": None,
"autoOffEnabled": False,
"antiMoldTimer": None,
"antiMoldConfig": None,
}
],
}
assert diag["status"] == "success"
for device in diag["result"]:
assert device["id"] == "**REDACTED**"
assert device["qrId"] == "**REDACTED**"
assert device["macAddress"] == "**REDACTED**"
assert device["location"] == "**REDACTED**"
assert device["productModel"] in ["skyv2", "pure"]

View File

@ -4,6 +4,7 @@ from __future__ import annotations
from datetime import timedelta
from unittest.mock import patch
from pysensibo.model import SensiboData
import pytest
from homeassistant.components.climate.const import (
@ -24,12 +25,12 @@ from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers import device_registry as dr, entity_registry as er
from homeassistant.util import dt
from .response import DATA_FROM_API
from tests.common import async_fire_time_changed
async def test_entity(hass: HomeAssistant, load_int: ConfigEntry) -> None:
async def test_entity(
hass: HomeAssistant, load_int: ConfigEntry, get_data: SensiboData
) -> None:
"""Test the Sensibo climate."""
state1 = hass.states.get("climate.hallway")
@ -55,7 +56,10 @@ async def test_entity(hass: HomeAssistant, load_int: ConfigEntry) -> None:
@pytest.mark.parametrize("p_error", SENSIBO_ERRORS)
async def test_entity_send_command(
hass: HomeAssistant, p_error: Exception, load_int: ConfigEntry
hass: HomeAssistant,
p_error: Exception,
load_int: ConfigEntry,
get_data: SensiboData,
) -> None:
"""Test the Sensibo send command with error."""
@ -94,7 +98,7 @@ async def test_entity_send_command(
async def test_entity_send_command_calibration(
hass: HomeAssistant, load_int: ConfigEntry
hass: HomeAssistant, load_int: ConfigEntry, get_data: SensiboData
) -> None:
"""Test the Sensibo send command for calibration."""
@ -106,7 +110,7 @@ async def test_entity_send_command_calibration(
with patch(
"homeassistant.components.sensibo.coordinator.SensiboClient.async_get_devices_data",
return_value=DATA_FROM_API,
return_value=get_data,
):
async_fire_time_changed(
hass,

View File

@ -3,6 +3,8 @@ from __future__ import annotations
from unittest.mock import patch
from pysensibo.model import SensiboData
from homeassistant import config_entries
from homeassistant.components.sensibo.const import DOMAIN
from homeassistant.components.sensibo.util import NoUsernameError
@ -10,12 +12,11 @@ from homeassistant.config_entries import SOURCE_USER
from homeassistant.core import HomeAssistant
from . import ENTRY_CONFIG
from .response import DATA_FROM_API
from tests.common import MockConfigEntry
async def test_setup_entry(hass: HomeAssistant) -> None:
async def test_setup_entry(hass: HomeAssistant, get_data: SensiboData) -> None:
"""Test setup entry."""
entry = MockConfigEntry(
domain=DOMAIN,
@ -29,7 +30,7 @@ async def test_setup_entry(hass: HomeAssistant) -> None:
with patch(
"homeassistant.components.sensibo.coordinator.SensiboClient.async_get_devices_data",
return_value=DATA_FROM_API,
return_value=get_data,
), patch(
"homeassistant.components.sensibo.util.SensiboClient.async_get_devices",
return_value={"result": [{"id": "xyzxyz"}, {"id": "abcabc"}]},
@ -43,7 +44,7 @@ async def test_setup_entry(hass: HomeAssistant) -> None:
assert entry.state == config_entries.ConfigEntryState.LOADED
async def test_migrate_entry(hass: HomeAssistant) -> None:
async def test_migrate_entry(hass: HomeAssistant, get_data: SensiboData) -> None:
"""Test migrate entry unique id."""
entry = MockConfigEntry(
domain=DOMAIN,
@ -57,7 +58,7 @@ async def test_migrate_entry(hass: HomeAssistant) -> None:
with patch(
"homeassistant.components.sensibo.coordinator.SensiboClient.async_get_devices_data",
return_value=DATA_FROM_API,
return_value=get_data,
), patch(
"homeassistant.components.sensibo.util.SensiboClient.async_get_devices",
return_value={"result": [{"id": "xyzxyz"}, {"id": "abcabc"}]},
@ -73,7 +74,7 @@ async def test_migrate_entry(hass: HomeAssistant) -> None:
assert entry.unique_id == "username"
async def test_migrate_entry_fails(hass: HomeAssistant) -> None:
async def test_migrate_entry_fails(hass: HomeAssistant, get_data: SensiboData) -> None:
"""Test migrate entry unique id."""
entry = MockConfigEntry(
domain=DOMAIN,
@ -101,7 +102,7 @@ async def test_migrate_entry_fails(hass: HomeAssistant) -> None:
assert entry.unique_id == "12"
async def test_unload_entry(hass: HomeAssistant) -> None:
async def test_unload_entry(hass: HomeAssistant, get_data: SensiboData) -> None:
"""Test unload an entry."""
entry = MockConfigEntry(
domain=DOMAIN,
@ -115,7 +116,7 @@ async def test_unload_entry(hass: HomeAssistant) -> None:
with patch(
"homeassistant.components.sensibo.coordinator.SensiboClient.async_get_devices_data",
return_value=DATA_FROM_API,
return_value=get_data,
), patch(
"homeassistant.components.sensibo.util.SensiboClient.async_get_devices",
return_value={"result": [{"id": "xyzxyz"}, {"id": "abcabc"}]},