From 40ceb29869961f3c12453610012245b0cf270268 Mon Sep 17 00:00:00 2001 From: golles Date: Sat, 11 Dec 2021 22:48:58 +0100 Subject: [PATCH] 1.1.3, fixes related to the HA 2021.12 release Updated config flow from upstream --- custom_components/knmi/api.py | 2 +- custom_components/knmi/config_flow.py | 17 +++++++++++------ custom_components/knmi/const.py | 2 +- custom_components/knmi/entity.py | 5 +++-- custom_components/knmi/manifest.json | 2 +- 5 files changed, 17 insertions(+), 11 deletions(-) diff --git a/custom_components/knmi/api.py b/custom_components/knmi/api.py index b7e42e5..6e12043 100644 --- a/custom_components/knmi/api.py +++ b/custom_components/knmi/api.py @@ -30,7 +30,7 @@ async def async_get_data(self) -> dict: async def api_wrapper(self, method: str, url: str) -> dict: """Get information from the API.""" try: - async with async_timeout.timeout(TIMEOUT, loop=asyncio.get_event_loop()): + async with async_timeout.timeout(TIMEOUT): if method == "get": response = await self._session.get(url) # The API has no proper error handling for a wrong API key. diff --git a/custom_components/knmi/config_flow.py b/custom_components/knmi/config_flow.py index dea67e6..8dda9bc 100644 --- a/custom_components/knmi/config_flow.py +++ b/custom_components/knmi/config_flow.py @@ -46,6 +46,13 @@ async def async_step_user(self, user_input=None): return await self._show_config_form(user_input) + user_input = {} + # Provide defaults for form + user_input[CONF_API_KEY] = "" + user_input[CONF_LATITUDE] = self.hass.config.latitude + user_input[CONF_LONGITUDE] = self.hass.config.longitude + user_input[CONF_NAME] = self.hass.config.location_name + return await self._show_config_form(user_input) @staticmethod @@ -59,16 +66,14 @@ async def _show_config_form(self, user_input): # pylint: disable=unused-argumen step_id="user", data_schema=vol.Schema( { + vol.Required(CONF_NAME, default=user_input[CONF_NAME]): str, vol.Required( - CONF_NAME, default=self.hass.config.location_name - ): str, - vol.Required( - CONF_LATITUDE, default=self.hass.config.latitude + CONF_LATITUDE, default=user_input[CONF_LATITUDE] ): cv.latitude, vol.Required( - CONF_LONGITUDE, default=self.hass.config.longitude + CONF_LONGITUDE, default=user_input[CONF_LONGITUDE] ): cv.longitude, - vol.Required(CONF_API_KEY): str, + vol.Required(CONF_API_KEY, default=user_input[CONF_API_KEY]): str, } ), errors=self._errors, diff --git a/custom_components/knmi/const.py b/custom_components/knmi/const.py index 7a372ba..ec20534 100644 --- a/custom_components/knmi/const.py +++ b/custom_components/knmi/const.py @@ -16,7 +16,7 @@ # Base component constants. NAME = "KNMI" DOMAIN = "knmi" -VERSION = "1.1.2" +VERSION = "1.1.3" ATTRIBUTION = "KNMI Weergegevens via https://weerlive.nl/" # Platforms. diff --git a/custom_components/knmi/entity.py b/custom_components/knmi/entity.py index c900f14..78ebeb2 100644 --- a/custom_components/knmi/entity.py +++ b/custom_components/knmi/entity.py @@ -1,4 +1,5 @@ """KnmiEntity class""" +from homeassistant.helpers.device_registry import DeviceEntryType from homeassistant.helpers.update_coordinator import CoordinatorEntity from .const import DOMAIN, NAME, VERSION, ATTRIBUTION @@ -21,12 +22,12 @@ def device_info(self): "name": NAME, "model": VERSION, "manufacturer": NAME, - "entry_type": "service", + "entry_type": DeviceEntryType.SERVICE, "configuration_url": "http://weerlive.nl/api/toegang/account.php", } @property - def device_state_attributes(self): + def extra_state_attributes(self): """Return the state attributes.""" return { "attribution": ATTRIBUTION, diff --git a/custom_components/knmi/manifest.json b/custom_components/knmi/manifest.json index 2a77c14..24244f8 100644 --- a/custom_components/knmi/manifest.json +++ b/custom_components/knmi/manifest.json @@ -4,7 +4,7 @@ "documentation": "https://github.com/golles/ha-knmi/", "iot_class": "cloud_polling", "issue_tracker": "https://github.com/golles/ha-knmi//issues", - "version": "1.1.2", + "version": "1.1.3", "config_flow": true, "codeowners": [ "@golles"