mirror of
https://github.com/home-assistant/core.git
synced 2025-04-26 02:07:54 +00:00
Add diagnostics support to bond (#67412)
This commit is contained in:
parent
076fe97110
commit
ac031cb817
39
homeassistant/components/bond/diagnostics.py
Normal file
39
homeassistant/components/bond/diagnostics.py
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
"""Diagnostics support for bond."""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
from homeassistant.components.diagnostics import async_redact_data
|
||||||
|
from homeassistant.config_entries import ConfigEntry
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
|
from .const import DOMAIN, HUB
|
||||||
|
from .utils import BondHub
|
||||||
|
|
||||||
|
TO_REDACT = {"access_token"}
|
||||||
|
|
||||||
|
|
||||||
|
async def async_get_config_entry_diagnostics(
|
||||||
|
hass: HomeAssistant, entry: ConfigEntry
|
||||||
|
) -> dict[str, Any]:
|
||||||
|
"""Return diagnostics for a config entry."""
|
||||||
|
data = hass.data[DOMAIN][entry.entry_id]
|
||||||
|
hub: BondHub = data[HUB]
|
||||||
|
return {
|
||||||
|
"entry": {
|
||||||
|
"title": entry.title,
|
||||||
|
"data": async_redact_data(entry.data, TO_REDACT),
|
||||||
|
},
|
||||||
|
"hub": {
|
||||||
|
"version": hub._version, # pylint: disable=protected-access
|
||||||
|
},
|
||||||
|
"devices": [
|
||||||
|
{
|
||||||
|
"device_id": device.device_id,
|
||||||
|
"props": device.props,
|
||||||
|
"attrs": device._attrs, # pylint: disable=protected-access
|
||||||
|
"supported_actions": device._supported_actions, # pylint: disable=protected-access
|
||||||
|
}
|
||||||
|
for device in hub.devices
|
||||||
|
],
|
||||||
|
}
|
@ -8,6 +8,7 @@ from typing import Any
|
|||||||
from unittest.mock import MagicMock, patch
|
from unittest.mock import MagicMock, patch
|
||||||
|
|
||||||
from aiohttp.client_exceptions import ClientResponseError
|
from aiohttp.client_exceptions import ClientResponseError
|
||||||
|
from bond_api import DeviceType
|
||||||
|
|
||||||
from homeassistant import core
|
from homeassistant import core
|
||||||
from homeassistant.components.bond.const import DOMAIN as BOND_DOMAIN
|
from homeassistant.components.bond.const import DOMAIN as BOND_DOMAIN
|
||||||
@ -18,6 +19,15 @@ from homeassistant.util import utcnow
|
|||||||
from tests.common import MockConfigEntry, async_fire_time_changed
|
from tests.common import MockConfigEntry, async_fire_time_changed
|
||||||
|
|
||||||
|
|
||||||
|
def ceiling_fan_with_breeze(name: str):
|
||||||
|
"""Create a ceiling fan with given name with breeze support."""
|
||||||
|
return {
|
||||||
|
"name": name,
|
||||||
|
"type": DeviceType.CEILING_FAN,
|
||||||
|
"actions": ["SetSpeed", "SetDirection", "BreezeOn"],
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def patch_setup_entry(domain: str, *, enabled: bool = True):
|
def patch_setup_entry(domain: str, *, enabled: bool = True):
|
||||||
"""Patch async_setup_entry for specified domain."""
|
"""Patch async_setup_entry for specified domain."""
|
||||||
if not enabled:
|
if not enabled:
|
||||||
|
43
tests/components/bond/test_diagnostics.py
Normal file
43
tests/components/bond/test_diagnostics.py
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
"""Test bond diagnostics."""
|
||||||
|
|
||||||
|
from homeassistant.components.fan import DOMAIN as FAN_DOMAIN
|
||||||
|
|
||||||
|
from .common import ceiling_fan_with_breeze, setup_platform
|
||||||
|
|
||||||
|
from tests.components.diagnostics import get_diagnostics_for_config_entry
|
||||||
|
|
||||||
|
|
||||||
|
async def test_diagnostics(hass, hass_client):
|
||||||
|
"""Test generating diagnostics for a config entry."""
|
||||||
|
|
||||||
|
entry = await setup_platform(
|
||||||
|
hass,
|
||||||
|
FAN_DOMAIN,
|
||||||
|
ceiling_fan_with_breeze("name-1"),
|
||||||
|
bond_device_id="test-device-id",
|
||||||
|
props={"max_speed": 6},
|
||||||
|
)
|
||||||
|
diag = await get_diagnostics_for_config_entry(hass, hass_client, entry)
|
||||||
|
mock_device = diag["devices"][0]
|
||||||
|
mock_device["attrs"]["actions"] = set(mock_device["attrs"]["actions"])
|
||||||
|
mock_device["supported_actions"] = set(mock_device["supported_actions"])
|
||||||
|
|
||||||
|
assert diag == {
|
||||||
|
"devices": [
|
||||||
|
{
|
||||||
|
"attrs": {
|
||||||
|
"actions": {"SetSpeed", "SetDirection", "BreezeOn"},
|
||||||
|
"name": "name-1",
|
||||||
|
"type": "CF",
|
||||||
|
},
|
||||||
|
"device_id": "test-device-id",
|
||||||
|
"props": {"max_speed": 6},
|
||||||
|
"supported_actions": {"BreezeOn", "SetSpeed", "SetDirection"},
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"entry": {
|
||||||
|
"data": {"access_token": "**REDACTED**", "host": "some host"},
|
||||||
|
"title": "Mock Title",
|
||||||
|
},
|
||||||
|
"hub": {"version": {"bondid": "test-bond-id"}},
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user