Use dataclass properties in vicare discovery (#60746)

Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
epenet 2021-12-01 19:39:03 +01:00 committed by GitHub
parent 4411d51d6f
commit 3d5f4e54ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 9 deletions

View File

@ -8,7 +8,7 @@ from PyViCare.PyViCareUtils import PyViCareInvalidCredentialsError
import voluptuous as vol import voluptuous as vol
from homeassistant import config_entries from homeassistant import config_entries
from homeassistant.components.dhcp import MAC_ADDRESS from homeassistant.components import dhcp
from homeassistant.const import ( from homeassistant.const import (
CONF_CLIENT_ID, CONF_CLIENT_ID,
CONF_NAME, CONF_NAME,
@ -16,6 +16,7 @@ from homeassistant.const import (
CONF_SCAN_INTERVAL, CONF_SCAN_INTERVAL,
CONF_USERNAME, CONF_USERNAME,
) )
from homeassistant.data_entry_flow import FlowResult
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.device_registry import format_mac from homeassistant.helpers.device_registry import format_mac
@ -74,9 +75,9 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
errors=errors, errors=errors,
) )
async def async_step_dhcp(self, discovery_info): async def async_step_dhcp(self, discovery_info: dhcp.DhcpServiceInfo) -> FlowResult:
"""Invoke when a Viessmann MAC address is discovered on the network.""" """Invoke when a Viessmann MAC address is discovered on the network."""
formatted_mac = format_mac(discovery_info[MAC_ADDRESS]) formatted_mac = format_mac(discovery_info.macaddress)
_LOGGER.info("Found device with mac %s", formatted_mac) _LOGGER.info("Found device with mac %s", formatted_mac)
await self.async_set_unique_id(formatted_mac) await self.async_set_unique_id(formatted_mac)

View File

@ -167,9 +167,11 @@ async def test_form_dhcp(hass):
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
DOMAIN, DOMAIN,
context={"source": config_entries.SOURCE_DHCP}, context={"source": config_entries.SOURCE_DHCP},
data={ data=dhcp.DhcpServiceInfo(
dhcp.MAC_ADDRESS: MOCK_MAC, ip="1.1.1.1",
}, hostname="mock_hostname",
macaddress=MOCK_MAC,
),
) )
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
assert result["step_id"] == "user" assert result["step_id"] == "user"
@ -249,9 +251,11 @@ async def test_dhcp_single_instance_allowed(hass):
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
DOMAIN, DOMAIN,
context={"source": config_entries.SOURCE_DHCP}, context={"source": config_entries.SOURCE_DHCP},
data={ data=dhcp.DhcpServiceInfo(
dhcp.MAC_ADDRESS: MOCK_MAC, ip="1.1.1.1",
}, hostname="mock_hostname",
macaddress=MOCK_MAC,
),
) )
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
assert result["reason"] == "single_instance_allowed" assert result["reason"] == "single_instance_allowed"