Use zeroconf attributes in enphase-envoy (#58961)
parent
185f7beafc
commit
8cc2f3b7a4
|
@ -9,6 +9,7 @@ import httpx
|
|||
import voluptuous as vol
|
||||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.components import zeroconf
|
||||
from homeassistant.const import (
|
||||
CONF_HOST,
|
||||
CONF_IP_ADDRESS,
|
||||
|
@ -20,6 +21,7 @@ from homeassistant.core import HomeAssistant, callback
|
|||
from homeassistant.data_entry_flow import FlowResult
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers.httpx_client import get_async_client
|
||||
from homeassistant.helpers.typing import DiscoveryInfoType
|
||||
|
||||
from .const import DOMAIN
|
||||
|
||||
|
@ -99,11 +101,13 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||
if CONF_HOST in entry.data
|
||||
}
|
||||
|
||||
async def async_step_zeroconf(self, discovery_info):
|
||||
async def async_step_zeroconf(
|
||||
self, discovery_info: DiscoveryInfoType
|
||||
) -> FlowResult:
|
||||
"""Handle a flow initialized by zeroconf discovery."""
|
||||
self.serial = discovery_info["properties"]["serialnum"]
|
||||
self.serial = discovery_info[zeroconf.ATTR_PROPERTIES]["serialnum"]
|
||||
await self.async_set_unique_id(self.serial)
|
||||
self.ip_address = discovery_info[CONF_HOST]
|
||||
self.ip_address = discovery_info[zeroconf.ATTR_HOST]
|
||||
self._abort_if_unique_id_configured({CONF_HOST: self.ip_address})
|
||||
for entry in self._async_current_entries(include_ignore=False):
|
||||
if (
|
||||
|
|
|
@ -4,6 +4,7 @@ from unittest.mock import MagicMock, patch
|
|||
import httpx
|
||||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.components import zeroconf
|
||||
from homeassistant.components.enphase_envoy.const import DOMAIN
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
|
@ -157,10 +158,10 @@ async def test_zeroconf(hass: HomeAssistant) -> None:
|
|||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_ZEROCONF},
|
||||
data={
|
||||
"properties": {"serialnum": "1234"},
|
||||
"host": "1.1.1.1",
|
||||
},
|
||||
data=zeroconf.HaServiceInfo(
|
||||
properties={"serialnum": "1234"},
|
||||
host="1.1.1.1",
|
||||
),
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
|
@ -253,10 +254,10 @@ async def test_zeroconf_serial_already_exists(hass: HomeAssistant) -> None:
|
|||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_ZEROCONF},
|
||||
data={
|
||||
"properties": {"serialnum": "1234"},
|
||||
"host": "1.1.1.1",
|
||||
},
|
||||
data=zeroconf.HaServiceInfo(
|
||||
properties={"serialnum": "1234"},
|
||||
host="1.1.1.1",
|
||||
),
|
||||
)
|
||||
|
||||
assert result["type"] == "abort"
|
||||
|
@ -288,10 +289,10 @@ async def test_zeroconf_host_already_exists(hass: HomeAssistant) -> None:
|
|||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_ZEROCONF},
|
||||
data={
|
||||
"properties": {"serialnum": "1234"},
|
||||
"host": "1.1.1.1",
|
||||
},
|
||||
data=zeroconf.HaServiceInfo(
|
||||
properties={"serialnum": "1234"},
|
||||
host="1.1.1.1",
|
||||
),
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
|
|
Loading…
Reference in New Issue