"""The test for the sensibo sensor platform.""" from datetime import timedelta from unittest.mock import MagicMock from freezegun.api import FrozenDateTimeFactory from pysensibo.model import PureAQI import pytest from syrupy.assertion import SnapshotAssertion from homeassistant.config_entries import ConfigEntry from homeassistant.const import STATE_UNKNOWN, Platform from homeassistant.core import HomeAssistant from homeassistant.helpers import entity_registry as er from tests.common import async_fire_time_changed, snapshot_platform @pytest.mark.usefixtures("entity_registry_enabled_by_default") @pytest.mark.parametrize( "load_platforms", [[Platform.SENSOR]], ) async def test_sensor( hass: HomeAssistant, load_int: ConfigEntry, mock_client: MagicMock, entity_registry: er.EntityRegistry, snapshot: SnapshotAssertion, freezer: FrozenDateTimeFactory, ) -> None: """Test the Sensibo sensor.""" await snapshot_platform(hass, entity_registry, snapshot, load_int.entry_id) mock_client.async_get_devices_data.return_value.parsed[ "AAZZAAZZ" ].pm25_pure = PureAQI(2) freezer.tick(timedelta(minutes=5)) async_fire_time_changed(hass) await hass.async_block_till_done() state = hass.states.get("sensor.kitchen_kitchen_pure_aqi") assert state.state == "moderate" mock_client.async_get_devices_data.return_value.parsed[ "AAZZAAZZ" ].pm25_pure = PureAQI(0) freezer.tick(timedelta(minutes=5)) async_fire_time_changed(hass) await hass.async_block_till_done() state = hass.states.get("sensor.kitchen_kitchen_pure_aqi") assert state.state == STATE_UNKNOWN