diff --git a/homeassistant/components/gios/__init__.py b/homeassistant/components/gios/__init__.py index c76efbcf361..f756980f5d0 100644 --- a/homeassistant/components/gios/__init__.py +++ b/homeassistant/components/gios/__init__.py @@ -4,9 +4,14 @@ from __future__ import annotations import logging +from aiohttp.client_exceptions import ClientConnectorError +from gios import Gios +from gios.exceptions import GiosError + from homeassistant.components.air_quality import DOMAIN as AIR_QUALITY_PLATFORM from homeassistant.const import Platform from homeassistant.core import HomeAssistant +from homeassistant.exceptions import ConfigEntryNotReady from homeassistant.helpers import device_registry as dr, entity_registry as er from homeassistant.helpers.aiohttp_client import async_get_clientsession @@ -36,8 +41,12 @@ async def async_setup_entry(hass: HomeAssistant, entry: GiosConfigEntry) -> bool device_registry.async_update_device(device_entry.id, new_identifiers={new_ids}) websession = async_get_clientsession(hass) + try: + gios = await Gios.create(websession, station_id) + except (GiosError, ConnectionError, ClientConnectorError) as err: + raise ConfigEntryNotReady from err - coordinator = GiosDataUpdateCoordinator(hass, entry, websession, station_id) + coordinator = GiosDataUpdateCoordinator(hass, entry, gios) await coordinator.async_config_entry_first_refresh() entry.runtime_data = GiosData(coordinator) diff --git a/homeassistant/components/gios/config_flow.py b/homeassistant/components/gios/config_flow.py index a089aeab820..ecd0baee6f9 100644 --- a/homeassistant/components/gios/config_flow.py +++ b/homeassistant/components/gios/config_flow.py @@ -37,7 +37,7 @@ class GiosFlowHandler(ConfigFlow, domain=DOMAIN): websession = async_get_clientsession(self.hass) async with asyncio.timeout(API_TIMEOUT): - gios = Gios(user_input[CONF_STATION_ID], websession) + gios = await Gios.create(websession, user_input[CONF_STATION_ID]) await gios.async_update() assert gios.station_name is not None diff --git a/homeassistant/components/gios/const.py b/homeassistant/components/gios/const.py index a8490511ab8..2294e89c961 100644 --- a/homeassistant/components/gios/const.py +++ b/homeassistant/components/gios/const.py @@ -13,7 +13,7 @@ SCAN_INTERVAL: Final = timedelta(minutes=30) DOMAIN: Final = "gios" MANUFACTURER: Final = "Główny Inspektorat Ochrony Środowiska" -URL = "http://powietrze.gios.gov.pl/pjp/current/station_details/info/{station_id}" +URL = "https://powietrze.gios.gov.pl/pjp/current/station_details/info/{station_id}" API_TIMEOUT: Final = 30 diff --git a/homeassistant/components/gios/coordinator.py b/homeassistant/components/gios/coordinator.py index be4b41ca6ee..95f3b8af797 100644 --- a/homeassistant/components/gios/coordinator.py +++ b/homeassistant/components/gios/coordinator.py @@ -6,7 +6,6 @@ import asyncio from dataclasses import dataclass import logging -from aiohttp import ClientSession from aiohttp.client_exceptions import ClientConnectorError from gios import Gios from gios.exceptions import GiosError @@ -39,11 +38,10 @@ class GiosDataUpdateCoordinator(DataUpdateCoordinator[GiosSensors]): self, hass: HomeAssistant, config_entry: GiosConfigEntry, - session: ClientSession, - station_id: int, + gios: Gios, ) -> None: """Class to manage fetching GIOS data API.""" - self.gios = Gios(station_id, session) + self.gios = gios super().__init__( hass, diff --git a/homeassistant/components/gios/manifest.json b/homeassistant/components/gios/manifest.json index 3d2e719fab6..8deb2eee414 100644 --- a/homeassistant/components/gios/manifest.json +++ b/homeassistant/components/gios/manifest.json @@ -7,5 +7,5 @@ "integration_type": "service", "iot_class": "cloud_polling", "loggers": ["dacite", "gios"], - "requirements": ["gios==5.0.0"] + "requirements": ["gios==6.0.0"] } diff --git a/requirements_all.txt b/requirements_all.txt index 535f3eace46..7a600a83c07 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -1008,7 +1008,7 @@ georss-qld-bushfire-alert-client==0.8 getmac==0.9.5 # homeassistant.components.gios -gios==5.0.0 +gios==6.0.0 # homeassistant.components.gitter gitterpy==0.1.7 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index e27a33ce02f..fa66d8b0552 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -861,7 +861,7 @@ georss-qld-bushfire-alert-client==0.8 getmac==0.9.5 # homeassistant.components.gios -gios==5.0.0 +gios==6.0.0 # homeassistant.components.glances glances-api==0.8.0