Migrate OpenWeaterMap to new library (support API 3.0) (#116870)
Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
parent
5bca9d142c
commit
24d31924a0
14 changed files with 580 additions and 523 deletions
20
homeassistant/components/openweathermap/utils.py
Normal file
20
homeassistant/components/openweathermap/utils.py
Normal file
|
@ -0,0 +1,20 @@
|
|||
"""Util functions for OpenWeatherMap."""
|
||||
|
||||
from pyopenweathermap import OWMClient, RequestError
|
||||
|
||||
|
||||
async def validate_api_key(api_key, mode):
|
||||
"""Validate API key."""
|
||||
api_key_valid = None
|
||||
errors, description_placeholders = {}, {}
|
||||
try:
|
||||
owm_client = OWMClient(api_key, mode)
|
||||
api_key_valid = await owm_client.validate_key()
|
||||
except RequestError as error:
|
||||
errors["base"] = "cannot_connect"
|
||||
description_placeholders["error"] = str(error)
|
||||
|
||||
if api_key_valid is False:
|
||||
errors["base"] = "invalid_api_key"
|
||||
|
||||
return errors, description_placeholders
|
Loading…
Add table
Add a link
Reference in a new issue