mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 01:08:12 +00:00
ESPHome dashboard tweaks (#86176)
This commit is contained in:
parent
4f63398941
commit
a83318f373
@ -10,6 +10,7 @@ from homeassistant.const import CONF_PASSWORD
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from . import CONF_NOISE_PSK, DomainData
|
||||
from .dashboard import async_get_dashboard
|
||||
|
||||
CONF_MAC_ADDRESS = "mac_address"
|
||||
|
||||
@ -39,4 +40,7 @@ async def async_get_config_entry_diagnostics(
|
||||
"scanner": await scanner.async_diagnostics(),
|
||||
}
|
||||
|
||||
if dashboard := async_get_dashboard(hass):
|
||||
diag["dashboard"] = dashboard.addon_slug
|
||||
|
||||
return async_redact_data(diag, REDACT_KEYS)
|
||||
|
@ -1 +1,5 @@
|
||||
"""Tests for esphome."""
|
||||
|
||||
DASHBOARD_SLUG = "mock-slug"
|
||||
DASHBOARD_HOST = "mock-host"
|
||||
DASHBOARD_PORT = 1234
|
||||
|
@ -7,10 +7,12 @@ from aioesphomeapi import APIClient, DeviceInfo
|
||||
import pytest
|
||||
from zeroconf import Zeroconf
|
||||
|
||||
from homeassistant.components.esphome import CONF_NOISE_PSK, DOMAIN
|
||||
from homeassistant.components.esphome import CONF_NOISE_PSK, DOMAIN, dashboard
|
||||
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_PORT
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from . import DASHBOARD_HOST, DASHBOARD_PORT, DASHBOARD_SLUG
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
@ -101,11 +103,14 @@ def mock_client(mock_device_info):
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_dashboard():
|
||||
async def mock_dashboard(hass):
|
||||
"""Mock dashboard."""
|
||||
data = {"configured": [], "importable": []}
|
||||
with patch(
|
||||
"esphome_dashboard_api.ESPHomeDashboardAPI.get_devices",
|
||||
return_value=data,
|
||||
):
|
||||
await dashboard.async_set_dashboard_info(
|
||||
hass, DASHBOARD_SLUG, DASHBOARD_HOST, DASHBOARD_PORT
|
||||
)
|
||||
yield data
|
||||
|
@ -496,7 +496,7 @@ async def test_reauth_fixed_via_dashboard(
|
||||
}
|
||||
)
|
||||
|
||||
await dashboard.async_set_dashboard_info(hass, "mock-slug", "mock-host", 6052)
|
||||
await dashboard.async_get_dashboard(hass).async_refresh()
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.esphome.dashboard.ESPHomeDashboardAPI.get_encryption_key",
|
||||
@ -701,7 +701,7 @@ async def test_zeroconf_encryption_key_via_dashboard(
|
||||
}
|
||||
)
|
||||
|
||||
await dashboard.async_set_dashboard_info(hass, "mock-slug", "mock-host", 6052)
|
||||
await dashboard.async_get_dashboard(hass).async_refresh()
|
||||
|
||||
mock_client.device_info.side_effect = [
|
||||
RequiresEncryptionAPIError,
|
||||
@ -756,7 +756,7 @@ async def test_zeroconf_no_encryption_key_via_dashboard(
|
||||
assert flow["type"] == FlowResultType.FORM
|
||||
assert flow["step_id"] == "discovery_confirm"
|
||||
|
||||
await dashboard.async_set_dashboard_info(hass, "mock-slug", "mock-host", 6052)
|
||||
await dashboard.async_get_dashboard(hass).async_refresh()
|
||||
|
||||
mock_client.device_info.side_effect = RequiresEncryptionAPIError
|
||||
|
||||
|
@ -7,6 +7,8 @@ from homeassistant.components.esphome import CONF_NOISE_PSK
|
||||
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_PORT
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from . import DASHBOARD_SLUG
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
from tests.components.diagnostics import get_diagnostics_for_config_entry
|
||||
|
||||
@ -16,6 +18,7 @@ async def test_diagnostics(
|
||||
hass_client: ClientSession,
|
||||
init_integration: MockConfigEntry,
|
||||
enable_bluetooth: pytest.fixture,
|
||||
mock_dashboard,
|
||||
):
|
||||
"""Test diagnostics for config entry."""
|
||||
result = await get_diagnostics_for_config_entry(hass, hass_client, init_integration)
|
||||
@ -28,3 +31,4 @@ async def test_diagnostics(
|
||||
CONF_NOISE_PSK: "**REDACTED**",
|
||||
}
|
||||
assert result["config"]["unique_id"] == "11:22:33:44:55:aa"
|
||||
assert result["dashboard"] == DASHBOARD_SLUG
|
||||
|
@ -3,7 +3,7 @@ from unittest.mock import Mock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.esphome.dashboard import async_set_dashboard_info
|
||||
from homeassistant.components.esphome.dashboard import async_get_dashboard
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
@ -44,7 +44,7 @@ async def test_update_entity(
|
||||
):
|
||||
"""Test ESPHome update entity."""
|
||||
mock_dashboard["configured"] = devices_payload
|
||||
await async_set_dashboard_info(hass, "mock-addon-slug", "mock-addon-host", 1234)
|
||||
await async_get_dashboard(hass).async_refresh()
|
||||
|
||||
mock_config_entry.add_to_hass(hass)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user