Add common strings in daikin config flow (#41419)
This commit is contained in:
parent
cf83c6bf00
commit
f42eca3fcf
5 changed files with 21 additions and 22 deletions
|
@ -9,7 +9,7 @@ from pydaikin.daikin_base import Appliance
|
|||
import voluptuous as vol
|
||||
|
||||
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
|
||||
from homeassistant.const import CONF_HOST, CONF_HOSTS, CONF_PASSWORD
|
||||
from homeassistant.const import CONF_API_KEY, CONF_HOST, CONF_HOSTS, CONF_PASSWORD
|
||||
from homeassistant.exceptions import ConfigEntryNotReady
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC
|
||||
|
@ -17,7 +17,7 @@ from homeassistant.helpers.typing import HomeAssistantType
|
|||
from homeassistant.util import Throttle
|
||||
|
||||
from . import config_flow # noqa: F401
|
||||
from .const import CONF_KEY, CONF_UUID, KEY_MAC, TIMEOUT
|
||||
from .const import CONF_UUID, KEY_MAC, TIMEOUT
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
@ -77,7 +77,7 @@ async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry):
|
|||
daikin_api = await daikin_api_setup(
|
||||
hass,
|
||||
conf[CONF_HOST],
|
||||
conf.get(CONF_KEY),
|
||||
conf.get(CONF_API_KEY),
|
||||
conf.get(CONF_UUID),
|
||||
conf.get(CONF_PASSWORD),
|
||||
)
|
||||
|
|
|
@ -10,9 +10,9 @@ from pydaikin.discovery import Discovery
|
|||
import voluptuous as vol
|
||||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.const import CONF_HOST, CONF_PASSWORD
|
||||
from homeassistant.const import CONF_API_KEY, CONF_HOST, CONF_PASSWORD
|
||||
|
||||
from .const import CONF_KEY, CONF_UUID, KEY_IP, KEY_MAC, TIMEOUT
|
||||
from .const import CONF_UUID, KEY_IP, KEY_MAC, TIMEOUT
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
@ -34,7 +34,7 @@ class FlowHandler(config_entries.ConfigFlow):
|
|||
return vol.Schema(
|
||||
{
|
||||
vol.Required(CONF_HOST, default=self.host): str,
|
||||
vol.Optional(CONF_KEY): str,
|
||||
vol.Optional(CONF_API_KEY): str,
|
||||
vol.Optional(CONF_PASSWORD): str,
|
||||
}
|
||||
)
|
||||
|
@ -50,7 +50,7 @@ class FlowHandler(config_entries.ConfigFlow):
|
|||
data={
|
||||
CONF_HOST: host,
|
||||
KEY_MAC: mac,
|
||||
CONF_KEY: key,
|
||||
CONF_API_KEY: key,
|
||||
CONF_UUID: uuid,
|
||||
CONF_PASSWORD: password,
|
||||
},
|
||||
|
@ -81,27 +81,27 @@ class FlowHandler(config_entries.ConfigFlow):
|
|||
return self.async_show_form(
|
||||
step_id="user",
|
||||
data_schema=self.schema,
|
||||
errors={"base": "device_timeout"},
|
||||
errors={"base": "cannot_connect"},
|
||||
)
|
||||
except web_exceptions.HTTPForbidden:
|
||||
return self.async_show_form(
|
||||
step_id="user",
|
||||
data_schema=self.schema,
|
||||
errors={"base": "forbidden"},
|
||||
errors={"base": "invalid_auth"},
|
||||
)
|
||||
except ClientError:
|
||||
_LOGGER.exception("ClientError")
|
||||
return self.async_show_form(
|
||||
step_id="user",
|
||||
data_schema=self.schema,
|
||||
errors={"base": "device_fail"},
|
||||
errors={"base": "unknown"},
|
||||
)
|
||||
except Exception: # pylint: disable=broad-except
|
||||
_LOGGER.exception("Unexpected error creating device")
|
||||
return self.async_show_form(
|
||||
step_id="user",
|
||||
data_schema=self.schema,
|
||||
errors={"base": "device_fail"},
|
||||
errors={"base": "unknown"},
|
||||
)
|
||||
|
||||
mac = device.mac
|
||||
|
@ -113,7 +113,7 @@ class FlowHandler(config_entries.ConfigFlow):
|
|||
return self.async_show_form(step_id="user", data_schema=self.schema)
|
||||
return await self._create_device(
|
||||
user_input[CONF_HOST],
|
||||
user_input.get(CONF_KEY),
|
||||
user_input.get(CONF_API_KEY),
|
||||
user_input.get(CONF_PASSWORD),
|
||||
)
|
||||
|
||||
|
|
|
@ -76,7 +76,6 @@ SENSOR_TYPES = {
|
|||
},
|
||||
}
|
||||
|
||||
CONF_KEY = "key"
|
||||
CONF_UUID = "uuid"
|
||||
|
||||
KEY_MAC = "mac"
|
||||
|
|
|
@ -3,10 +3,10 @@
|
|||
"step": {
|
||||
"user": {
|
||||
"title": "Configure Daikin AC",
|
||||
"description": "Enter IP address of your Daikin AC.\n\nNote that [%key:common::config_flow::data::api_key%] and [%key:common::config_flow::data::password%] are used by BRP072Cxx and SKYFi devices respectively.",
|
||||
"description": "Enter [%key:common::config_flow::data::ip%] of your Daikin AC.\n\nNote that [%key:common::config_flow::data::api_key%] and [%key:common::config_flow::data::password%] only are used by BRP072Cxx and SKYFi devices respectively.",
|
||||
"data": {
|
||||
"host": "[%key:common::config_flow::data::host%]",
|
||||
"key": "[%key:common::config_flow::data::api_key%]",
|
||||
"api_key": "[%key:common::config_flow::data::api_key%]",
|
||||
"password": "[%key:common::config_flow::data::password%]"
|
||||
}
|
||||
}
|
||||
|
@ -16,9 +16,9 @@
|
|||
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]"
|
||||
},
|
||||
"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%]"
|
||||
"unknown": "[%key:common::config_flow::error::unknown%]",
|
||||
"invalid_auth": "[%key:common::config_flow::error::invalid_auth%]",
|
||||
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -109,10 +109,10 @@ async def test_import(hass, mock_daikin):
|
|||
@pytest.mark.parametrize(
|
||||
"s_effect,reason",
|
||||
[
|
||||
(asyncio.TimeoutError, "device_timeout"),
|
||||
(HTTPForbidden, "forbidden"),
|
||||
(ClientError, "device_fail"),
|
||||
(Exception, "device_fail"),
|
||||
(asyncio.TimeoutError, "cannot_connect"),
|
||||
(HTTPForbidden, "invalid_auth"),
|
||||
(ClientError, "unknown"),
|
||||
(Exception, "unknown"),
|
||||
],
|
||||
)
|
||||
async def test_device_abort(hass, mock_daikin, s_effect, reason):
|
||||
|
|
Loading…
Add table
Reference in a new issue