mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 08:47:57 +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)
|
||||
|
||||
CLIENT_INFO = f"Home Assistant {ha_version}"
|
||||
|
||||
|
||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
"""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:
|
||||
"""Set up the esphome component."""
|
||||
host = entry.data[CONF_HOST]
|
||||
port = entry.data[CONF_PORT]
|
||||
password = entry.data[CONF_PASSWORD]
|
||||
noise_psk = entry.data.get(CONF_NOISE_PSK)
|
||||
host: str = entry.data[CONF_HOST]
|
||||
port: int = entry.data[CONF_PORT]
|
||||
password: str | None = entry.data[CONF_PASSWORD]
|
||||
noise_psk: str | None = entry.data.get(CONF_NOISE_PSK)
|
||||
|
||||
zeroconf_instance = await zeroconf.async_get_instance(hass)
|
||||
|
||||
@ -45,7 +47,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ESPHomeConfigEntry) -> b
|
||||
host,
|
||||
port,
|
||||
password,
|
||||
client_info=f"Home Assistant {ha_version}",
|
||||
client_info=CLIENT_INFO,
|
||||
zeroconf_instance=zeroconf_instance,
|
||||
noise_psk=noise_psk,
|
||||
)
|
||||
@ -61,7 +63,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ESPHomeConfigEntry) -> b
|
||||
entry.runtime_data = entry_data
|
||||
|
||||
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()
|
||||
|
||||
|
@ -33,12 +33,6 @@ class DomainData:
|
||||
"""
|
||||
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(
|
||||
self, hass: HomeAssistant, entry: ESPHomeConfigEntry
|
||||
) -> ESPHomeStorage:
|
||||
|
@ -164,7 +164,6 @@ class ESPHomeManager:
|
||||
cli: APIClient,
|
||||
zeroconf_instance: zeroconf.HaZeroconf,
|
||||
domain_data: DomainData,
|
||||
entry_data: RuntimeEntryData,
|
||||
) -> None:
|
||||
"""Initialize the esphome manager."""
|
||||
self.hass = hass
|
||||
@ -177,7 +176,7 @@ class ESPHomeManager:
|
||||
self.voice_assistant_pipeline: VoiceAssistantPipeline | None = None
|
||||
self.reconnect_logic: ReconnectLogic | None = None
|
||||
self.zeroconf_instance = zeroconf_instance
|
||||
self.entry_data = entry_data
|
||||
self.entry_data = entry.runtime_data
|
||||
|
||||
async def on_stop(self, event: Event) -> None:
|
||||
"""Cleanup the socket client on HA close."""
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
from ipaddress import ip_address
|
||||
import json
|
||||
from unittest.mock import AsyncMock, MagicMock, patch
|
||||
from unittest.mock import AsyncMock, patch
|
||||
|
||||
from aioesphomeapi import (
|
||||
APIClient,
|
||||
@ -18,7 +18,7 @@ import pytest
|
||||
|
||||
from homeassistant import config_entries
|
||||
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 (
|
||||
CONF_ALLOW_SERVICE_CALLS,
|
||||
CONF_DEVICE_NAME,
|
||||
@ -1136,10 +1136,7 @@ async def test_discovery_dhcp_no_changes(
|
||||
)
|
||||
entry.add_to_hass(hass)
|
||||
|
||||
mock_entry_data = MagicMock()
|
||||
mock_entry_data.device_info.name = "test8266"
|
||||
domain_data = DomainData.get(hass)
|
||||
domain_data.set_entry_data(entry, mock_entry_data)
|
||||
mock_client.device_info = AsyncMock(return_value=DeviceInfo(name="test8266"))
|
||||
|
||||
service_info = dhcp.DhcpServiceInfo(
|
||||
ip="192.168.43.183",
|
||||
|
Loading…
x
Reference in New Issue
Block a user