Use DhcpServiceInfo in emonitor (#59965)
Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
parent
cb306236f2
commit
f17d58a049
2 changed files with 22 additions and 21 deletions
|
@ -6,8 +6,9 @@ import aiohttp
|
|||
import voluptuous as vol
|
||||
|
||||
from homeassistant import config_entries, core
|
||||
from homeassistant.components.dhcp import IP_ADDRESS, MAC_ADDRESS
|
||||
from homeassistant.components import dhcp
|
||||
from homeassistant.const import CONF_HOST, CONF_NAME
|
||||
from homeassistant.data_entry_flow import FlowResult
|
||||
from homeassistant.helpers import aiohttp_client
|
||||
from homeassistant.helpers.device_registry import format_mac
|
||||
|
||||
|
@ -62,12 +63,12 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
errors=errors,
|
||||
)
|
||||
|
||||
async def async_step_dhcp(self, discovery_info):
|
||||
async def async_step_dhcp(self, discovery_info: dhcp.DhcpServiceInfo) -> FlowResult:
|
||||
"""Handle dhcp discovery."""
|
||||
self.discovered_ip = discovery_info[IP_ADDRESS]
|
||||
await self.async_set_unique_id(format_mac(discovery_info[MAC_ADDRESS]))
|
||||
self.discovered_ip = discovery_info[dhcp.IP_ADDRESS]
|
||||
await self.async_set_unique_id(format_mac(discovery_info[dhcp.MAC_ADDRESS]))
|
||||
self._abort_if_unique_id_configured(updates={CONF_HOST: self.discovered_ip})
|
||||
name = name_short_mac(short_mac(discovery_info[MAC_ADDRESS]))
|
||||
name = name_short_mac(short_mac(discovery_info[dhcp.MAC_ADDRESS]))
|
||||
self.context["title_placeholders"] = {"name": name}
|
||||
try:
|
||||
self.discovered_info = await fetch_mac_and_title(
|
||||
|
|
|
@ -5,7 +5,7 @@ from aioemonitor.monitor import EmonitorNetwork, EmonitorStatus
|
|||
import aiohttp
|
||||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.components.dhcp import HOSTNAME, IP_ADDRESS, MAC_ADDRESS
|
||||
from homeassistant.components import dhcp
|
||||
from homeassistant.components.emonitor.const import DOMAIN
|
||||
from homeassistant.const import CONF_HOST
|
||||
|
||||
|
@ -102,11 +102,11 @@ async def test_dhcp_can_confirm(hass):
|
|||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_DHCP},
|
||||
data={
|
||||
HOSTNAME: "emonitor",
|
||||
IP_ADDRESS: "1.2.3.4",
|
||||
MAC_ADDRESS: "aa:bb:cc:dd:ee:ff",
|
||||
},
|
||||
data=dhcp.DhcpServiceInfo(
|
||||
hostname="emonitor",
|
||||
ip="1.2.3.4",
|
||||
macaddress="aa:bb:cc:dd:ee:ff",
|
||||
),
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
|
@ -145,11 +145,11 @@ async def test_dhcp_fails_to_connect(hass):
|
|||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_DHCP},
|
||||
data={
|
||||
HOSTNAME: "emonitor",
|
||||
IP_ADDRESS: "1.2.3.4",
|
||||
MAC_ADDRESS: "aa:bb:cc:dd:ee:ff",
|
||||
},
|
||||
data=dhcp.DhcpServiceInfo(
|
||||
hostname="emonitor",
|
||||
ip="1.2.3.4",
|
||||
macaddress="aa:bb:cc:dd:ee:ff",
|
||||
),
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
|
@ -174,11 +174,11 @@ async def test_dhcp_already_exists(hass):
|
|||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_DHCP},
|
||||
data={
|
||||
HOSTNAME: "emonitor",
|
||||
IP_ADDRESS: "1.2.3.4",
|
||||
MAC_ADDRESS: "aa:bb:cc:dd:ee:ff",
|
||||
},
|
||||
data=dhcp.DhcpServiceInfo(
|
||||
hostname="emonitor",
|
||||
ip="1.2.3.4",
|
||||
macaddress="aa:bb:cc:dd:ee:ff",
|
||||
),
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue