Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use dataclass properties in axis discovery #60558

Merged
merged 4 commits into from Nov 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 11 additions & 13 deletions homeassistant/components/axis/config_flow.py
Expand Up @@ -156,21 +156,21 @@ async def async_step_dhcp(self, discovery_info: dhcp.DhcpServiceInfo) -> FlowRes
"""Prepare configuration for a DHCP discovered Axis device."""
return await self._process_discovered_device(
{
CONF_HOST: discovery_info[dhcp.IP_ADDRESS],
CONF_MAC: format_mac(discovery_info[dhcp.MAC_ADDRESS]),
CONF_NAME: discovery_info[dhcp.HOSTNAME],
CONF_HOST: discovery_info.ip,
CONF_MAC: format_mac(discovery_info.macaddress),
CONF_NAME: discovery_info.hostname,
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."""
url = urlsplit(discovery_info["presentationURL"])
url = urlsplit(discovery_info.upnp[ssdp.ATTR_UPNP_PRESENTATION_URL])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is some real meta stuff right here 馃し馃徎

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ignore this comment

return await self._process_discovered_device(
{
CONF_HOST: url.hostname,
CONF_MAC: format_mac(discovery_info["serialNumber"]),
CONF_NAME: f"{discovery_info['friendlyName']}",
CONF_MAC: format_mac(discovery_info.upnp[ssdp.ATTR_UPNP_SERIAL]),
CONF_NAME: f"{discovery_info.upnp[ssdp.ATTR_UPNP_FRIENDLY_NAME]}",
CONF_PORT: url.port,
}
)
Expand All @@ -181,12 +181,10 @@ async def async_step_zeroconf(
"""Prepare configuration for a Zeroconf discovered Axis device."""
return await self._process_discovered_device(
{
CONF_HOST: discovery_info[zeroconf.ATTR_HOST],
CONF_MAC: format_mac(
discovery_info[zeroconf.ATTR_PROPERTIES]["macaddress"]
),
CONF_NAME: discovery_info[zeroconf.ATTR_NAME].split(".", 1)[0],
CONF_PORT: discovery_info[zeroconf.ATTR_PORT],
CONF_HOST: discovery_info.host,
CONF_MAC: format_mac(discovery_info.properties["macaddress"]),
CONF_NAME: discovery_info.name.split(".", 1)[0],
CONF_PORT: discovery_info.port,
}
)

Expand Down
16 changes: 9 additions & 7 deletions tests/components/axis/test_device.py
Expand Up @@ -8,7 +8,7 @@
import pytest
import respx

from homeassistant.components import axis
from homeassistant.components import axis, zeroconf
from homeassistant.components.axis.const import (
CONF_EVENTS,
CONF_MODEL,
Expand Down Expand Up @@ -383,12 +383,14 @@ async def test_update_address(hass):
mock_default_vapix_requests(respx, "2.3.4.5")
await hass.config_entries.flow.async_init(
AXIS_DOMAIN,
data={
"host": "2.3.4.5",
"port": 80,
"name": "name",
"properties": {"macaddress": MAC},
},
data=zeroconf.ZeroconfServiceInfo(
host="2.3.4.5",
hostname="mock_hostname",
name="name",
port=80,
properties={"macaddress": MAC},
type="mock_type",
),
context={"source": SOURCE_ZEROCONF},
)
await hass.async_block_till_done()
Expand Down