From b7b23d949f550ff539d50e018c8f7380d691e2f2 Mon Sep 17 00:00:00 2001 From: "Dr. Drinovac" <52541649+RobertD502@users.noreply.github.com> Date: Thu, 17 Aug 2023 12:33:38 -0400 Subject: [PATCH 1/6] add timezone_error --- custom_components/petkit/translations/en.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/custom_components/petkit/translations/en.json b/custom_components/petkit/translations/en.json index f3e46cd..8af2326 100644 --- a/custom_components/petkit/translations/en.json +++ b/custom_components/petkit/translations/en.json @@ -10,7 +10,8 @@ "no_devices": "No devices found on account", "server_busy": "PetKit servers are busy. Please try again later.", "petkit_error": "Unknown error encountered. Please see Home Assistant logs for more details.", - "region_error": "Please select the country associated with your account." + "region_error": "Please select the country associated with your account.", + "timezone_error": "A timezone could not be found. If you are running Home Assistant as a standalone Docker container, you must define the TZ environmental variable." }, "step": { "user": { From a9bc4333e56d63d1de15439878b8e2dfe6e49871 Mon Sep 17 00:00:00 2001 From: "Dr. Drinovac" <52541649+RobertD502@users.noreply.github.com> Date: Thu, 17 Aug 2023 12:34:12 -0400 Subject: [PATCH 2/6] add timezone_error --- custom_components/petkit/translations/hr.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/custom_components/petkit/translations/hr.json b/custom_components/petkit/translations/hr.json index 60eb275..7f00452 100644 --- a/custom_components/petkit/translations/hr.json +++ b/custom_components/petkit/translations/hr.json @@ -10,7 +10,8 @@ "no_devices": "Na vašem računu nisu pronađeni uređaji", "server_busy": "PetKit serveri su zauzeti. Molimo pokušajte ponovo kasnije.", "petkit_error": "Došlo je do nepoznate pogreške. Za više detalja pogledajte Home Assistant zapisnike.", - "region_error": "Odaberite državu povezanu s vašim računom." + "region_error": "Odaberite državu povezanu s vašim računom.", + "timezone_error": "Vremenska zona nije pronađena. Ako pokrećete Home Assistant kao samostalni Docker spremnik, morate definirati TZ varijablu." }, "step": { "user": { From 45f6e1d64c761237d86db053a89706fea7b04ced Mon Sep 17 00:00:00 2001 From: "Dr. Drinovac" <52541649+RobertD502@users.noreply.github.com> Date: Thu, 17 Aug 2023 12:35:36 -0400 Subject: [PATCH 3/6] catch TimezoneError exception --- custom_components/petkit/config_flow.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/custom_components/petkit/config_flow.py b/custom_components/petkit/config_flow.py index f7a6d91..3dc5756 100644 --- a/custom_components/petkit/config_flow.py +++ b/custom_components/petkit/config_flow.py @@ -4,7 +4,7 @@ from collections.abc import Mapping from typing import Any -from petkitaio.exceptions import AuthError, PetKitError, RegionError, ServerError +from petkitaio.exceptions import AuthError, PetKitError, RegionError, ServerError, TimezoneError import voluptuous as vol from homeassistant import config_entries @@ -67,6 +67,8 @@ async def async_step_reauth_confirm( await async_validate_api(self.hass, email, password, region) except RegionError: errors["base"] = "region_error" + except TimezoneError: + errors["base"] = "timezone_error" except AuthError: errors["base"] = "invalid_auth" except ConnectionError: @@ -118,6 +120,8 @@ async def async_step_user( await async_validate_api(self.hass, email, password, region) except RegionError: errors["base"] = "region_error" + except TimezoneError: + errors["base"] = "timezone_error" except AuthError: errors["base"] = "invalid_auth" except ConnectionError: From 9789ba80dc1c36b3af54304d264dd21b5eb2e002 Mon Sep 17 00:00:00 2001 From: "Dr. Drinovac" <52541649+RobertD502@users.noreply.github.com> Date: Thu, 17 Aug 2023 12:36:40 -0400 Subject: [PATCH 4/6] catch TimezoneError exception --- custom_components/petkit/util.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/custom_components/petkit/util.py b/custom_components/petkit/util.py index 5244a2a..5799ee5 100644 --- a/custom_components/petkit/util.py +++ b/custom_components/petkit/util.py @@ -5,7 +5,7 @@ import async_timeout from petkitaio import PetKitClient -from petkitaio.exceptions import AuthError, PetKitError, RegionError, ServerError +from petkitaio.exceptions import AuthError, PetKitError, RegionError, ServerError, TimezoneError from homeassistant.core import HomeAssistant from homeassistant.helpers.aiohttp_client import async_get_clientsession @@ -23,13 +23,16 @@ async def async_validate_api(hass: HomeAssistant, email: str, password: str, reg region=region, timeout=TIMEOUT, ) - try: async with async_timeout.timeout(TIMEOUT): devices_query = await client.get_device_roster() except AuthError as err: LOGGER.error(f'Could not authenticate on PetKit servers: {err}') raise AuthError(err) + except TimezoneError: + error = 'A timezone could not be found. If you are running Home Assistant as a standalone Docker container, you must define the TZ environmental variable.' + LOGGER.error(f'{error}') + raise TimezoneError(error) except ServerError as err: LOGGER.error(f'PetKit servers are busy.Please try again later.') raise ServerError(err) From 46d51a13f63926953b544ae2632d0b737a5acb3c Mon Sep 17 00:00:00 2001 From: "Dr. Drinovac" <52541649+RobertD502@users.noreply.github.com> Date: Thu, 17 Aug 2023 12:37:23 -0400 Subject: [PATCH 5/6] bump integration and petkitaio to 0.1.9 --- custom_components/petkit/manifest.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/custom_components/petkit/manifest.json b/custom_components/petkit/manifest.json index 00e78c2..10e786c 100644 --- a/custom_components/petkit/manifest.json +++ b/custom_components/petkit/manifest.json @@ -11,8 +11,8 @@ "iot_class": "cloud_polling", "issue_tracker": "https://github.com/RobertD502/home-assistant-petkit/issues", "requirements": [ - "petkitaio==0.1.8", + "petkitaio==0.1.9", "tzlocal>=4.2" ], - "version": "0.1.8" + "version": "0.1.9" } From 001ad72d511e06aae65ea29f398d57a2f60f3c19 Mon Sep 17 00:00:00 2001 From: "Dr. Drinovac" <52541649+RobertD502@users.noreply.github.com> Date: Thu, 17 Aug 2023 12:38:05 -0400 Subject: [PATCH 6/6] add timezone_error --- custom_components/petkit/strings.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/custom_components/petkit/strings.json b/custom_components/petkit/strings.json index e1babcf..60dab3f 100644 --- a/custom_components/petkit/strings.json +++ b/custom_components/petkit/strings.json @@ -26,7 +26,8 @@ "no_devices": "No devices found on account", "server_busy": "PetKit servers are busy. Please try again later.", "petkit_error": "Unknown error encountered. Please see Home Assistant logs for more details.", - "region_error": "Please select the country associated with your account." + "region_error": "Please select the country associated with your account.", + "timezone_error": "A timezone could not be found. If you are running Home Assistant as a standalone Docker container, you must define the TZ environmental variable." }, "abort": { "already_configured": "PetKit account is already configured",