mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 09:17:53 +00:00
Use DhcpServiceInfo in somfy_mylink (#60099)
This commit is contained in:
parent
8f7f32d844
commit
4e1089cedb
@ -7,9 +7,10 @@ from somfy_mylink_synergy import SomfyMyLinkSynergy
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant import config_entries, core, exceptions
|
||||
from homeassistant.components.dhcp import HOSTNAME, IP_ADDRESS, MAC_ADDRESS
|
||||
from homeassistant.components import dhcp
|
||||
from homeassistant.const import CONF_HOST, CONF_PORT
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.data_entry_flow import FlowResult
|
||||
from homeassistant.helpers.device_registry import format_mac
|
||||
|
||||
from .const import (
|
||||
@ -58,18 +59,18 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
self.mac = None
|
||||
self.ip_address = None
|
||||
|
||||
async def async_step_dhcp(self, discovery_info):
|
||||
async def async_step_dhcp(self, discovery_info: dhcp.DhcpServiceInfo) -> FlowResult:
|
||||
"""Handle dhcp discovery."""
|
||||
self._async_abort_entries_match({CONF_HOST: discovery_info[IP_ADDRESS]})
|
||||
self._async_abort_entries_match({CONF_HOST: discovery_info[dhcp.IP_ADDRESS]})
|
||||
|
||||
formatted_mac = format_mac(discovery_info[MAC_ADDRESS])
|
||||
formatted_mac = format_mac(discovery_info[dhcp.MAC_ADDRESS])
|
||||
await self.async_set_unique_id(format_mac(formatted_mac))
|
||||
self._abort_if_unique_id_configured(
|
||||
updates={CONF_HOST: discovery_info[IP_ADDRESS]}
|
||||
updates={CONF_HOST: discovery_info[dhcp.IP_ADDRESS]}
|
||||
)
|
||||
self.host = discovery_info[HOSTNAME]
|
||||
self.host = discovery_info[dhcp.HOSTNAME]
|
||||
self.mac = formatted_mac
|
||||
self.ip_address = discovery_info[IP_ADDRESS]
|
||||
self.ip_address = discovery_info[dhcp.IP_ADDRESS]
|
||||
self.context["title_placeholders"] = {"ip": self.ip_address, "mac": self.mac}
|
||||
return await self.async_step_user()
|
||||
|
||||
|
@ -5,7 +5,7 @@ from unittest.mock import patch
|
||||
import pytest
|
||||
|
||||
from homeassistant import config_entries, data_entry_flow
|
||||
from homeassistant.components.dhcp import HOSTNAME, IP_ADDRESS, MAC_ADDRESS
|
||||
from homeassistant.components import dhcp
|
||||
from homeassistant.components.somfy_mylink.const import (
|
||||
CONF_REVERSED_TARGET_IDS,
|
||||
CONF_SYSTEM_ID,
|
||||
@ -252,11 +252,11 @@ async def test_form_user_already_configured_from_dhcp(hass):
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_DHCP},
|
||||
data={
|
||||
IP_ADDRESS: "1.1.1.1",
|
||||
MAC_ADDRESS: "AA:BB:CC:DD:EE:FF",
|
||||
HOSTNAME: "somfy_eeff",
|
||||
},
|
||||
data=dhcp.DhcpServiceInfo(
|
||||
ip="1.1.1.1",
|
||||
macaddress="AA:BB:CC:DD:EE:FF",
|
||||
hostname="somfy_eeff",
|
||||
),
|
||||
)
|
||||
|
||||
await hass.async_block_till_done()
|
||||
@ -276,11 +276,11 @@ async def test_already_configured_with_ignored(hass):
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_DHCP},
|
||||
data={
|
||||
IP_ADDRESS: "1.1.1.1",
|
||||
MAC_ADDRESS: "AA:BB:CC:DD:EE:FF",
|
||||
HOSTNAME: "somfy_eeff",
|
||||
},
|
||||
data=dhcp.DhcpServiceInfo(
|
||||
ip="1.1.1.1",
|
||||
macaddress="AA:BB:CC:DD:EE:FF",
|
||||
hostname="somfy_eeff",
|
||||
),
|
||||
)
|
||||
assert result["type"] == "form"
|
||||
|
||||
@ -291,11 +291,11 @@ async def test_dhcp_discovery(hass):
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_DHCP},
|
||||
data={
|
||||
IP_ADDRESS: "1.1.1.1",
|
||||
MAC_ADDRESS: "AA:BB:CC:DD:EE:FF",
|
||||
HOSTNAME: "somfy_eeff",
|
||||
},
|
||||
data=dhcp.DhcpServiceInfo(
|
||||
ip="1.1.1.1",
|
||||
macaddress="AA:BB:CC:DD:EE:FF",
|
||||
hostname="somfy_eeff",
|
||||
),
|
||||
)
|
||||
assert result["type"] == "form"
|
||||
assert result["errors"] == {}
|
||||
|
Loading…
x
Reference in New Issue
Block a user