Bump pydaikin to 2.0.1, catch HTTPForbidden exception (#35466)
This commit is contained in:
1 parent
3de4bc56b5
commit
93f8d21bc0
6 files changed
+60
-35
No files matched your search
@@ -3,7 +3,7 @@ import asyncio
|
||||
import logging
|
||||
from uuid import uuid4
|
||||
|
||||
from aiohttp import ClientError
|
||||
from aiohttp import ClientError, web_exceptions
|
||||
from async_timeout import timeout
|
||||
from pydaikin.daikin_base import Appliance
|
||||
import voluptuous as vol
|
||||
@@ -15,6 +15,14 @@ from .const import CONF_KEY, CONF_UUID, KEY_IP, KEY_MAC, TIMEOUT
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
DATA_SCHEMA = vol.Schema(
|
||||
{
|
||||
vol.Required(CONF_HOST): str,
|
||||
vol.Optional(CONF_KEY): str,
|
||||
vol.Optional(CONF_PASSWORD): str,
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@config_entries.HANDLERS.register("daikin")
|
||||
class FlowHandler(config_entries.ConfigFlow):
|
||||
@@ -43,7 +51,6 @@ class FlowHandler(config_entries.ConfigFlow):
|
||||
|
||||
async def _create_device(self, host, key=None, password=None):
|
||||
"""Create device."""
|
||||
|
||||
# BRP07Cxx devices needs uuid together with key
|
||||
if key:
|
||||
uuid = str(uuid4())
|
||||
@@ -64,13 +71,25 @@ class FlowHandler(config_entries.ConfigFlow):
|
||||
password=password,
|
||||
)
|
||||
except asyncio.TimeoutError:
|
||||
return self.async_abort(reason="device_timeout")
|
||||
return self.async_show_form(
|
||||
step_id="user",
|
||||
data_schema=DATA_SCHEMA,
|
||||
errors={"base": "device_timeout"},
|
||||
)
|
||||
except web_exceptions.HTTPForbidden:
|
||||
return self.async_show_form(
|
||||
step_id="user", data_schema=DATA_SCHEMA, errors={"base": "forbidden"},
|
||||
)
|
||||
except ClientError:
|
||||
_LOGGER.exception("ClientError")
|
||||
return self.async_abort(reason="device_fail")
|
||||
return self.async_show_form(
|
||||
step_id="user", data_schema=DATA_SCHEMA, errors={"base": "device_fail"},
|
||||
)
|
||||
except Exception: # pylint: disable=broad-except
|
||||
_LOGGER.exception("Unexpected error creating device")
|
||||
return self.async_abort(reason="device_fail")
|
||||
return self.async_show_form(
|
||||
step_id="user", data_schema=DATA_SCHEMA, errors={"base": "device_fail"},
|
||||
)
|
||||
|
||||
mac = device.mac
|
||||
return self._create_entry(host, mac, key, uuid, password)
|
||||
@@ -78,16 +97,7 @@ class FlowHandler(config_entries.ConfigFlow):
|
||||
async def async_step_user(self, user_input=None):
|
||||
"""User initiated config flow."""
|
||||
if user_input is None:
|
||||
return self.async_show_form(
|
||||
step_id="user",
|
||||
data_schema=vol.Schema(
|
||||
{
|
||||
vol.Required(CONF_HOST): str,
|
||||
vol.Optional(CONF_KEY): str,
|
||||
vol.Optional(CONF_PASSWORD): str,
|
||||
}
|
||||
),
|
||||
)
|
||||
return self.async_show_form(step_id="user", data_schema=DATA_SCHEMA,)
|
||||
return await self._create_device(
|
||||
user_input[CONF_HOST],
|
||||
user_input.get(CONF_KEY),
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
"name": "Daikin AC",
|
||||
"config_flow": true,
|
||||
"documentation": "https://www.home-assistant.io/integrations/daikin",
|
||||
"requirements": ["pydaikin==2.0.0"],
|
||||
"requirements": ["pydaikin==2.0.1"],
|
||||
"codeowners": ["@fredrike"],
|
||||
"quality_scale": "platinum"
|
||||
}
|
||||
@@ -5,16 +5,19 @@
|
||||
"title": "Configure Daikin AC",
|
||||
"description": "Enter IP address of your Daikin AC.",
|
||||
"data": {
|
||||
"host": "Host",
|
||||
"key": "Authentication key (only used by BRP072C/Zena devices)",
|
||||
"password": "Device password (only used by SKYFi devices)"
|
||||
}
|
||||
"host": "[%key:common::config_flow::data::host%]",
|
||||
"key": "[%key:common::config_flow::data::api_key%]",
|
||||
"password": "[%key:common::config_flow::data::password%]"
|
||||
}
|
||||
}
|
||||
},
|
||||
"abort": {
|
||||
"device_timeout": "Timeout connecting to the device.",
|
||||
"device_fail": "Unexpected error creating device.",
|
||||
"already_configured": "Device is already configured"
|
||||
"already_configured": "[%key:common::config_flow::abort::already_configured_device%]"
|
||||
},
|
||||
"error": {
|
||||
"device_fail": "[%key:common::config_flow::error::unknown%]",
|
||||
"forbidden": "[%key:common::config_flow::error::invalid_auth%]",
|
||||
"device_timeout": "[%key:common::config_flow::error::cannot_connect%]"
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user