mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 21:06:19 +00:00
Add diagnostics to Airobot integration (#158247)
This commit is contained in:
38
homeassistant/components/airobot/diagnostics.py
Normal file
38
homeassistant/components/airobot/diagnostics.py
Normal file
@@ -0,0 +1,38 @@
|
||||
"""Diagnostics support for Airobot."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import asdict
|
||||
from typing import Any
|
||||
|
||||
from homeassistant.components.diagnostics import async_redact_data
|
||||
from homeassistant.const import CONF_HOST, CONF_MAC, CONF_PASSWORD, CONF_USERNAME
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .coordinator import AirobotConfigEntry
|
||||
|
||||
TO_REDACT_CONFIG = [CONF_HOST, CONF_MAC, CONF_PASSWORD, CONF_USERNAME]
|
||||
|
||||
|
||||
async def async_get_config_entry_diagnostics(
|
||||
hass: HomeAssistant, entry: AirobotConfigEntry
|
||||
) -> dict[str, Any]:
|
||||
"""Return diagnostics for a config entry."""
|
||||
coordinator = entry.runtime_data
|
||||
|
||||
# Build device capabilities info
|
||||
device_capabilities = None
|
||||
if coordinator.data:
|
||||
device_capabilities = {
|
||||
"has_floor_sensor": coordinator.data.status.has_floor_sensor,
|
||||
"has_co2_sensor": coordinator.data.status.has_co2_sensor,
|
||||
"hw_version": coordinator.data.status.hw_version,
|
||||
"fw_version": coordinator.data.status.fw_version,
|
||||
}
|
||||
|
||||
return {
|
||||
"entry_data": async_redact_data(entry.data, TO_REDACT_CONFIG),
|
||||
"device_capabilities": device_capabilities,
|
||||
"status": asdict(coordinator.data.status) if coordinator.data else None,
|
||||
"settings": asdict(coordinator.data.settings) if coordinator.data else None,
|
||||
}
|
||||
@@ -39,7 +39,7 @@ rules:
|
||||
|
||||
# Gold
|
||||
devices: done
|
||||
diagnostics: todo
|
||||
diagnostics: done
|
||||
discovery-update-info: done
|
||||
discovery: done
|
||||
docs-data-update: done
|
||||
@@ -55,7 +55,7 @@ rules:
|
||||
entity-category: done
|
||||
entity-device-class: done
|
||||
entity-disabled-by-default: done
|
||||
entity-translations: todo
|
||||
entity-translations: done
|
||||
exception-translations: done
|
||||
icon-translations: todo
|
||||
reconfiguration-flow: todo
|
||||
|
||||
50
tests/components/airobot/snapshots/test_diagnostics.ambr
Normal file
50
tests/components/airobot/snapshots/test_diagnostics.ambr
Normal file
@@ -0,0 +1,50 @@
|
||||
# serializer version: 1
|
||||
# name: test_entry_diagnostics
|
||||
dict({
|
||||
'device_capabilities': dict({
|
||||
'fw_version': 300,
|
||||
'has_co2_sensor': False,
|
||||
'has_floor_sensor': False,
|
||||
'hw_version': 256,
|
||||
}),
|
||||
'entry_data': dict({
|
||||
'host': '**REDACTED**',
|
||||
'mac': '**REDACTED**',
|
||||
'password': '**REDACTED**',
|
||||
'username': '**REDACTED**',
|
||||
}),
|
||||
'settings': dict({
|
||||
'device_id': 'T01A1B2C3',
|
||||
'device_name': 'Test Thermostat',
|
||||
'hysteresis_band': 0.1,
|
||||
'mode': 1,
|
||||
'setpoint_temp': 22.0,
|
||||
'setpoint_temp_away': 18.0,
|
||||
'setting_flags': dict({
|
||||
'actuator_exercise_disabled': False,
|
||||
'boost_enabled': False,
|
||||
'childlock_enabled': False,
|
||||
'reboot': False,
|
||||
'recalibrate_co2': False,
|
||||
}),
|
||||
}),
|
||||
'status': dict({
|
||||
'aqi': None,
|
||||
'co2': None,
|
||||
'device_id': 'T01A1B2C3',
|
||||
'device_uptime': 10000,
|
||||
'errors': 0,
|
||||
'fw_version': 300,
|
||||
'heating_uptime': 5000,
|
||||
'hum_air': 45.0,
|
||||
'hw_version': 256,
|
||||
'setpoint_temp': 22.0,
|
||||
'status_flags': dict({
|
||||
'heating_on': False,
|
||||
'window_open_detected': False,
|
||||
}),
|
||||
'temp_air': 22.0,
|
||||
'temp_floor': None,
|
||||
}),
|
||||
})
|
||||
# ---
|
||||
21
tests/components/airobot/test_diagnostics.py
Normal file
21
tests/components/airobot/test_diagnostics.py
Normal file
@@ -0,0 +1,21 @@
|
||||
"""Test the Airobot diagnostics."""
|
||||
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
from tests.components.diagnostics import get_diagnostics_for_config_entry
|
||||
from tests.typing import ClientSessionGenerator
|
||||
|
||||
|
||||
async def test_entry_diagnostics(
|
||||
hass: HomeAssistant,
|
||||
hass_client: ClientSessionGenerator,
|
||||
init_integration: MockConfigEntry,
|
||||
snapshot: SnapshotAssertion,
|
||||
) -> None:
|
||||
"""Test config entry diagnostics."""
|
||||
result = await get_diagnostics_for_config_entry(hass, hass_client, init_integration)
|
||||
|
||||
assert result == snapshot
|
||||
Reference in New Issue
Block a user