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