Skip to content

Commit

Permalink
Use snapshot testing in NAM sensor and diagnostics (home-assistant#11…
Browse files Browse the repository at this point in the history
…5877)

* Use snapshot testing in NAM diagnostics

* Use snapshot testing in NAM sensor

* Add NAM data fixture

---------

Co-authored-by: Maciej Bieniek <[email protected]>
  • Loading branch information
bieniu and bieniu authored Apr 20, 2024
1 parent c4e7a7a commit 194f336
Show file tree
Hide file tree
Showing 7 changed files with 1,820 additions and 519 deletions.
35 changes: 3 additions & 32 deletions tests/components/nam/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,13 @@

from homeassistant.components.nam.const import DOMAIN

from tests.common import MockConfigEntry
from tests.common import MockConfigEntry, load_json_object_fixture

INCOMPLETE_NAM_DATA = {
"software_version": "NAMF-2020-36",
"sensordatavalues": [],
}

nam_data = {
"software_version": "NAMF-2020-36",
"uptime": "456987",
"sensordatavalues": [
{"value_type": "PMS_P0", "value": "6.00"},
{"value_type": "PMS_P1", "value": "10.00"},
{"value_type": "PMS_P2", "value": "11.00"},
{"value_type": "SDS_P1", "value": "18.65"},
{"value_type": "SDS_P2", "value": "11.03"},
{"value_type": "SPS30_P0", "value": "31.23"},
{"value_type": "SPS30_P1", "value": "21.23"},
{"value_type": "SPS30_P2", "value": "34.32"},
{"value_type": "SPS30_P4", "value": "24.72"},
{"value_type": "conc_co2_ppm", "value": "865"},
{"value_type": "BME280_temperature", "value": "7.56"},
{"value_type": "BME280_humidity", "value": "45.69"},
{"value_type": "BME280_pressure", "value": "101101.17"},
{"value_type": "BMP_temperature", "value": "7.56"},
{"value_type": "BMP_pressure", "value": "103201.18"},
{"value_type": "BMP280_temperature", "value": "5.56"},
{"value_type": "BMP280_pressure", "value": "102201.18"},
{"value_type": "SHT3X_temperature", "value": "6.28"},
{"value_type": "SHT3X_humidity", "value": "34.69"},
{"value_type": "humidity", "value": "46.23"},
{"value_type": "temperature", "value": "6.26"},
{"value_type": "HECA_temperature", "value": "7.95"},
{"value_type": "HECA_humidity", "value": "49.97"},
{"value_type": "signal", "value": "-72"},
],
}


async def init_integration(hass, co2_sensor=True) -> MockConfigEntry:
"""Set up the Nettigo Air Monitor integration in Home Assistant."""
Expand All @@ -52,6 +21,8 @@ async def init_integration(hass, co2_sensor=True) -> MockConfigEntry:
data={"host": "10.10.2.3"},
)

nam_data = load_json_object_fixture("nam/nam_data.json")

if not co2_sensor:
# Remove conc_co2_ppm value
nam_data["sensordatavalues"].pop(6)
Expand Down
33 changes: 0 additions & 33 deletions tests/components/nam/fixtures/diagnostics_data.json

This file was deleted.

30 changes: 30 additions & 0 deletions tests/components/nam/fixtures/nam_data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"software_version": "NAMF-2020-36",
"uptime": "456987",
"sensordatavalues": [
{ "value_type": "PMS_P0", "value": "6.00" },
{ "value_type": "PMS_P1", "value": "10.00" },
{ "value_type": "PMS_P2", "value": "11.00" },
{ "value_type": "SDS_P1", "value": "18.65" },
{ "value_type": "SDS_P2", "value": "11.03" },
{ "value_type": "SPS30_P0", "value": "31.23" },
{ "value_type": "SPS30_P1", "value": "21.23" },
{ "value_type": "SPS30_P2", "value": "34.32" },
{ "value_type": "SPS30_P4", "value": "24.72" },
{ "value_type": "conc_co2_ppm", "value": "865" },
{ "value_type": "BME280_temperature", "value": "7.56" },
{ "value_type": "BME280_humidity", "value": "45.69" },
{ "value_type": "BME280_pressure", "value": "101101.17" },
{ "value_type": "BMP_temperature", "value": "7.56" },
{ "value_type": "BMP_pressure", "value": "103201.18" },
{ "value_type": "BMP280_temperature", "value": "5.56" },
{ "value_type": "BMP280_pressure", "value": "102201.18" },
{ "value_type": "SHT3X_temperature", "value": "6.28" },
{ "value_type": "SHT3X_humidity", "value": "34.69" },
{ "value_type": "humidity", "value": "46.23" },
{ "value_type": "temperature", "value": "6.26" },
{ "value_type": "HECA_temperature", "value": "7.95" },
{ "value_type": "HECA_humidity", "value": "49.97" },
{ "value_type": "signal", "value": "-72" }
]
}
41 changes: 41 additions & 0 deletions tests/components/nam/snapshots/test_diagnostics.ambr
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# serializer version: 1
# name: test_entry_diagnostics
dict({
'data': dict({
'bme280_humidity': 45.7,
'bme280_pressure': 1011.012,
'bme280_temperature': 7.6,
'bmp180_pressure': 1032.012,
'bmp180_temperature': 7.6,
'bmp280_pressure': 1022.012,
'bmp280_temperature': 5.6,
'dht22_humidity': 46.2,
'dht22_temperature': 6.3,
'heca_humidity': 50.0,
'heca_temperature': 8.0,
'mhz14a_carbon_dioxide': 865.0,
'pms_caqi': 19,
'pms_caqi_level': 'very_low',
'pms_p0': 6.0,
'pms_p1': 10.0,
'pms_p2': 11.0,
'sds011_caqi': 19,
'sds011_caqi_level': 'very_low',
'sds011_p1': 18.6,
'sds011_p2': 11.0,
'sht3x_humidity': 34.7,
'sht3x_temperature': 6.3,
'signal': -72.0,
'sps30_caqi': 54,
'sps30_caqi_level': 'medium',
'sps30_p0': 31.2,
'sps30_p1': 21.2,
'sps30_p2': 34.3,
'sps30_p4': 24.7,
'uptime': 456987,
}),
'info': dict({
'host': '10.10.2.3',
}),
})
# ---
Loading

0 comments on commit 194f336

Please sign in to comment.