Prettier Zeroconf discovery name for Axis devices (#45216)
* Change zeroconf name to be based of prettier name rather than hostname to help user understand what device is discovered Have a full zeroconf discovery message in tests Clean up unusued globals * Use non-formatted serial number for config entry title as well
This commit is contained in:
parent
8151721fbc
commit
3cc45697cb
4 changed files with 24 additions and 27 deletions
|
@ -29,15 +29,6 @@ from .device import get_device
|
||||||
from .errors import AuthenticationRequired, CannotConnect
|
from .errors import AuthenticationRequired, CannotConnect
|
||||||
|
|
||||||
AXIS_OUI = {"00:40:8c", "ac:cc:8e", "b8:a4:4f"}
|
AXIS_OUI = {"00:40:8c", "ac:cc:8e", "b8:a4:4f"}
|
||||||
|
|
||||||
CONFIG_FILE = "axis.conf"
|
|
||||||
|
|
||||||
EVENT_TYPES = ["motion", "vmd3", "pir", "sound", "daynight", "tampering", "input"]
|
|
||||||
|
|
||||||
PLATFORMS = ["camera"]
|
|
||||||
|
|
||||||
AXIS_INCLUDE = EVENT_TYPES + PLATFORMS
|
|
||||||
|
|
||||||
DEFAULT_PORT = 80
|
DEFAULT_PORT = 80
|
||||||
|
|
||||||
|
|
||||||
|
@ -58,6 +49,7 @@ class AxisFlowHandler(config_entries.ConfigFlow, domain=AXIS_DOMAIN):
|
||||||
self.device_config = {}
|
self.device_config = {}
|
||||||
self.discovery_schema = {}
|
self.discovery_schema = {}
|
||||||
self.import_schema = {}
|
self.import_schema = {}
|
||||||
|
self.serial = None
|
||||||
|
|
||||||
async def async_step_user(self, user_input=None):
|
async def async_step_user(self, user_input=None):
|
||||||
"""Handle a Axis config flow start.
|
"""Handle a Axis config flow start.
|
||||||
|
@ -76,7 +68,8 @@ class AxisFlowHandler(config_entries.ConfigFlow, domain=AXIS_DOMAIN):
|
||||||
password=user_input[CONF_PASSWORD],
|
password=user_input[CONF_PASSWORD],
|
||||||
)
|
)
|
||||||
|
|
||||||
await self.async_set_unique_id(format_mac(device.vapix.serial_number))
|
self.serial = device.vapix.serial_number
|
||||||
|
await self.async_set_unique_id(format_mac(self.serial))
|
||||||
|
|
||||||
self._abort_if_unique_id_configured(
|
self._abort_if_unique_id_configured(
|
||||||
updates={
|
updates={
|
||||||
|
@ -135,7 +128,7 @@ class AxisFlowHandler(config_entries.ConfigFlow, domain=AXIS_DOMAIN):
|
||||||
|
|
||||||
self.device_config[CONF_NAME] = name
|
self.device_config[CONF_NAME] = name
|
||||||
|
|
||||||
title = f"{model} - {self.unique_id}"
|
title = f"{model} - {self.serial}"
|
||||||
return self.async_create_entry(title=title, data=self.device_config)
|
return self.async_create_entry(title=title, data=self.device_config)
|
||||||
|
|
||||||
async def async_step_dhcp(self, discovery_info: dict):
|
async def async_step_dhcp(self, discovery_info: dict):
|
||||||
|
@ -155,7 +148,7 @@ class AxisFlowHandler(config_entries.ConfigFlow, domain=AXIS_DOMAIN):
|
||||||
{
|
{
|
||||||
CONF_HOST: discovery_info[CONF_HOST],
|
CONF_HOST: discovery_info[CONF_HOST],
|
||||||
CONF_MAC: format_mac(discovery_info["properties"]["macaddress"]),
|
CONF_MAC: format_mac(discovery_info["properties"]["macaddress"]),
|
||||||
CONF_NAME: discovery_info["hostname"][:-7],
|
CONF_NAME: discovery_info["name"].split(".", 1)[0],
|
||||||
CONF_PORT: discovery_info[CONF_PORT],
|
CONF_PORT: discovery_info[CONF_PORT],
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"config": {
|
"config": {
|
||||||
"flow_title": "Axis device: {name} ({host})",
|
"flow_title": "{name} ({host})",
|
||||||
"step": {
|
"step": {
|
||||||
"user": {
|
"user": {
|
||||||
"title": "Set up Axis device",
|
"title": "Set up Axis device",
|
||||||
|
|
|
@ -33,7 +33,6 @@ from homeassistant.data_entry_flow import (
|
||||||
)
|
)
|
||||||
|
|
||||||
from .test_device import (
|
from .test_device import (
|
||||||
FORMATTED_MAC,
|
|
||||||
MAC,
|
MAC,
|
||||||
MODEL,
|
MODEL,
|
||||||
NAME,
|
NAME,
|
||||||
|
@ -68,7 +67,7 @@ async def test_flow_manual_configuration(hass):
|
||||||
)
|
)
|
||||||
|
|
||||||
assert result["type"] == RESULT_TYPE_CREATE_ENTRY
|
assert result["type"] == RESULT_TYPE_CREATE_ENTRY
|
||||||
assert result["title"] == f"M1065-LW - {FORMATTED_MAC}"
|
assert result["title"] == f"M1065-LW - {MAC}"
|
||||||
assert result["data"] == {
|
assert result["data"] == {
|
||||||
CONF_HOST: "1.2.3.4",
|
CONF_HOST: "1.2.3.4",
|
||||||
CONF_USERNAME: "user",
|
CONF_USERNAME: "user",
|
||||||
|
@ -225,7 +224,7 @@ async def test_flow_create_entry_multiple_existing_entries_of_same_model(hass):
|
||||||
)
|
)
|
||||||
|
|
||||||
assert result["type"] == RESULT_TYPE_CREATE_ENTRY
|
assert result["type"] == RESULT_TYPE_CREATE_ENTRY
|
||||||
assert result["title"] == f"M1065-LW - {FORMATTED_MAC}"
|
assert result["title"] == f"M1065-LW - {MAC}"
|
||||||
assert result["data"] == {
|
assert result["data"] == {
|
||||||
CONF_HOST: "1.2.3.4",
|
CONF_HOST: "1.2.3.4",
|
||||||
CONF_USERNAME: "user",
|
CONF_USERNAME: "user",
|
||||||
|
@ -266,7 +265,7 @@ async def test_dhcp_flow(hass):
|
||||||
)
|
)
|
||||||
|
|
||||||
assert result["type"] == RESULT_TYPE_CREATE_ENTRY
|
assert result["type"] == RESULT_TYPE_CREATE_ENTRY
|
||||||
assert result["title"] == f"M1065-LW - {FORMATTED_MAC}"
|
assert result["title"] == f"M1065-LW - {MAC}"
|
||||||
assert result["data"] == {
|
assert result["data"] == {
|
||||||
CONF_HOST: "1.2.3.4",
|
CONF_HOST: "1.2.3.4",
|
||||||
CONF_USERNAME: "user",
|
CONF_USERNAME: "user",
|
||||||
|
@ -376,10 +375,15 @@ async def test_zeroconf_flow(hass):
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
AXIS_DOMAIN,
|
AXIS_DOMAIN,
|
||||||
data={
|
data={
|
||||||
CONF_HOST: "1.2.3.4",
|
"host": "1.2.3.4",
|
||||||
CONF_PORT: 80,
|
"port": 80,
|
||||||
"hostname": "name",
|
"hostname": f"axis-{MAC.lower()}.local.",
|
||||||
"properties": {"macaddress": MAC},
|
"type": "_axis-video._tcp.local.",
|
||||||
|
"name": f"AXIS M1065-L - {MAC}._axis-video._tcp.local.",
|
||||||
|
"properties": {
|
||||||
|
"_raw": {"macaddress": MAC.encode()},
|
||||||
|
"macaddress": MAC,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
context={"source": SOURCE_ZEROCONF},
|
context={"source": SOURCE_ZEROCONF},
|
||||||
)
|
)
|
||||||
|
@ -400,7 +404,7 @@ async def test_zeroconf_flow(hass):
|
||||||
)
|
)
|
||||||
|
|
||||||
assert result["type"] == RESULT_TYPE_CREATE_ENTRY
|
assert result["type"] == RESULT_TYPE_CREATE_ENTRY
|
||||||
assert result["title"] == f"M1065-LW - {FORMATTED_MAC}"
|
assert result["title"] == f"M1065-LW - {MAC}"
|
||||||
assert result["data"] == {
|
assert result["data"] == {
|
||||||
CONF_HOST: "1.2.3.4",
|
CONF_HOST: "1.2.3.4",
|
||||||
CONF_USERNAME: "user",
|
CONF_USERNAME: "user",
|
||||||
|
@ -424,7 +428,7 @@ async def test_zeroconf_flow_already_configured(hass):
|
||||||
data={
|
data={
|
||||||
CONF_HOST: "1.2.3.4",
|
CONF_HOST: "1.2.3.4",
|
||||||
CONF_PORT: 80,
|
CONF_PORT: 80,
|
||||||
"hostname": "name",
|
"name": "name",
|
||||||
"properties": {"macaddress": MAC},
|
"properties": {"macaddress": MAC},
|
||||||
},
|
},
|
||||||
context={"source": SOURCE_ZEROCONF},
|
context={"source": SOURCE_ZEROCONF},
|
||||||
|
@ -459,7 +463,7 @@ async def test_zeroconf_flow_updated_configuration(hass):
|
||||||
data={
|
data={
|
||||||
CONF_HOST: "2.3.4.5",
|
CONF_HOST: "2.3.4.5",
|
||||||
CONF_PORT: 8080,
|
CONF_PORT: 8080,
|
||||||
"hostname": "name",
|
"name": "name",
|
||||||
"properties": {"macaddress": MAC},
|
"properties": {"macaddress": MAC},
|
||||||
},
|
},
|
||||||
context={"source": SOURCE_ZEROCONF},
|
context={"source": SOURCE_ZEROCONF},
|
||||||
|
@ -486,7 +490,7 @@ async def test_zeroconf_flow_ignore_non_axis_device(hass):
|
||||||
data={
|
data={
|
||||||
CONF_HOST: "169.254.3.4",
|
CONF_HOST: "169.254.3.4",
|
||||||
CONF_PORT: 80,
|
CONF_PORT: 80,
|
||||||
"hostname": "",
|
"name": "",
|
||||||
"properties": {"macaddress": "01234567890"},
|
"properties": {"macaddress": "01234567890"},
|
||||||
},
|
},
|
||||||
context={"source": SOURCE_ZEROCONF},
|
context={"source": SOURCE_ZEROCONF},
|
||||||
|
@ -503,7 +507,7 @@ async def test_zeroconf_flow_ignore_link_local_address(hass):
|
||||||
data={
|
data={
|
||||||
CONF_HOST: "169.254.3.4",
|
CONF_HOST: "169.254.3.4",
|
||||||
CONF_PORT: 80,
|
CONF_PORT: 80,
|
||||||
"hostname": "",
|
"name": "",
|
||||||
"properties": {"macaddress": MAC},
|
"properties": {"macaddress": MAC},
|
||||||
},
|
},
|
||||||
context={"source": SOURCE_ZEROCONF},
|
context={"source": SOURCE_ZEROCONF},
|
||||||
|
|
|
@ -378,7 +378,7 @@ async def test_update_address(hass):
|
||||||
data={
|
data={
|
||||||
"host": "2.3.4.5",
|
"host": "2.3.4.5",
|
||||||
"port": 80,
|
"port": 80,
|
||||||
"hostname": "name",
|
"name": "name",
|
||||||
"properties": {"macaddress": MAC},
|
"properties": {"macaddress": MAC},
|
||||||
},
|
},
|
||||||
context={"source": SOURCE_ZEROCONF},
|
context={"source": SOURCE_ZEROCONF},
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue