2021-05-07 13:59:29 +00:00
|
|
|
"""Tests for the Nettigo Air Monitor integration."""
|
2024-03-08 19:38:34 +00:00
|
|
|
|
2021-11-18 01:00:19 +00:00
|
|
|
from unittest.mock import AsyncMock, Mock, patch
|
2021-05-07 13:59:29 +00:00
|
|
|
|
|
|
|
from homeassistant.components.nam.const import DOMAIN
|
|
|
|
|
2024-04-20 10:34:27 +00:00
|
|
|
from tests.common import MockConfigEntry, load_json_object_fixture
|
2021-05-07 13:59:29 +00:00
|
|
|
|
|
|
|
INCOMPLETE_NAM_DATA = {
|
|
|
|
"software_version": "NAMF-2020-36",
|
|
|
|
"sensordatavalues": [],
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async def init_integration(hass, co2_sensor=True) -> MockConfigEntry:
|
|
|
|
"""Set up the Nettigo Air Monitor integration in Home Assistant."""
|
|
|
|
entry = MockConfigEntry(
|
|
|
|
domain=DOMAIN,
|
|
|
|
title="10.10.2.3",
|
|
|
|
unique_id="aa:bb:cc:dd:ee:ff",
|
|
|
|
data={"host": "10.10.2.3"},
|
|
|
|
)
|
|
|
|
|
2024-04-20 10:34:27 +00:00
|
|
|
nam_data = load_json_object_fixture("nam/nam_data.json")
|
|
|
|
|
2021-05-07 13:59:29 +00:00
|
|
|
if not co2_sensor:
|
|
|
|
# Remove conc_co2_ppm value
|
|
|
|
nam_data["sensordatavalues"].pop(6)
|
|
|
|
|
2021-11-18 01:00:19 +00:00
|
|
|
update_response = Mock(json=AsyncMock(return_value=nam_data))
|
|
|
|
|
2024-03-25 23:02:16 +00:00
|
|
|
with (
|
|
|
|
patch("homeassistant.components.nam.NettigoAirMonitor.initialize"),
|
|
|
|
patch(
|
|
|
|
"homeassistant.components.nam.NettigoAirMonitor._async_http_request",
|
|
|
|
return_value=update_response,
|
|
|
|
),
|
2021-05-07 13:59:29 +00:00
|
|
|
):
|
|
|
|
entry.add_to_hass(hass)
|
|
|
|
await hass.config_entries.async_setup(entry.entry_id)
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
|
|
|
return entry
|