Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump gios library to version 3.1.0 #89044

Merged
merged 3 commits into from Mar 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 3 additions & 7 deletions homeassistant/components/gios/__init__.py
Expand Up @@ -7,7 +7,8 @@
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
Expand Down Expand Up @@ -89,10 +90,5 @@ async def _async_update_data(self) -> dict[str, Any]:
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
4 changes: 2 additions & 2 deletions homeassistant/components/gios/config_flow.py
Expand Up @@ -6,7 +6,7 @@

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
Expand Down Expand Up @@ -50,7 +50,7 @@ async def async_step_user(
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(
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/gios/manifest.json
Expand Up @@ -8,5 +8,5 @@
"iot_class": "cloud_polling",
"loggers": ["dacite", "gios"],
"quality_scale": "platinum",
"requirements": ["gios==2.3.0"]
"requirements": ["gios==3.1.0"]
}
4 changes: 4 additions & 0 deletions homeassistant/components/gios/sensor.py
Expand Up @@ -60,6 +60,10 @@ class GiosSensorEntityDescription(SensorEntityDescription):
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,
Expand Down
14 changes: 14 additions & 0 deletions homeassistant/components/gios/strings.json
Expand Up @@ -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"
}
}
}
}
}
2 changes: 1 addition & 1 deletion requirements_all.txt
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion requirements_test_all.txt
Expand Up @@ -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
Expand Down
30 changes: 15 additions & 15 deletions tests/components/gios/fixtures/diagnostics_data.json
Expand Up @@ -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
}
}
16 changes: 8 additions & 8 deletions 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"
Expand Down
27 changes: 18 additions & 9 deletions tests/components/gios/test_sensor.py
Expand Up @@ -12,6 +12,7 @@
DOMAIN,
)
from homeassistant.components.sensor import (
ATTR_OPTIONS,
ATTR_STATE_CLASS,
DOMAIN as PLATFORM,
SensorDeviceClass,
Expand Down Expand Up @@ -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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can also provide translations for attributes in our strings.json file.

https://developers.home-assistant.io/docs/internationalization/core#entity-state-attributes

Although the frontend currently only supports climate right now, it would be a matter of time before the rest is implemented. The backend supports it fully.

Copy link
Member Author

@bieniu bieniu Mar 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I plan to migrate index attributes to the separate entities in the next step. Do you think the attributes will be better? And I want to remove name and station attributes because they present static data.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm always all in favor of less attributes 🎉 😬


entry = registry.async_get("sensor.home_c6h6")
assert entry
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -152,19 +153,27 @@ 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
assert entry.unique_id == "123-so2"

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
Expand Down Expand Up @@ -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(
Expand Down