From 1538f639ae8082067548bc0ecb5311cd7ad8e6d1 Mon Sep 17 00:00:00 2001 From: Maciej Bieniek Date: Mon, 6 Mar 2023 18:12:19 +0100 Subject: [PATCH] Bump `gios` library to version 3.1.0 (#89044) --- homeassistant/components/gios/__init__.py | 10 ++----- homeassistant/components/gios/config_flow.py | 4 +-- homeassistant/components/gios/manifest.json | 2 +- homeassistant/components/gios/sensor.py | 4 +++ homeassistant/components/gios/strings.json | 14 +++++++++ requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- .../gios/fixtures/diagnostics_data.json | 30 +++++++++---------- tests/components/gios/fixtures/indexes.json | 16 +++++----- tests/components/gios/test_sensor.py | 27 +++++++++++------ 10 files changed, 67 insertions(+), 44 deletions(-) diff --git a/homeassistant/components/gios/__init__.py b/homeassistant/components/gios/__init__.py index 1ade1a83cc7..4aad3b05370 100644 --- a/homeassistant/components/gios/__init__.py +++ b/homeassistant/components/gios/__init__.py @@ -7,7 +7,8 @@ from typing import Any, cast from aiohttp import ClientSession from aiohttp.client_exceptions import ClientConnectorError from async_timeout import timeout -from gios import ApiError, Gios, InvalidSensorsData, NoStationError +from gios import Gios +from gios.exceptions import GiosError from homeassistant.components.air_quality import DOMAIN as AIR_QUALITY_PLATFORM from homeassistant.config_entries import ConfigEntry @@ -89,10 +90,5 @@ class GiosDataUpdateCoordinator(DataUpdateCoordinator): try: async with timeout(API_TIMEOUT): return cast(dict[str, Any], await self.gios.async_update()) - except ( - ApiError, - NoStationError, - ClientConnectorError, - InvalidSensorsData, - ) as error: + except (GiosError, ClientConnectorError) as error: raise UpdateFailed(error) from error diff --git a/homeassistant/components/gios/config_flow.py b/homeassistant/components/gios/config_flow.py index 0fa5052e129..a1b4abd2dc7 100644 --- a/homeassistant/components/gios/config_flow.py +++ b/homeassistant/components/gios/config_flow.py @@ -6,7 +6,7 @@ from typing import Any from aiohttp.client_exceptions import ClientConnectorError from async_timeout import timeout -from gios import ApiError, Gios, InvalidSensorsData, NoStationError +from gios import ApiError, Gios, InvalidSensorsDataError, NoStationError import voluptuous as vol from homeassistant import config_entries @@ -50,7 +50,7 @@ class GiosFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): errors["base"] = "cannot_connect" except NoStationError: errors[CONF_STATION_ID] = "wrong_station_id" - except InvalidSensorsData: + except InvalidSensorsDataError: errors[CONF_STATION_ID] = "invalid_sensors_data" return self.async_show_form( diff --git a/homeassistant/components/gios/manifest.json b/homeassistant/components/gios/manifest.json index 6b3051a4bdd..41954645f5c 100644 --- a/homeassistant/components/gios/manifest.json +++ b/homeassistant/components/gios/manifest.json @@ -8,5 +8,5 @@ "iot_class": "cloud_polling", "loggers": ["dacite", "gios"], "quality_scale": "platinum", - "requirements": ["gios==2.3.0"] + "requirements": ["gios==3.1.0"] } diff --git a/homeassistant/components/gios/sensor.py b/homeassistant/components/gios/sensor.py index cabbb671aed..9c73b358897 100644 --- a/homeassistant/components/gios/sensor.py +++ b/homeassistant/components/gios/sensor.py @@ -60,6 +60,10 @@ SENSOR_TYPES: tuple[GiosSensorEntityDescription, ...] = ( key=ATTR_AQI, name="AQI", value=None, + icon="mdi:air-filter", + device_class=SensorDeviceClass.ENUM, + options=["very_bad", "bad", "sufficient", "moderate", "good", "very_good"], + translation_key="aqi", ), GiosSensorEntityDescription( key=ATTR_C6H6, diff --git a/homeassistant/components/gios/strings.json b/homeassistant/components/gios/strings.json index 18db42b69c0..a76bd3f612c 100644 --- a/homeassistant/components/gios/strings.json +++ b/homeassistant/components/gios/strings.json @@ -22,5 +22,19 @@ "info": { "can_reach_server": "Reach GIO\u015a server" } + }, + "entity": { + "sensor": { + "aqi": { + "state": { + "very_bad": "Very bad", + "bad": "Bad", + "sufficient": "Sufficient", + "moderate": "Moderate", + "good": "Good", + "very_good": "Very good" + } + } + } } } diff --git a/requirements_all.txt b/requirements_all.txt index 1a948b2d7d9..1c7d0f4687d 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -786,7 +786,7 @@ georss_qld_bushfire_alert_client==0.5 getmac==0.8.2 # homeassistant.components.gios -gios==2.3.0 +gios==3.1.0 # homeassistant.components.gitter gitterpy==0.1.7 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index ebcac904941..b103783ce92 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -602,7 +602,7 @@ georss_qld_bushfire_alert_client==0.5 getmac==0.8.2 # homeassistant.components.gios -gios==2.3.0 +gios==3.1.0 # homeassistant.components.glances glances_api==0.4.1 diff --git a/tests/components/gios/fixtures/diagnostics_data.json b/tests/components/gios/fixtures/diagnostics_data.json index 1044c9887bb..feee534ec31 100644 --- a/tests/components/gios/fixtures/diagnostics_data.json +++ b/tests/components/gios/fixtures/diagnostics_data.json @@ -3,48 +3,48 @@ "name": "AQI", "id": null, "index": null, - "value": "dobry" + "value": "good" }, "c6h6": { - "name": "benzen", + "name": "benzene", "id": 658, - "index": "bardzo dobry", + "index": "very_good", "value": 0.23789 }, "co": { - "name": "tlenek węgla", + "name": "carbon monoxide", "id": 660, - "index": "dobry", + "index": "good", "value": 251.874 }, "no2": { - "name": "dwutlenek azotu", + "name": "nitrogen dioxide", "id": 665, - "index": "dobry", + "index": "good", "value": 7.13411 }, "o3": { - "name": "ozon", + "name": "ozone", "id": 667, - "index": "dobry", + "index": "good", "value": 95.7768 }, "pm10": { - "name": "py\u0142 zawieszony PM10", + "name": "particulate matter 10", "id": 14395, - "index": "dobry", + "index": "good", "value": 16.8344 }, "pm25": { - "name": "py\u0142 zawieszony PM2.5", + "name": "particulate matter 2.5", "id": 670, - "index": "dobry", + "index": "good", "value": 4 }, "so2": { - "name": "dwutlenek siarki", + "name": "sulfur dioxide", "id": 672, - "index": "bardzo dobry", + "index": "very_good", "value": 4.35478 } } diff --git a/tests/components/gios/fixtures/indexes.json b/tests/components/gios/fixtures/indexes.json index cee504b0cc7..c53d1c78f6e 100644 --- a/tests/components/gios/fixtures/indexes.json +++ b/tests/components/gios/fixtures/indexes.json @@ -1,28 +1,28 @@ { "id": 123, "stCalcDate": "2020-07-31 15:10:17", - "stIndexLevel": { "id": 1, "indexLevelName": "dobry" }, + "stIndexLevel": { "id": 1, "indexLevelName": "Dobry" }, "stSourceDataDate": "2020-07-31 14:00:00", "so2CalcDate": "2020-07-31 15:10:17", - "so2IndexLevel": { "id": 0, "indexLevelName": "bardzo dobry" }, + "so2IndexLevel": { "id": 0, "indexLevelName": "Bardzo dobry" }, "so2SourceDataDate": "2020-07-31 14:00:00", "no2CalcDate": 1596201017000, - "no2IndexLevel": { "id": 0, "indexLevelName": "dobry" }, + "no2IndexLevel": { "id": 0, "indexLevelName": "Dobry" }, "no2SourceDataDate": "2020-07-31 14:00:00", "coCalcDate": "2020-07-31 15:10:17", - "coIndexLevel": { "id": 0, "indexLevelName": "dobry" }, + "coIndexLevel": { "id": 0, "indexLevelName": "Dobry" }, "coSourceDataDate": "2020-07-31 14:00:00", "pm10CalcDate": "2020-07-31 15:10:17", - "pm10IndexLevel": { "id": 0, "indexLevelName": "dobry" }, + "pm10IndexLevel": { "id": 0, "indexLevelName": "Dobry" }, "pm10SourceDataDate": "2020-07-31 14:00:00", "pm25CalcDate": "2020-07-31 15:10:17", - "pm25IndexLevel": { "id": 0, "indexLevelName": "dobry" }, + "pm25IndexLevel": { "id": 0, "indexLevelName": "Dobry" }, "pm25SourceDataDate": "2020-07-31 14:00:00", "o3CalcDate": "2020-07-31 15:10:17", - "o3IndexLevel": { "id": 1, "indexLevelName": "dobry" }, + "o3IndexLevel": { "id": 1, "indexLevelName": "Dobry" }, "o3SourceDataDate": "2020-07-31 14:00:00", "c6h6CalcDate": "2020-07-31 15:10:17", - "c6h6IndexLevel": { "id": 0, "indexLevelName": "bardzo dobry" }, + "c6h6IndexLevel": { "id": 0, "indexLevelName": "Bardzo dobry" }, "c6h6SourceDataDate": "2020-07-31 14:00:00", "stIndexStatus": true, "stIndexCrParam": "OZON" diff --git a/tests/components/gios/test_sensor.py b/tests/components/gios/test_sensor.py index 9dbdda7d2ee..c5b19502a0f 100644 --- a/tests/components/gios/test_sensor.py +++ b/tests/components/gios/test_sensor.py @@ -12,6 +12,7 @@ from homeassistant.components.gios.const import ( DOMAIN, ) from homeassistant.components.sensor import ( + ATTR_OPTIONS, ATTR_STATE_CLASS, DOMAIN as PLATFORM, SensorDeviceClass, @@ -50,7 +51,7 @@ async def test_sensor(hass: HomeAssistant) -> None: == CONCENTRATION_MICROGRAMS_PER_CUBIC_METER ) assert state.attributes.get(ATTR_ICON) == "mdi:molecule" - assert state.attributes.get(ATTR_INDEX) == "bardzo dobry" + assert state.attributes.get(ATTR_INDEX) == "very_good" entry = registry.async_get("sensor.home_c6h6") assert entry @@ -67,7 +68,7 @@ async def test_sensor(hass: HomeAssistant) -> None: state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == CONCENTRATION_MICROGRAMS_PER_CUBIC_METER ) - assert state.attributes.get(ATTR_INDEX) == "dobry" + assert state.attributes.get(ATTR_INDEX) == "good" entry = registry.async_get("sensor.home_co") assert entry @@ -84,7 +85,7 @@ async def test_sensor(hass: HomeAssistant) -> None: state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == CONCENTRATION_MICROGRAMS_PER_CUBIC_METER ) - assert state.attributes.get(ATTR_INDEX) == "dobry" + assert state.attributes.get(ATTR_INDEX) == "good" entry = registry.async_get("sensor.home_no2") assert entry @@ -101,7 +102,7 @@ async def test_sensor(hass: HomeAssistant) -> None: state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == CONCENTRATION_MICROGRAMS_PER_CUBIC_METER ) - assert state.attributes.get(ATTR_INDEX) == "dobry" + assert state.attributes.get(ATTR_INDEX) == "good" entry = registry.async_get("sensor.home_o3") assert entry @@ -118,7 +119,7 @@ async def test_sensor(hass: HomeAssistant) -> None: state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == CONCENTRATION_MICROGRAMS_PER_CUBIC_METER ) - assert state.attributes.get(ATTR_INDEX) == "dobry" + assert state.attributes.get(ATTR_INDEX) == "good" entry = registry.async_get("sensor.home_pm10") assert entry @@ -135,7 +136,7 @@ async def test_sensor(hass: HomeAssistant) -> None: state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == CONCENTRATION_MICROGRAMS_PER_CUBIC_METER ) - assert state.attributes.get(ATTR_INDEX) == "dobry" + assert state.attributes.get(ATTR_INDEX) == "good" entry = registry.async_get("sensor.home_pm2_5") assert entry @@ -152,7 +153,7 @@ async def test_sensor(hass: HomeAssistant) -> None: state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == CONCENTRATION_MICROGRAMS_PER_CUBIC_METER ) - assert state.attributes.get(ATTR_INDEX) == "bardzo dobry" + assert state.attributes.get(ATTR_INDEX) == "very_good" entry = registry.async_get("sensor.home_so2") assert entry @@ -160,11 +161,19 @@ async def test_sensor(hass: HomeAssistant) -> None: state = hass.states.get("sensor.home_aqi") assert state - assert state.state == "dobry" + assert state.state == "good" assert state.attributes.get(ATTR_ATTRIBUTION) == ATTRIBUTION assert state.attributes.get(ATTR_STATION) == "Test Name 1" assert state.attributes.get(ATTR_STATE_CLASS) is None assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) is None + assert state.attributes.get(ATTR_OPTIONS) == [ + "very_bad", + "bad", + "sufficient", + "moderate", + "good", + "very_good", + ] entry = registry.async_get("sensor.home_aqi") assert entry @@ -342,7 +351,7 @@ async def test_aqi_sensor_availability(hass: HomeAssistant) -> None: state = hass.states.get("sensor.home_aqi") assert state assert state.state != STATE_UNAVAILABLE - assert state.state == "dobry" + assert state.state == "good" future = utcnow() + timedelta(minutes=60) with patch(