mirror of
https://github.com/home-assistant/core.git
synced 2025-04-25 17:57:55 +00:00
Use the shared Zeroconf instance in esphome (#38747)
This commit is contained in:
parent
7f7a0003c7
commit
9b23d7c2fd
@ -17,6 +17,7 @@ from aioesphomeapi import (
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant import const
|
||||
from homeassistant.components import zeroconf
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import (
|
||||
CONF_HOST,
|
||||
@ -66,12 +67,15 @@ async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry) -> bool
|
||||
port = entry.data[CONF_PORT]
|
||||
password = entry.data[CONF_PASSWORD]
|
||||
|
||||
zeroconf_instance = await zeroconf.async_get_instance(hass)
|
||||
|
||||
cli = APIClient(
|
||||
hass.loop,
|
||||
host,
|
||||
port,
|
||||
password,
|
||||
client_info=f"Home Assistant {const.__version__}",
|
||||
zeroconf_instance=zeroconf_instance,
|
||||
)
|
||||
|
||||
# Store client in per-config-entry hass.data
|
||||
|
@ -5,6 +5,7 @@ from typing import Optional
|
||||
from aioesphomeapi import APIClient, APIConnectionError
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components import zeroconf
|
||||
from homeassistant.config_entries import CONN_CLASS_LOCAL_PUSH, ConfigFlow
|
||||
from homeassistant.const import CONF_HOST, CONF_NAME, CONF_PASSWORD, CONF_PORT
|
||||
from homeassistant.core import callback
|
||||
@ -165,7 +166,14 @@ class EsphomeFlowHandler(ConfigFlow, domain=DOMAIN):
|
||||
|
||||
async def fetch_device_info(self):
|
||||
"""Fetch device info from API and return any errors."""
|
||||
cli = APIClient(self.hass.loop, self._host, self._port, "")
|
||||
zeroconf_instance = await zeroconf.async_get_instance(self.hass)
|
||||
cli = APIClient(
|
||||
self.hass.loop,
|
||||
self._host,
|
||||
self._port,
|
||||
"",
|
||||
zeroconf_instance=zeroconf_instance,
|
||||
)
|
||||
|
||||
try:
|
||||
await cli.connect()
|
||||
@ -181,7 +189,14 @@ class EsphomeFlowHandler(ConfigFlow, domain=DOMAIN):
|
||||
|
||||
async def try_login(self):
|
||||
"""Try logging in to device and return any errors."""
|
||||
cli = APIClient(self.hass.loop, self._host, self._port, self._password)
|
||||
zeroconf_instance = await zeroconf.async_get_instance(self.hass)
|
||||
cli = APIClient(
|
||||
self.hass.loop,
|
||||
self._host,
|
||||
self._port,
|
||||
self._password,
|
||||
zeroconf_instance=zeroconf_instance,
|
||||
)
|
||||
|
||||
try:
|
||||
await cli.connect(login=True)
|
||||
|
@ -3,7 +3,10 @@
|
||||
"name": "ESPHome",
|
||||
"config_flow": true,
|
||||
"documentation": "https://www.home-assistant.io/integrations/esphome",
|
||||
"requirements": ["aioesphomeapi==2.6.1"],
|
||||
"requirements": ["aioesphomeapi==2.6.3"],
|
||||
"zeroconf": ["_esphomelib._tcp.local."],
|
||||
"codeowners": ["@OttoWinter"]
|
||||
"codeowners": ["@OttoWinter"],
|
||||
"after_dependencies": [
|
||||
"zeroconf"
|
||||
]
|
||||
}
|
||||
|
@ -160,7 +160,7 @@ aiodns==2.0.0
|
||||
aioeafm==0.1.2
|
||||
|
||||
# homeassistant.components.esphome
|
||||
aioesphomeapi==2.6.1
|
||||
aioesphomeapi==2.6.3
|
||||
|
||||
# homeassistant.components.flo
|
||||
aioflo==0.4.1
|
||||
|
@ -88,7 +88,7 @@ aiodns==2.0.0
|
||||
aioeafm==0.1.2
|
||||
|
||||
# homeassistant.components.esphome
|
||||
aioesphomeapi==2.6.1
|
||||
aioesphomeapi==2.6.3
|
||||
|
||||
# homeassistant.components.flo
|
||||
aioflo==0.4.1
|
||||
|
@ -22,11 +22,12 @@ def mock_client():
|
||||
"""Mock APIClient."""
|
||||
with patch("homeassistant.components.esphome.config_flow.APIClient") as mock_client:
|
||||
|
||||
def mock_constructor(loop, host, port, password):
|
||||
def mock_constructor(loop, host, port, password, zeroconf_instance=None):
|
||||
"""Fake the client constructor."""
|
||||
mock_client.host = host
|
||||
mock_client.port = port
|
||||
mock_client.password = password
|
||||
mock_client.zeroconf_instance = zeroconf_instance
|
||||
return mock_client
|
||||
|
||||
mock_client.side_effect = mock_constructor
|
||||
|
Loading…
x
Reference in New Issue
Block a user