From 32cea6b95d10ac21f53688809e45a28cea353e56 Mon Sep 17 00:00:00 2001 From: Diogo Gomes Date: Fri, 23 Sep 2022 15:23:33 +0100 Subject: [PATCH] Bump pyipma to 3.0.5 (#78936) * fix #78928 and review of #78332 * address comment --- homeassistant/components/ipma/__init__.py | 30 +++++++++------------ homeassistant/components/ipma/manifest.json | 2 +- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- 4 files changed, 16 insertions(+), 20 deletions(-) diff --git a/homeassistant/components/ipma/__init__.py b/homeassistant/components/ipma/__init__.py index 315362247a2..eec16a0c811 100644 --- a/homeassistant/components/ipma/__init__.py +++ b/homeassistant/components/ipma/__init__.py @@ -1,4 +1,5 @@ """Component for the Portuguese weather service - IPMA.""" +import asyncio import logging import async_timeout @@ -22,36 +23,31 @@ PLATFORMS = [Platform.WEATHER] _LOGGER = logging.getLogger(__name__) -async def async_get_api(hass): - """Get the pyipma api object.""" - websession = async_get_clientsession(hass) - return IPMA_API(websession) - - async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool: """Set up IPMA station as config entry.""" latitude = config_entry.data[CONF_LATITUDE] longitude = config_entry.data[CONF_LONGITUDE] - api = await async_get_api(hass) + api = IPMA_API(async_get_clientsession(hass)) + try: async with async_timeout.timeout(30): location = await Location.get(api, float(latitude), float(longitude)) - - _LOGGER.debug( - "Initializing for coordinates %s, %s -> station %s (%d, %d)", - latitude, - longitude, - location.station, - location.id_station, - location.global_id_local, - ) - except IPMAException as err: + except (IPMAException, asyncio.TimeoutError) as err: raise ConfigEntryNotReady( f"Could not get location for ({latitude},{longitude})" ) from err + _LOGGER.debug( + "Initializing for coordinates %s, %s -> station %s (%d, %d)", + latitude, + longitude, + location.station, + location.id_station, + location.global_id_local, + ) + hass.data.setdefault(DOMAIN, {}) hass.data[DOMAIN][config_entry.entry_id] = {DATA_API: api, DATA_LOCATION: location} diff --git a/homeassistant/components/ipma/manifest.json b/homeassistant/components/ipma/manifest.json index 23558600373..36dca71e957 100644 --- a/homeassistant/components/ipma/manifest.json +++ b/homeassistant/components/ipma/manifest.json @@ -3,7 +3,7 @@ "name": "Instituto Portugu\u00eas do Mar e Atmosfera (IPMA)", "config_flow": true, "documentation": "https://www.home-assistant.io/integrations/ipma", - "requirements": ["pyipma==3.0.4"], + "requirements": ["pyipma==3.0.5"], "codeowners": ["@dgomes", "@abmantis"], "iot_class": "cloud_polling", "loggers": ["geopy", "pyipma"] diff --git a/requirements_all.txt b/requirements_all.txt index 608c558b7ef..b809ca1a00f 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -1614,7 +1614,7 @@ pyinsteon==1.2.0 pyintesishome==1.8.0 # homeassistant.components.ipma -pyipma==3.0.4 +pyipma==3.0.5 # homeassistant.components.ipp pyipp==0.11.0 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index ffca40fe7da..f2b17378d31 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -1127,7 +1127,7 @@ pyicloud==1.0.0 pyinsteon==1.2.0 # homeassistant.components.ipma -pyipma==3.0.4 +pyipma==3.0.5 # homeassistant.components.ipp pyipp==0.11.0