mirror of
https://github.com/home-assistant/core.git
synced 2025-07-14 16:57:10 +00:00
Use DhcpServiceInfo in isy994 (#59982)
Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
parent
982f2065c8
commit
14d4a9a69d
@ -10,8 +10,7 @@ from pyisy.connection import Connection
|
|||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant import config_entries, core, data_entry_flow, exceptions
|
from homeassistant import config_entries, core, data_entry_flow, exceptions
|
||||||
from homeassistant.components import ssdp
|
from homeassistant.components import dhcp, ssdp
|
||||||
from homeassistant.components.dhcp import HOSTNAME, IP_ADDRESS, MAC_ADDRESS
|
|
||||||
from homeassistant.const import CONF_HOST, CONF_NAME, CONF_PASSWORD, CONF_USERNAME
|
from homeassistant.const import CONF_HOST, CONF_NAME, CONF_PASSWORD, CONF_USERNAME
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import callback
|
||||||
from homeassistant.helpers import aiohttp_client
|
from homeassistant.helpers import aiohttp_client
|
||||||
@ -184,16 +183,18 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
)
|
)
|
||||||
raise data_entry_flow.AbortFlow("already_configured")
|
raise data_entry_flow.AbortFlow("already_configured")
|
||||||
|
|
||||||
async def async_step_dhcp(self, discovery_info):
|
async def async_step_dhcp(
|
||||||
|
self, discovery_info: dhcp.DhcpServiceInfo
|
||||||
|
) -> data_entry_flow.FlowResult:
|
||||||
"""Handle a discovered isy994 via dhcp."""
|
"""Handle a discovered isy994 via dhcp."""
|
||||||
friendly_name = discovery_info[HOSTNAME]
|
friendly_name = discovery_info[dhcp.HOSTNAME]
|
||||||
url = f"http://{discovery_info[IP_ADDRESS]}"
|
url = f"http://{discovery_info[dhcp.IP_ADDRESS]}"
|
||||||
mac = discovery_info[MAC_ADDRESS]
|
mac = discovery_info[dhcp.MAC_ADDRESS]
|
||||||
isy_mac = (
|
isy_mac = (
|
||||||
f"{mac[0:2]}:{mac[2:4]}:{mac[4:6]}:{mac[6:8]}:{mac[8:10]}:{mac[10:12]}"
|
f"{mac[0:2]}:{mac[2:4]}:{mac[4:6]}:{mac[6:8]}:{mac[8:10]}:{mac[10:12]}"
|
||||||
)
|
)
|
||||||
await self._async_set_unique_id_or_update(
|
await self._async_set_unique_id_or_update(
|
||||||
isy_mac, discovery_info[IP_ADDRESS], None
|
isy_mac, discovery_info[dhcp.IP_ADDRESS], None
|
||||||
)
|
)
|
||||||
|
|
||||||
self.discovered_conf = {
|
self.discovered_conf = {
|
||||||
|
@ -485,11 +485,11 @@ async def test_form_dhcp(hass: HomeAssistant):
|
|||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
context={"source": SOURCE_DHCP},
|
context={"source": SOURCE_DHCP},
|
||||||
data={
|
data=dhcp.DhcpServiceInfo(
|
||||||
dhcp.IP_ADDRESS: "1.2.3.4",
|
ip="1.2.3.4",
|
||||||
dhcp.HOSTNAME: "isy994-ems",
|
hostname="isy994-ems",
|
||||||
dhcp.MAC_ADDRESS: MOCK_MAC,
|
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"
|
||||||
@ -529,11 +529,11 @@ async def test_form_dhcp_existing_entry(hass: HomeAssistant):
|
|||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
context={"source": SOURCE_DHCP},
|
context={"source": SOURCE_DHCP},
|
||||||
data={
|
data=dhcp.DhcpServiceInfo(
|
||||||
dhcp.IP_ADDRESS: "1.2.3.4",
|
ip="1.2.3.4",
|
||||||
dhcp.HOSTNAME: "isy994-ems",
|
hostname="isy994-ems",
|
||||||
dhcp.MAC_ADDRESS: MOCK_MAC,
|
macaddress=MOCK_MAC,
|
||||||
},
|
),
|
||||||
)
|
)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
@ -559,11 +559,11 @@ async def test_form_dhcp_existing_entry_preserves_port(hass: HomeAssistant):
|
|||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
context={"source": SOURCE_DHCP},
|
context={"source": SOURCE_DHCP},
|
||||||
data={
|
data=dhcp.DhcpServiceInfo(
|
||||||
dhcp.IP_ADDRESS: "1.2.3.4",
|
ip="1.2.3.4",
|
||||||
dhcp.HOSTNAME: "isy994-ems",
|
hostname="isy994-ems",
|
||||||
dhcp.MAC_ADDRESS: MOCK_MAC,
|
macaddress=MOCK_MAC,
|
||||||
},
|
),
|
||||||
)
|
)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user