Move WAQI state attributes to separate sensors (#101217)

* Migrate WAQI to has entity name

* Split WAQI extra state attributes into separate sensors

* Split WAQI extra state attributes into separate sensors

* Fix test

* Support new aiowaqi

* Bump aiowaqi to 2.1.0

* Add nephelometry as possible value

* Fix test
This commit is contained in:
Joost Lekkerkerker 2023-10-19 12:30:40 +02:00 committed by GitHub
parent c377cf1ce0
commit 9857c0fa3a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 388 additions and 49 deletions

View file

@ -3,10 +3,11 @@ import json
from unittest.mock import patch
from aiowaqi import WAQIAirQuality, WAQIError, WAQISearchResult
from syrupy import SnapshotAssertion
from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN
from homeassistant.components.waqi.const import CONF_STATION_NUMBER, DOMAIN
from homeassistant.components.waqi.sensor import CONF_LOCATIONS, CONF_STATIONS
from homeassistant.components.waqi.sensor import CONF_LOCATIONS, CONF_STATIONS, SENSORS
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntryState
from homeassistant.const import (
CONF_API_KEY,
@ -72,7 +73,7 @@ async def test_legacy_migration_already_imported(
assert await async_setup_component(hass, DOMAIN, {})
await hass.async_block_till_done()
state = hass.states.get("sensor.de_jongweg_utrecht")
state = hass.states.get("sensor.de_jongweg_utrecht_air_quality_index")
assert state.state == "29"
hass.async_create_task(
@ -114,13 +115,15 @@ async def test_sensor_id_migration(
entities = er.async_entries_for_config_entry(
entity_registry, mock_config_entry.entry_id
)
assert len(entities) == 1
assert len(entities) == 11
assert hass.states.get("sensor.waqi_4584")
assert hass.states.get("sensor.de_jongweg_utrecht") is None
assert hass.states.get("sensor.de_jongweg_utrecht_air_quality_index") is None
assert entities[0].unique_id == "4584_air_quality"
async def test_sensor(hass: HomeAssistant, mock_config_entry: MockConfigEntry) -> None:
async def test_sensor(
hass: HomeAssistant, mock_config_entry: MockConfigEntry, snapshot: SnapshotAssertion
) -> None:
"""Test failed update."""
mock_config_entry.add_to_hass(hass)
with patch(
@ -131,9 +134,12 @@ async def test_sensor(hass: HomeAssistant, mock_config_entry: MockConfigEntry) -
):
assert await async_setup_component(hass, DOMAIN, {})
await hass.async_block_till_done()
state = hass.states.get("sensor.de_jongweg_utrecht")
assert state.state == "29"
entity_registry = er.async_get(hass)
for sensor in SENSORS:
entity_id = entity_registry.async_get_entity_id(
SENSOR_DOMAIN, DOMAIN, f"4584_{sensor.key}"
)
assert hass.states.get(entity_id) == snapshot
async def test_updating_failed(