Skip to content

Commit

Permalink
Merge pull request #33 from RobertD502/tz_exception
Browse files Browse the repository at this point in the history
Catch TimezoneError exception
  • Loading branch information
RobertD502 authored Aug 17, 2023
2 parents 78ac0d9 + 001ad72 commit 93d14ee
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 8 deletions.
6 changes: 5 additions & 1 deletion custom_components/petkit/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions custom_components/petkit/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
3 changes: 2 additions & 1 deletion custom_components/petkit/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion custom_components/petkit/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
3 changes: 2 additions & 1 deletion custom_components/petkit/translations/hr.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
7 changes: 5 additions & 2 deletions custom_components/petkit/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit 93d14ee

Please sign in to comment.