Bump pyairvisual to 5.0.2 (#40554)
* Bump pyairvisual to 5.0.2 * Fix tests
This commit is contained in:
parent
0856c7292c
commit
f82ca44aac
8 changed files with 59 additions and 72 deletions
|
@ -1,7 +1,7 @@
|
|||
"""Define a config flow manager for AirVisual."""
|
||||
import asyncio
|
||||
|
||||
from pyairvisual import Client
|
||||
from pyairvisual import CloudAPI, NodeSamba
|
||||
from pyairvisual.errors import InvalidKeyError, NodeProError
|
||||
import voluptuous as vol
|
||||
|
||||
|
@ -108,7 +108,7 @@ class AirVisualFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
return self.async_abort(reason="already_configured")
|
||||
|
||||
websession = aiohttp_client.async_get_clientsession(self.hass)
|
||||
client = Client(session=websession, api_key=user_input[CONF_API_KEY])
|
||||
cloud_api = CloudAPI(user_input[CONF_API_KEY], session=websession)
|
||||
|
||||
# If this is the first (and only the first) time we've seen this API key, check
|
||||
# that it's valid:
|
||||
|
@ -120,7 +120,7 @@ class AirVisualFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
async with check_keys_lock:
|
||||
if user_input[CONF_API_KEY] not in checked_keys:
|
||||
try:
|
||||
await client.api.nearest_city()
|
||||
await cloud_api.air_quality.nearest_city()
|
||||
except InvalidKeyError:
|
||||
return self.async_show_form(
|
||||
step_id="geography",
|
||||
|
@ -157,16 +157,10 @@ class AirVisualFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
|
||||
await self._async_set_unique_id(user_input[CONF_IP_ADDRESS])
|
||||
|
||||
websession = aiohttp_client.async_get_clientsession(self.hass)
|
||||
client = Client(session=websession)
|
||||
node = NodeSamba(user_input[CONF_IP_ADDRESS], user_input[CONF_PASSWORD])
|
||||
|
||||
try:
|
||||
await client.node.from_samba(
|
||||
user_input[CONF_IP_ADDRESS],
|
||||
user_input[CONF_PASSWORD],
|
||||
include_history=False,
|
||||
include_trends=False,
|
||||
)
|
||||
await node.async_connect()
|
||||
except NodeProError as err:
|
||||
LOGGER.error("Error connecting to Node/Pro unit: %s", err)
|
||||
return self.async_show_form(
|
||||
|
@ -175,6 +169,8 @@ class AirVisualFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
errors={CONF_IP_ADDRESS: "unable_to_connect"},
|
||||
)
|
||||
|
||||
await node.async_disconnect()
|
||||
|
||||
return self.async_create_entry(
|
||||
title=f"Node/Pro ({user_input[CONF_IP_ADDRESS]})",
|
||||
data={**user_input, CONF_INTEGRATION_TYPE: INTEGRATION_TYPE_NODE_PRO},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue