Axis - Improve discovery title by adding placeholder support (#27663)

* Improve discovery title by adding placeholder support
pull/27937/head
Robert Svensson 2019-10-16 20:45:03 +02:00 committed by GitHub
parent 0607a30612
commit 6ffc520b1c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 0 deletions

View File

@ -12,6 +12,7 @@
"device_unavailable": "Device is not available", "device_unavailable": "Device is not available",
"faulty_credentials": "Bad user credentials" "faulty_credentials": "Bad user credentials"
}, },
"flow_title": "Axis device: {name} ({host})",
"step": { "step": {
"user": { "user": {
"data": { "data": {

View File

@ -191,6 +191,12 @@ class AxisFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
load_json, self.hass.config.path(CONFIG_FILE) load_json, self.hass.config.path(CONFIG_FILE)
) )
# pylint: disable=no-member # https://github.com/PyCQA/pylint/issues/3167
self.context["title_placeholders"] = {
"name": discovery_info["hostname"][:-7],
"host": discovery_info[CONF_HOST],
}
if serialnumber not in config_file: if serialnumber not in config_file:
self.discovery_schema = { self.discovery_schema = {
vol.Required(CONF_HOST, default=discovery_info[CONF_HOST]): str, vol.Required(CONF_HOST, default=discovery_info[CONF_HOST]): str,
@ -198,6 +204,7 @@ class AxisFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
vol.Required(CONF_PASSWORD): str, vol.Required(CONF_PASSWORD): str,
vol.Required(CONF_PORT, default=discovery_info[CONF_PORT]): int, vol.Required(CONF_PORT, default=discovery_info[CONF_PORT]): int,
} }
return await self.async_step_user() return await self.async_step_user()
try: try:

View File

@ -1,6 +1,7 @@
{ {
"config": { "config": {
"title": "Axis device", "title": "Axis device",
"flow_title": "Axis device: {name} ({host})",
"step": { "step": {
"user": { "user": {
"title": "Set up Axis device", "title": "Set up Axis device",

View File

@ -186,6 +186,7 @@ async def test_zeroconf_flow(hass):
data={ data={
config_flow.CONF_HOST: "1.2.3.4", config_flow.CONF_HOST: "1.2.3.4",
config_flow.CONF_PORT: 80, config_flow.CONF_PORT: 80,
"hostname": "name",
"properties": {"macaddress": "00408C12345"}, "properties": {"macaddress": "00408C12345"},
}, },
context={"source": "zeroconf"}, context={"source": "zeroconf"},
@ -319,6 +320,7 @@ async def test_zeroconf_flow_bad_config_file(hass):
config_flow.DOMAIN, config_flow.DOMAIN,
data={ data={
config_flow.CONF_HOST: "1.2.3.4", config_flow.CONF_HOST: "1.2.3.4",
"hostname": "name",
"properties": {"macaddress": "00408C12345"}, "properties": {"macaddress": "00408C12345"},
}, },
context={"source": "zeroconf"}, context={"source": "zeroconf"},