mirror of
https://github.com/home-assistant/core.git
synced 2025-04-25 01:38:02 +00:00
Use dataclass properties in axis discovery (#60558)
Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
parent
c2830b3e66
commit
8954609f6b
@ -156,21 +156,21 @@ class AxisFlowHandler(config_entries.ConfigFlow, domain=AXIS_DOMAIN):
|
|||||||
"""Prepare configuration for a DHCP discovered Axis device."""
|
"""Prepare configuration for a DHCP discovered Axis device."""
|
||||||
return await self._process_discovered_device(
|
return await self._process_discovered_device(
|
||||||
{
|
{
|
||||||
CONF_HOST: discovery_info[dhcp.IP_ADDRESS],
|
CONF_HOST: discovery_info.ip,
|
||||||
CONF_MAC: format_mac(discovery_info[dhcp.MAC_ADDRESS]),
|
CONF_MAC: format_mac(discovery_info.macaddress),
|
||||||
CONF_NAME: discovery_info[dhcp.HOSTNAME],
|
CONF_NAME: discovery_info.hostname,
|
||||||
CONF_PORT: DEFAULT_PORT,
|
CONF_PORT: DEFAULT_PORT,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
async def async_step_ssdp(self, discovery_info: ssdp.SsdpServiceInfo):
|
async def async_step_ssdp(self, discovery_info: ssdp.SsdpServiceInfo) -> FlowResult:
|
||||||
"""Prepare configuration for a SSDP discovered Axis device."""
|
"""Prepare configuration for a SSDP discovered Axis device."""
|
||||||
url = urlsplit(discovery_info["presentationURL"])
|
url = urlsplit(discovery_info.upnp[ssdp.ATTR_UPNP_PRESENTATION_URL])
|
||||||
return await self._process_discovered_device(
|
return await self._process_discovered_device(
|
||||||
{
|
{
|
||||||
CONF_HOST: url.hostname,
|
CONF_HOST: url.hostname,
|
||||||
CONF_MAC: format_mac(discovery_info["serialNumber"]),
|
CONF_MAC: format_mac(discovery_info.upnp[ssdp.ATTR_UPNP_SERIAL]),
|
||||||
CONF_NAME: f"{discovery_info['friendlyName']}",
|
CONF_NAME: f"{discovery_info.upnp[ssdp.ATTR_UPNP_FRIENDLY_NAME]}",
|
||||||
CONF_PORT: url.port,
|
CONF_PORT: url.port,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@ -181,12 +181,10 @@ class AxisFlowHandler(config_entries.ConfigFlow, domain=AXIS_DOMAIN):
|
|||||||
"""Prepare configuration for a Zeroconf discovered Axis device."""
|
"""Prepare configuration for a Zeroconf discovered Axis device."""
|
||||||
return await self._process_discovered_device(
|
return await self._process_discovered_device(
|
||||||
{
|
{
|
||||||
CONF_HOST: discovery_info[zeroconf.ATTR_HOST],
|
CONF_HOST: discovery_info.host,
|
||||||
CONF_MAC: format_mac(
|
CONF_MAC: format_mac(discovery_info.properties["macaddress"]),
|
||||||
discovery_info[zeroconf.ATTR_PROPERTIES]["macaddress"]
|
CONF_NAME: discovery_info.name.split(".", 1)[0],
|
||||||
),
|
CONF_PORT: discovery_info.port,
|
||||||
CONF_NAME: discovery_info[zeroconf.ATTR_NAME].split(".", 1)[0],
|
|
||||||
CONF_PORT: discovery_info[zeroconf.ATTR_PORT],
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ from axis.event_stream import OPERATION_INITIALIZED
|
|||||||
import pytest
|
import pytest
|
||||||
import respx
|
import respx
|
||||||
|
|
||||||
from homeassistant.components import axis
|
from homeassistant.components import axis, zeroconf
|
||||||
from homeassistant.components.axis.const import (
|
from homeassistant.components.axis.const import (
|
||||||
CONF_EVENTS,
|
CONF_EVENTS,
|
||||||
CONF_MODEL,
|
CONF_MODEL,
|
||||||
@ -383,12 +383,14 @@ async def test_update_address(hass):
|
|||||||
mock_default_vapix_requests(respx, "2.3.4.5")
|
mock_default_vapix_requests(respx, "2.3.4.5")
|
||||||
await hass.config_entries.flow.async_init(
|
await hass.config_entries.flow.async_init(
|
||||||
AXIS_DOMAIN,
|
AXIS_DOMAIN,
|
||||||
data={
|
data=zeroconf.ZeroconfServiceInfo(
|
||||||
"host": "2.3.4.5",
|
host="2.3.4.5",
|
||||||
"port": 80,
|
hostname="mock_hostname",
|
||||||
"name": "name",
|
name="name",
|
||||||
"properties": {"macaddress": MAC},
|
port=80,
|
||||||
},
|
properties={"macaddress": MAC},
|
||||||
|
type="mock_type",
|
||||||
|
),
|
||||||
context={"source": SOURCE_ZEROCONF},
|
context={"source": SOURCE_ZEROCONF},
|
||||||
)
|
)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user