Use SnapshotAssertion in rainmachine diagnostic tests (#117979)

* Use SnapshotAssertion in rainmachine diagnostic tests

* Force entry_id

* Adjust

* Fix incorrect fixtures

* Adjust
This commit is contained in:
epenet 2024-05-23 16:22:31 +02:00 committed by GitHub
parent 880b315890
commit 0c243d699c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 2792 additions and 1225 deletions

View File

@ -1,6 +1,7 @@
"""Define test fixtures for RainMachine.""" """Define test fixtures for RainMachine."""
import json import json
from typing import Any
from unittest.mock import AsyncMock, patch from unittest.mock import AsyncMock, patch
import pytest import pytest
@ -32,7 +33,12 @@ def config_fixture(hass):
@pytest.fixture(name="config_entry") @pytest.fixture(name="config_entry")
def config_entry_fixture(hass, config, controller_mac): def config_entry_fixture(hass, config, controller_mac):
"""Define a config entry fixture.""" """Define a config entry fixture."""
entry = MockConfigEntry(domain=DOMAIN, unique_id=controller_mac, data=config) entry = MockConfigEntry(
domain=DOMAIN,
unique_id=controller_mac,
data=config,
entry_id="81bd010ed0a63b705f6da8407cb26d4b",
)
entry.add_to_hass(hass) entry.add_to_hass(hass)
return entry return entry
@ -100,7 +106,9 @@ def data_machine_firmare_update_status_fixture():
@pytest.fixture(name="data_programs", scope="package") @pytest.fixture(name="data_programs", scope="package")
def data_programs_fixture(): def data_programs_fixture():
"""Define program data.""" """Define program data."""
return json.loads(load_fixture("programs_data.json", "rainmachine")) raw_data = json.loads(load_fixture("programs_data.json", "rainmachine"))
# This replicate the process from `regenmaschine` to convert list to dict
return {program["uid"]: program for program in raw_data}
@pytest.fixture(name="data_provision_settings", scope="package") @pytest.fixture(name="data_provision_settings", scope="package")
@ -124,7 +132,16 @@ def data_restrictions_universal_fixture():
@pytest.fixture(name="data_zones", scope="package") @pytest.fixture(name="data_zones", scope="package")
def data_zones_fixture(): def data_zones_fixture():
"""Define zone data.""" """Define zone data."""
return json.loads(load_fixture("zones_data.json", "rainmachine")) raw_data = json.loads(load_fixture("zones_data.json", "rainmachine"))
# This replicate the process from `regenmaschine` to convert list to dict
zone_details = json.loads(load_fixture("zones_details.json", "rainmachine"))
zones: dict[int, dict[str, Any]] = {}
for zone in raw_data:
[extra] = [z for z in zone_details if z["uid"] == zone["uid"]]
zones[zone["uid"]] = {**zone, **extra}
return zones
@pytest.fixture(name="setup_rainmachine") @pytest.fixture(name="setup_rainmachine")

View File

@ -0,0 +1,482 @@
[
{
"uid": 1,
"name": "Landscaping",
"valveid": 1,
"ETcoef": 0.80000000000000004,
"active": true,
"type": 4,
"internet": true,
"savings": 100,
"slope": 1,
"sun": 1,
"soil": 5,
"group_id": 4,
"history": true,
"master": false,
"before": 0,
"after": 0,
"waterSense": {
"fieldCapacity": 0.17000000000000001,
"rootDepth": 229,
"minRuntime": 0,
"appEfficiency": 0.75,
"isTallPlant": true,
"permWilting": 0.029999999999999999,
"allowedSurfaceAcc": 8.3800000000000008,
"maxAllowedDepletion": 0.5,
"precipitationRate": 25.399999999999999,
"currentFieldCapacity": 16.030000000000001,
"area": 92.900001525878906,
"referenceTime": 1243,
"detailedMonthsKc": [
1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0
],
"flowrate": null,
"soilIntakeRate": 10.16
},
"customSoilPreset": null,
"customVegetationPreset": null,
"customSprinklerPreset": null
},
{
"uid": 2,
"name": "Flower Box",
"valveid": 2,
"ETcoef": 0.80000000000000004,
"active": true,
"type": 5,
"internet": true,
"savings": 100,
"slope": 1,
"sun": 1,
"soil": 5,
"group_id": 3,
"history": true,
"master": false,
"before": 0,
"after": 0,
"waterSense": {
"fieldCapacity": 0.17000000000000001,
"rootDepth": 457,
"minRuntime": 5,
"appEfficiency": 0.80000000000000004,
"isTallPlant": true,
"permWilting": 0.029999999999999999,
"allowedSurfaceAcc": 8.3800000000000008,
"maxAllowedDepletion": 0.34999999999999998,
"precipitationRate": 12.699999999999999,
"currentFieldCapacity": 22.390000000000001,
"area": 92.900000000000006,
"referenceTime": 2680,
"detailedMonthsKc": [
1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0
],
"flowrate": null,
"soilIntakeRate": 10.16
},
"customSoilPreset": null,
"customVegetationPreset": null,
"customSprinklerPreset": null
},
{
"uid": 3,
"name": "TEST",
"valveid": 3,
"ETcoef": 0.80000000000000004,
"active": false,
"type": 9,
"internet": true,
"savings": 100,
"slope": 1,
"sun": 1,
"soil": 1,
"group_id": 1,
"history": true,
"master": false,
"before": 0,
"after": 0,
"waterSense": {
"fieldCapacity": 0.29999999999999999,
"rootDepth": 700,
"minRuntime": 0,
"appEfficiency": 0.69999999999999996,
"isTallPlant": true,
"permWilting": 0.029999999999999999,
"allowedSurfaceAcc": 6.5999999999999996,
"maxAllowedDepletion": 0.59999999999999998,
"precipitationRate": 35.560000000000002,
"currentFieldCapacity": 113.40000000000001,
"area": 92.900000000000006,
"referenceTime": 380,
"detailedMonthsKc": [
1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0
],
"flowrate": null,
"soilIntakeRate": 5.0800000000000001
},
"customSoilPreset": null,
"customVegetationPreset": null,
"customSprinklerPreset": null
},
{
"uid": 4,
"name": "Zone 4",
"valveid": 4,
"ETcoef": 0.80000000000000004,
"active": false,
"type": 2,
"internet": true,
"savings": 100,
"slope": 1,
"sun": 1,
"soil": 1,
"group_id": 1,
"history": true,
"master": false,
"before": 0,
"after": 0,
"waterSense": {
"fieldCapacity": 0.29999999999999999,
"rootDepth": 203,
"minRuntime": -1,
"appEfficiency": 0.69999999999999996,
"isTallPlant": false,
"permWilting": 0.029999999999999999,
"allowedSurfaceAcc": 6.5999999999999996,
"maxAllowedDepletion": 0.40000000000000002,
"precipitationRate": 35.560000000000002,
"currentFieldCapacity": 21.920000000000002,
"area": 92.900000000000006,
"referenceTime": 761,
"detailedMonthsKc": [
1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0
],
"flowrate": 0.0,
"soilIntakeRate": 5.0800000000000001
},
"customSoilPreset": null,
"customVegetationPreset": null,
"customSprinklerPreset": null
},
{
"uid": 5,
"name": "Zone 5",
"valveid": 5,
"ETcoef": 0.80000000000000004,
"active": false,
"type": 2,
"internet": true,
"savings": 100,
"slope": 1,
"sun": 1,
"soil": 1,
"group_id": 1,
"history": true,
"master": false,
"before": 0,
"after": 0,
"waterSense": {
"fieldCapacity": 0.29999999999999999,
"rootDepth": 203,
"minRuntime": -1,
"appEfficiency": 0.69999999999999996,
"isTallPlant": false,
"permWilting": 0.029999999999999999,
"allowedSurfaceAcc": 6.5999999999999996,
"maxAllowedDepletion": 0.40000000000000002,
"precipitationRate": 35.560000000000002,
"currentFieldCapacity": 21.920000000000002,
"area": 92.900000000000006,
"referenceTime": 761,
"detailedMonthsKc": [
1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0
],
"flowrate": 0.0,
"soilIntakeRate": 5.0800000000000001
},
"customSoilPreset": null,
"customVegetationPreset": null,
"customSprinklerPreset": null
},
{
"uid": 6,
"name": "Zone 6",
"valveid": 6,
"ETcoef": 0.80000000000000004,
"active": false,
"type": 2,
"internet": true,
"savings": 100,
"slope": 1,
"sun": 1,
"soil": 1,
"group_id": 1,
"history": true,
"master": false,
"before": 0,
"after": 0,
"waterSense": {
"fieldCapacity": 0.29999999999999999,
"rootDepth": 203,
"minRuntime": -1,
"appEfficiency": 0.69999999999999996,
"isTallPlant": false,
"permWilting": 0.029999999999999999,
"allowedSurfaceAcc": 6.5999999999999996,
"maxAllowedDepletion": 0.40000000000000002,
"precipitationRate": 35.560000000000002,
"currentFieldCapacity": 21.920000000000002,
"area": 92.900000000000006,
"referenceTime": 761,
"detailedMonthsKc": [
1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0
],
"flowrate": 0.0,
"soilIntakeRate": 5.0800000000000001
},
"customSoilPreset": null,
"customVegetationPreset": null,
"customSprinklerPreset": null
},
{
"uid": 7,
"name": "Zone 7",
"valveid": 7,
"ETcoef": 0.80000000000000004,
"active": false,
"type": 2,
"internet": true,
"savings": 100,
"slope": 1,
"sun": 1,
"soil": 1,
"group_id": 1,
"history": true,
"master": false,
"before": 0,
"after": 0,
"waterSense": {
"fieldCapacity": 0.29999999999999999,
"rootDepth": 203,
"minRuntime": -1,
"appEfficiency": 0.69999999999999996,
"isTallPlant": false,
"permWilting": 0.029999999999999999,
"allowedSurfaceAcc": 6.5999999999999996,
"maxAllowedDepletion": 0.40000000000000002,
"precipitationRate": 35.560000000000002,
"currentFieldCapacity": 21.920000000000002,
"area": 92.900000000000006,
"referenceTime": 761,
"detailedMonthsKc": [
1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0
],
"flowrate": 0.0,
"soilIntakeRate": 5.0800000000000001
},
"customSoilPreset": null,
"customVegetationPreset": null,
"customSprinklerPreset": null
},
{
"uid": 8,
"name": "Zone 8",
"valveid": 8,
"ETcoef": 0.80000000000000004,
"active": false,
"type": 2,
"internet": true,
"savings": 100,
"slope": 1,
"sun": 1,
"soil": 1,
"group_id": 1,
"history": true,
"master": false,
"before": 0,
"after": 0,
"waterSense": {
"fieldCapacity": 0.29999999999999999,
"rootDepth": 203,
"minRuntime": -1,
"appEfficiency": 0.69999999999999996,
"isTallPlant": false,
"permWilting": 0.029999999999999999,
"allowedSurfaceAcc": 6.5999999999999996,
"maxAllowedDepletion": 0.40000000000000002,
"precipitationRate": 35.560000000000002,
"currentFieldCapacity": 21.920000000000002,
"area": 92.900000000000006,
"referenceTime": 761,
"detailedMonthsKc": [
1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0
],
"flowrate": 0.0,
"soilIntakeRate": 5.0800000000000001
},
"customSoilPreset": null,
"customVegetationPreset": null,
"customSprinklerPreset": null
},
{
"uid": 9,
"name": "Zone 9",
"valveid": 9,
"ETcoef": 0.80000000000000004,
"active": false,
"type": 2,
"internet": true,
"savings": 100,
"slope": 1,
"sun": 1,
"soil": 1,
"group_id": 1,
"history": true,
"master": false,
"before": 0,
"after": 0,
"waterSense": {
"fieldCapacity": 0.29999999999999999,
"rootDepth": 203,
"minRuntime": -1,
"appEfficiency": 0.69999999999999996,
"isTallPlant": false,
"permWilting": 0.029999999999999999,
"allowedSurfaceAcc": 6.5999999999999996,
"maxAllowedDepletion": 0.40000000000000002,
"precipitationRate": 35.560000000000002,
"currentFieldCapacity": 21.920000000000002,
"area": 92.900000000000006,
"referenceTime": 761,
"detailedMonthsKc": [
1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0
],
"flowrate": 0.0,
"soilIntakeRate": 5.0800000000000001
},
"customSoilPreset": null,
"customVegetationPreset": null,
"customSprinklerPreset": null
},
{
"uid": 10,
"name": "Zone 10",
"valveid": 10,
"ETcoef": 0.80000000000000004,
"active": false,
"type": 2,
"internet": true,
"savings": 100,
"slope": 1,
"sun": 1,
"soil": 1,
"group_id": 1,
"history": true,
"master": false,
"before": 0,
"after": 0,
"waterSense": {
"fieldCapacity": 0.29999999999999999,
"rootDepth": 203,
"minRuntime": -1,
"appEfficiency": 0.69999999999999996,
"isTallPlant": false,
"permWilting": 0.029999999999999999,
"allowedSurfaceAcc": 6.5999999999999996,
"maxAllowedDepletion": 0.40000000000000002,
"precipitationRate": 35.560000000000002,
"currentFieldCapacity": 21.920000000000002,
"area": 92.900000000000006,
"referenceTime": 761,
"detailedMonthsKc": [
1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0
],
"flowrate": 0.0,
"soilIntakeRate": 5.0800000000000001
},
"customSoilPreset": null,
"customVegetationPreset": null,
"customSprinklerPreset": null
},
{
"uid": 11,
"name": "Zone 11",
"valveid": 11,
"ETcoef": 0.80000000000000004,
"active": false,
"type": 2,
"internet": true,
"savings": 100,
"slope": 1,
"sun": 1,
"soil": 1,
"group_id": 1,
"history": true,
"master": false,
"before": 0,
"after": 0,
"waterSense": {
"fieldCapacity": 0.29999999999999999,
"rootDepth": 203,
"minRuntime": -1,
"appEfficiency": 0.69999999999999996,
"isTallPlant": false,
"permWilting": 0.029999999999999999,
"allowedSurfaceAcc": 6.5999999999999996,
"maxAllowedDepletion": 0.40000000000000002,
"precipitationRate": 35.560000000000002,
"currentFieldCapacity": 21.920000000000002,
"area": 92.900000000000006,
"referenceTime": 761,
"detailedMonthsKc": [
1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0
],
"flowrate": 0.0,
"soilIntakeRate": 5.0800000000000001
},
"customSoilPreset": null,
"customVegetationPreset": null,
"customSprinklerPreset": null
},
{
"uid": 12,
"name": "Zone 12",
"valveid": 12,
"ETcoef": 0.80000000000000004,
"active": false,
"type": 2,
"internet": true,
"savings": 100,
"slope": 1,
"sun": 1,
"soil": 1,
"group_id": 1,
"history": true,
"master": false,
"before": 0,
"after": 0,
"waterSense": {
"fieldCapacity": 0.29999999999999999,
"rootDepth": 203,
"minRuntime": -1,
"appEfficiency": 0.69999999999999996,
"isTallPlant": false,
"permWilting": 0.029999999999999999,
"allowedSurfaceAcc": 6.5999999999999996,
"maxAllowedDepletion": 0.40000000000000002,
"precipitationRate": 35.560000000000002,
"currentFieldCapacity": 21.920000000000002,
"area": 92.900000000000006,
"referenceTime": 761,
"detailedMonthsKc": [
1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0
],
"flowrate": 0.0,
"soilIntakeRate": 5.0800000000000001
},
"customSoilPreset": null,
"customVegetationPreset": null,
"customSprinklerPreset": null
}
]

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff