Refactor Sensibo tests to use snapshot (#100775)

This commit is contained in:
G Johansson 2023-09-23 23:37:02 +02:00 committed by GitHub
parent 8d8c7187d3
commit 28dc17c0b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 66 additions and 51 deletions

View File

@ -0,0 +1,33 @@
# serializer version: 1
# name: test_climate
ReadOnlyDict({
'current_humidity': 32.9,
'current_temperature': 21.2,
'fan_mode': 'high',
'fan_modes': list([
'quiet',
'low',
'medium',
]),
'friendly_name': 'Hallway',
'hvac_modes': list([
<HVACMode.COOL: 'cool'>,
<HVACMode.HEAT: 'heat'>,
<HVACMode.DRY: 'dry'>,
<HVACMode.HEAT_COOL: 'heat_cool'>,
<HVACMode.FAN_ONLY: 'fan_only'>,
<HVACMode.OFF: 'off'>,
]),
'max_temp': 20,
'min_temp': 10,
'supported_features': <ClimateEntityFeature: 41>,
'swing_mode': 'stopped',
'swing_modes': list([
'stopped',
'fixedtop',
'fixedmiddletop',
]),
'target_temp_step': 1,
'temperature': 25,
})
# ---

View File

@ -0,0 +1,26 @@
# serializer version: 1
# name: test_sensor
ReadOnlyDict({
'device_class': 'pm25',
'friendly_name': 'Kitchen PM2.5',
'icon': 'mdi:air-filter',
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
'unit_of_measurement': 'µg/m³',
})
# ---
# name: test_sensor.1
ReadOnlyDict({
'device_class': 'temperature',
'fanlevel': 'low',
'friendly_name': 'Hallway Climate React low temperature threshold',
'horizontalswing': 'stopped',
'light': 'on',
'mode': 'heat',
'on': True,
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
'swing': 'stopped',
'targettemperature': 21,
'temperatureunit': 'c',
'unit_of_measurement': <UnitOfTemperature.CELSIUS: '°C'>,
})
# ---

View File

@ -6,6 +6,7 @@ from unittest.mock import patch
from pysensibo.model import SensiboData
import pytest
from syrupy.assertion import SnapshotAssertion
from voluptuous import MultipleInvalid
from homeassistant.components.climate import (
@ -80,6 +81,7 @@ async def test_climate(
caplog: pytest.LogCaptureFixture,
get_data: SensiboData,
load_int: ConfigEntry,
snapshot: SnapshotAssertion,
) -> None:
"""Test the Sensibo climate."""
@ -88,36 +90,7 @@ async def test_climate(
state3 = hass.states.get("climate.bedroom")
assert state1.state == "heat"
assert state1.attributes == {
"hvac_modes": [
"cool",
"heat",
"dry",
"heat_cool",
"fan_only",
"off",
],
"min_temp": 10,
"max_temp": 20,
"target_temp_step": 1,
"fan_modes": [
"quiet",
"low",
"medium",
],
"swing_modes": [
"stopped",
"fixedtop",
"fixedmiddletop",
],
"current_temperature": 21.2,
"temperature": 25,
"current_humidity": 32.9,
"fan_mode": "high",
"swing_mode": "stopped",
"friendly_name": "Hallway",
"supported_features": 41,
}
assert state1.attributes == snapshot
assert state2.state == "off"

View File

@ -6,6 +6,7 @@ from unittest.mock import patch
from pysensibo.model import SensiboData
import pytest
from syrupy.assertion import SnapshotAssertion
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
@ -20,6 +21,7 @@ async def test_sensor(
load_int: ConfigEntry,
monkeypatch: pytest.MonkeyPatch,
get_data: SensiboData,
snapshot: SnapshotAssertion,
) -> None:
"""Test the Sensibo sensor."""
@ -31,27 +33,8 @@ async def test_sensor(
assert state2.state == "1"
assert state3.state == "n"
assert state4.state == "0.0"
assert state2.attributes == {
"state_class": "measurement",
"unit_of_measurement": "µg/m³",
"device_class": "pm25",
"icon": "mdi:air-filter",
"friendly_name": "Kitchen PM2.5",
}
assert state4.attributes == {
"device_class": "temperature",
"friendly_name": "Hallway Climate React low temperature threshold",
"state_class": "measurement",
"unit_of_measurement": "°C",
"on": True,
"targettemperature": 21,
"temperatureunit": "c",
"mode": "heat",
"fanlevel": "low",
"swing": "stopped",
"horizontalswing": "stopped",
"light": "on",
}
assert state2.attributes == snapshot
assert state4.attributes == snapshot
monkeypatch.setattr(get_data.parsed["AAZZAAZZ"], "pm25", 2)