mirror of
https://github.com/home-assistant/core.git
synced 2025-07-26 22:57:17 +00:00
Small cleanups to ESPHome (#120414)
This commit is contained in:
parent
f934fea754
commit
edaa5c60a7
@ -25,6 +25,8 @@ from .manager import ESPHomeManager, cleanup_instance
|
|||||||
|
|
||||||
CONFIG_SCHEMA = cv.config_entry_only_config_schema(DOMAIN)
|
CONFIG_SCHEMA = cv.config_entry_only_config_schema(DOMAIN)
|
||||||
|
|
||||||
|
CLIENT_INFO = f"Home Assistant {ha_version}"
|
||||||
|
|
||||||
|
|
||||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||||
"""Set up the esphome component."""
|
"""Set up the esphome component."""
|
||||||
@ -34,10 +36,10 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||||||
|
|
||||||
async def async_setup_entry(hass: HomeAssistant, entry: ESPHomeConfigEntry) -> bool:
|
async def async_setup_entry(hass: HomeAssistant, entry: ESPHomeConfigEntry) -> bool:
|
||||||
"""Set up the esphome component."""
|
"""Set up the esphome component."""
|
||||||
host = entry.data[CONF_HOST]
|
host: str = entry.data[CONF_HOST]
|
||||||
port = entry.data[CONF_PORT]
|
port: int = entry.data[CONF_PORT]
|
||||||
password = entry.data[CONF_PASSWORD]
|
password: str | None = entry.data[CONF_PASSWORD]
|
||||||
noise_psk = entry.data.get(CONF_NOISE_PSK)
|
noise_psk: str | None = entry.data.get(CONF_NOISE_PSK)
|
||||||
|
|
||||||
zeroconf_instance = await zeroconf.async_get_instance(hass)
|
zeroconf_instance = await zeroconf.async_get_instance(hass)
|
||||||
|
|
||||||
@ -45,7 +47,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ESPHomeConfigEntry) -> b
|
|||||||
host,
|
host,
|
||||||
port,
|
port,
|
||||||
password,
|
password,
|
||||||
client_info=f"Home Assistant {ha_version}",
|
client_info=CLIENT_INFO,
|
||||||
zeroconf_instance=zeroconf_instance,
|
zeroconf_instance=zeroconf_instance,
|
||||||
noise_psk=noise_psk,
|
noise_psk=noise_psk,
|
||||||
)
|
)
|
||||||
@ -61,7 +63,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ESPHomeConfigEntry) -> b
|
|||||||
entry.runtime_data = entry_data
|
entry.runtime_data = entry_data
|
||||||
|
|
||||||
manager = ESPHomeManager(
|
manager = ESPHomeManager(
|
||||||
hass, entry, host, password, cli, zeroconf_instance, domain_data, entry_data
|
hass, entry, host, password, cli, zeroconf_instance, domain_data
|
||||||
)
|
)
|
||||||
await manager.async_start()
|
await manager.async_start()
|
||||||
|
|
||||||
|
@ -33,12 +33,6 @@ class DomainData:
|
|||||||
"""
|
"""
|
||||||
return entry.runtime_data
|
return entry.runtime_data
|
||||||
|
|
||||||
def set_entry_data(
|
|
||||||
self, entry: ESPHomeConfigEntry, entry_data: RuntimeEntryData
|
|
||||||
) -> None:
|
|
||||||
"""Set the runtime entry data associated with this config entry."""
|
|
||||||
entry.runtime_data = entry_data
|
|
||||||
|
|
||||||
def get_or_create_store(
|
def get_or_create_store(
|
||||||
self, hass: HomeAssistant, entry: ESPHomeConfigEntry
|
self, hass: HomeAssistant, entry: ESPHomeConfigEntry
|
||||||
) -> ESPHomeStorage:
|
) -> ESPHomeStorage:
|
||||||
|
@ -164,7 +164,6 @@ class ESPHomeManager:
|
|||||||
cli: APIClient,
|
cli: APIClient,
|
||||||
zeroconf_instance: zeroconf.HaZeroconf,
|
zeroconf_instance: zeroconf.HaZeroconf,
|
||||||
domain_data: DomainData,
|
domain_data: DomainData,
|
||||||
entry_data: RuntimeEntryData,
|
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize the esphome manager."""
|
"""Initialize the esphome manager."""
|
||||||
self.hass = hass
|
self.hass = hass
|
||||||
@ -177,7 +176,7 @@ class ESPHomeManager:
|
|||||||
self.voice_assistant_pipeline: VoiceAssistantPipeline | None = None
|
self.voice_assistant_pipeline: VoiceAssistantPipeline | None = None
|
||||||
self.reconnect_logic: ReconnectLogic | None = None
|
self.reconnect_logic: ReconnectLogic | None = None
|
||||||
self.zeroconf_instance = zeroconf_instance
|
self.zeroconf_instance = zeroconf_instance
|
||||||
self.entry_data = entry_data
|
self.entry_data = entry.runtime_data
|
||||||
|
|
||||||
async def on_stop(self, event: Event) -> None:
|
async def on_stop(self, event: Event) -> None:
|
||||||
"""Cleanup the socket client on HA close."""
|
"""Cleanup the socket client on HA close."""
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
from ipaddress import ip_address
|
from ipaddress import ip_address
|
||||||
import json
|
import json
|
||||||
from unittest.mock import AsyncMock, MagicMock, patch
|
from unittest.mock import AsyncMock, patch
|
||||||
|
|
||||||
from aioesphomeapi import (
|
from aioesphomeapi import (
|
||||||
APIClient,
|
APIClient,
|
||||||
@ -18,7 +18,7 @@ import pytest
|
|||||||
|
|
||||||
from homeassistant import config_entries
|
from homeassistant import config_entries
|
||||||
from homeassistant.components import dhcp, zeroconf
|
from homeassistant.components import dhcp, zeroconf
|
||||||
from homeassistant.components.esphome import DomainData, dashboard
|
from homeassistant.components.esphome import dashboard
|
||||||
from homeassistant.components.esphome.const import (
|
from homeassistant.components.esphome.const import (
|
||||||
CONF_ALLOW_SERVICE_CALLS,
|
CONF_ALLOW_SERVICE_CALLS,
|
||||||
CONF_DEVICE_NAME,
|
CONF_DEVICE_NAME,
|
||||||
@ -1136,10 +1136,7 @@ async def test_discovery_dhcp_no_changes(
|
|||||||
)
|
)
|
||||||
entry.add_to_hass(hass)
|
entry.add_to_hass(hass)
|
||||||
|
|
||||||
mock_entry_data = MagicMock()
|
mock_client.device_info = AsyncMock(return_value=DeviceInfo(name="test8266"))
|
||||||
mock_entry_data.device_info.name = "test8266"
|
|
||||||
domain_data = DomainData.get(hass)
|
|
||||||
domain_data.set_entry_data(entry, mock_entry_data)
|
|
||||||
|
|
||||||
service_info = dhcp.DhcpServiceInfo(
|
service_info = dhcp.DhcpServiceInfo(
|
||||||
ip="192.168.43.183",
|
ip="192.168.43.183",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user