mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 10:17:09 +00:00
Use zeroconf attributes in enphase-envoy (#58961)
This commit is contained in:
parent
185f7beafc
commit
8cc2f3b7a4
@ -9,6 +9,7 @@ import httpx
|
|||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant import config_entries
|
from homeassistant import config_entries
|
||||||
|
from homeassistant.components import zeroconf
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
CONF_HOST,
|
CONF_HOST,
|
||||||
CONF_IP_ADDRESS,
|
CONF_IP_ADDRESS,
|
||||||
@ -20,6 +21,7 @@ from homeassistant.core import HomeAssistant, callback
|
|||||||
from homeassistant.data_entry_flow import FlowResult
|
from homeassistant.data_entry_flow import FlowResult
|
||||||
from homeassistant.exceptions import HomeAssistantError
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
from homeassistant.helpers.httpx_client import get_async_client
|
from homeassistant.helpers.httpx_client import get_async_client
|
||||||
|
from homeassistant.helpers.typing import DiscoveryInfoType
|
||||||
|
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
|
|
||||||
@ -99,11 +101,13 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
if CONF_HOST in entry.data
|
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."""
|
"""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)
|
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})
|
self._abort_if_unique_id_configured({CONF_HOST: self.ip_address})
|
||||||
for entry in self._async_current_entries(include_ignore=False):
|
for entry in self._async_current_entries(include_ignore=False):
|
||||||
if (
|
if (
|
||||||
|
@ -4,6 +4,7 @@ from unittest.mock import MagicMock, patch
|
|||||||
import httpx
|
import httpx
|
||||||
|
|
||||||
from homeassistant import config_entries
|
from homeassistant import config_entries
|
||||||
|
from homeassistant.components import zeroconf
|
||||||
from homeassistant.components.enphase_envoy.const import DOMAIN
|
from homeassistant.components.enphase_envoy.const import DOMAIN
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
@ -157,10 +158,10 @@ async def test_zeroconf(hass: HomeAssistant) -> None:
|
|||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
context={"source": config_entries.SOURCE_ZEROCONF},
|
context={"source": config_entries.SOURCE_ZEROCONF},
|
||||||
data={
|
data=zeroconf.HaServiceInfo(
|
||||||
"properties": {"serialnum": "1234"},
|
properties={"serialnum": "1234"},
|
||||||
"host": "1.1.1.1",
|
host="1.1.1.1",
|
||||||
},
|
),
|
||||||
)
|
)
|
||||||
await hass.async_block_till_done()
|
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(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
context={"source": config_entries.SOURCE_ZEROCONF},
|
context={"source": config_entries.SOURCE_ZEROCONF},
|
||||||
data={
|
data=zeroconf.HaServiceInfo(
|
||||||
"properties": {"serialnum": "1234"},
|
properties={"serialnum": "1234"},
|
||||||
"host": "1.1.1.1",
|
host="1.1.1.1",
|
||||||
},
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
assert result["type"] == "abort"
|
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(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
context={"source": config_entries.SOURCE_ZEROCONF},
|
context={"source": config_entries.SOURCE_ZEROCONF},
|
||||||
data={
|
data=zeroconf.HaServiceInfo(
|
||||||
"properties": {"serialnum": "1234"},
|
properties={"serialnum": "1234"},
|
||||||
"host": "1.1.1.1",
|
host="1.1.1.1",
|
||||||
},
|
),
|
||||||
)
|
)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user