From a2b07eb84108ae87ef5cc193d982e5857fe4aeac Mon Sep 17 00:00:00 2001 From: Ludy87 Date: Sat, 24 Jun 2023 21:56:12 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=85=20add=20show=20dyndns=5Fupdate=5Flimi?= =?UTF-8?q?t?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ludy87 --- custom_components/ipv64/config_flow.py | 14 +++++++------- custom_components/ipv64/coordinator.py | 6 ++++-- custom_components/ipv64/manifest.json | 2 +- custom_components/ipv64/sensor.py | 2 ++ hacs.json | 2 +- 5 files changed, 15 insertions(+), 11 deletions(-) diff --git a/custom_components/ipv64/config_flow.py b/custom_components/ipv64/config_flow.py index 51c540c..b741efa 100644 --- a/custom_components/ipv64/config_flow.py +++ b/custom_components/ipv64/config_flow.py @@ -44,26 +44,26 @@ async def check_domain_login(hass: core.HomeAssistant, data: dict[str, str]): headers=headers, raise_for_status=True, ) - result = await resp.json() + result = dict(await resp.json()) except aiohttp.ClientResponseError as error: _LOGGER.error("Your 'Account Update Token' is incorrect. Error: %s | Status: %i", error.message, error.status) raise TokenError() from error - url_account_info = "https://ipv64.net/api.php?get_account_info" - async with async_timeout.timeout(TIMEOUT): + url_account_info = "https://ipv64.net/api.php?get_account_info" try: - resp = await session.get( + resp_account_info = await session.get( url_account_info, headers=headers, raise_for_status=True, ) - account_result = await resp.json() + account_result = await resp_account_info.json() if account_result["update_hash"] != data[CONF_API_KEY]: raise APIKeyError() - result["dyndns_update_limit"] = account_result["dyndns_update_limit"] + result.update({"dyndns_update_limit": account_result["account_class"]["dyndns_update_limit"]}) except aiohttp.ClientResponseError as error: _LOGGER.error("Your 'API Key' is incorrect. Error: %s | Status: %i", error.message, error.status) raise APIKeyError() from error + _LOGGER.debug(result) return result @@ -113,7 +113,7 @@ async def async_step_user(self, user_input=None): CONF_DOMAIN: user_input[CONF_DOMAIN], CONF_API_KEY: user_input[CONF_API_KEY], CONF_TOKEN: user_input[CONF_TOKEN], - "dyndns_update_limit": info["dyndns_update_limit"], + "dyndns_update_limit": info["data"]["dyndns_update_limit"], }, options={CONF_SCAN_INTERVAL: user_input[CONF_SCAN_INTERVAL]}, ) diff --git a/custom_components/ipv64/coordinator.py b/custom_components/ipv64/coordinator.py index 57bda68..44730cd 100644 --- a/custom_components/ipv64/coordinator.py +++ b/custom_components/ipv64/coordinator.py @@ -66,7 +66,7 @@ async def _async_update_data(self): result = await resp.json() result_dict = { "wildcard": result["subdomains"][self.config_entry.data[CONF_DOMAIN]]["wildcard"], - "updates": result["subdomains"][self.config_entry.data[CONF_DOMAIN]]["updates"], + "updates": f"{result['subdomains'][self.config_entry.data[CONF_DOMAIN]]['updates']}/{self.config_entry.data['dyndns_update_limit']}", CONF_IP_ADDRESS: result["subdomains"][self.config_entry.data[CONF_DOMAIN]]["records"][0]["content"], "last_update": result["subdomains"][self.config_entry.data[CONF_DOMAIN]]["records"][0]["last_update"], } @@ -75,7 +75,9 @@ async def _async_update_data(self): errors = { "Account Update Token": "incorrect", "wildcard": self.data["wildcard"] if self.data and "wildcard" in self.data else "unlivable", - "updates": self.data["updates"] if self.data and "updates" in self.data else "unlivable", + "updates": f"{self.data['updates']}/{self.data['dyndns_update_limit']}" + if self.data and "updates" in self.data and "dyndns_update_limit" in self.data + else "unlivable", CONF_IP_ADDRESS: self.data[CONF_IP_ADDRESS] if self.data and CONF_IP_ADDRESS in self.data else "unlivable", diff --git a/custom_components/ipv64/manifest.json b/custom_components/ipv64/manifest.json index f669e76..9ae98a7 100644 --- a/custom_components/ipv64/manifest.json +++ b/custom_components/ipv64/manifest.json @@ -11,5 +11,5 @@ "iot_class": "local_polling", "issue_tracker": "https://github.com/Ludy87/ipv64/issues", "requirements": [], - "version": "1.0.0" + "version": "1.1.0" } \ No newline at end of file diff --git a/custom_components/ipv64/sensor.py b/custom_components/ipv64/sensor.py index 40aa00c..edcfe5f 100644 --- a/custom_components/ipv64/sensor.py +++ b/custom_components/ipv64/sensor.py @@ -62,6 +62,8 @@ async def update(self): class IPv64Sensor(IPv64BaseEntity, SensorEntity): """Sensor entity class for IPv64.""" + _attr_icon = "mdi:ip" + def __init__( self, coordinator: IPv64DataUpdateCoordinator, diff --git a/hacs.json b/hacs.json index 5848ed2..210fef0 100644 --- a/hacs.json +++ b/hacs.json @@ -2,6 +2,6 @@ "name": "IPv64", "country": ["DE", "US"], "render_readme": true, - "homeassistant": "2023.6.1", + "homeassistant": "2023.6.3", "hacs": "1.32.1" } \ No newline at end of file