Fix Diagnostics in Advantage Air (#95608)

* Fix diag paths

* Fix key sand add redactions

* Name things better.

* Add super basic test

* Rename docstring

* Add snapshot

---------

Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
pull/95642/head
Brett Adams 2023-07-01 03:52:52 +10:00 committed by GitHub
parent 376c61c34b
commit d4e40ed73f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 340 additions and 3 deletions

View File

@ -9,17 +9,30 @@ from homeassistant.core import HomeAssistant
from .const import DOMAIN as ADVANTAGE_AIR_DOMAIN
TO_REDACT = ["dealerPhoneNumber", "latitude", "logoPIN", "longitude", "postCode"]
TO_REDACT = [
"dealerPhoneNumber",
"latitude",
"logoPIN",
"longitude",
"postCode",
"rid",
"deviceNames",
"deviceIds",
"deviceIdsV2",
"backupId",
]
async def async_get_config_entry_diagnostics(
hass: HomeAssistant, config_entry: ConfigEntry
) -> dict[str, Any]:
"""Return diagnostics for a config entry."""
data = hass.data[ADVANTAGE_AIR_DOMAIN][config_entry.entry_id]["coordinator"].data
data = hass.data[ADVANTAGE_AIR_DOMAIN][config_entry.entry_id].coordinator.data
# Return only the relevant children
return {
"aircons": data["aircons"],
"aircons": data.get("aircons"),
"myLights": data.get("myLights"),
"myThings": data.get("myThings"),
"system": async_redact_data(data["system"], TO_REDACT),
}

View File

@ -0,0 +1,292 @@
# serializer version: 1
# name: test_select_async_setup_entry
dict({
'aircons': dict({
'ac1': dict({
'info': dict({
'aaAutoFanModeEnabled': False,
'climateControlModeEnabled': False,
'climateControlModeIsRunning': False,
'countDownToOff': 10,
'countDownToOn': 0,
'fan': 'high',
'filterCleanStatus': 0,
'freshAirStatus': 'off',
'mode': 'vent',
'myAutoModeEnabled': False,
'myAutoModeIsRunning': False,
'myZone': 1,
'name': 'myzone',
'setTemp': 24,
'state': 'on',
}),
'zones': dict({
'z01': dict({
'error': 0,
'maxDamper': 100,
'measuredTemp': 25,
'minDamper': 0,
'motion': 20,
'motionConfig': 2,
'name': 'Zone open with Sensor',
'number': 1,
'rssi': 40,
'setTemp': 24,
'state': 'open',
'type': 1,
'value': 100,
}),
'z02': dict({
'error': 0,
'maxDamper': 100,
'measuredTemp': 25,
'minDamper': 0,
'motion': 21,
'motionConfig': 2,
'name': 'Zone closed with Sensor',
'number': 2,
'rssi': 10,
'setTemp': 24,
'state': 'close',
'type': 1,
'value': 0,
}),
'z03': dict({
'error': 0,
'maxDamper': 100,
'measuredTemp': 25,
'minDamper': 0,
'motion': 22,
'motionConfig': 2,
'name': 'Zone 3',
'number': 3,
'rssi': 25,
'setTemp': 24,
'state': 'close',
'type': 1,
'value': 0,
}),
'z04': dict({
'error': 0,
'maxDamper': 100,
'measuredTemp': 25,
'minDamper': 0,
'motion': 1,
'motionConfig': 1,
'name': 'Zone 4',
'number': 4,
'rssi': 75,
'setTemp': 24,
'state': 'close',
'type': 1,
'value': 0,
}),
'z05': dict({
'error': 0,
'maxDamper': 100,
'measuredTemp': 25,
'minDamper': 0,
'motion': 5,
'motionConfig': 1,
'name': 'Zone 5',
'number': 5,
'rssi': 100,
'setTemp': 24,
'state': 'close',
'type': 1,
'value': 0,
}),
}),
}),
'ac2': dict({
'info': dict({
'aaAutoFanModeEnabled': True,
'climateControlModeEnabled': True,
'climateControlModeIsRunning': False,
'countDownToOff': 0,
'countDownToOn': 20,
'fan': 'autoAA',
'filterCleanStatus': 1,
'freshAirStatus': 'none',
'mode': 'cool',
'myAutoModeCurrentSetMode': 'cool',
'myAutoModeEnabled': False,
'myAutoModeIsRunning': False,
'myZone': 1,
'name': 'mytemp',
'setTemp': 24,
'state': 'off',
}),
'zones': dict({
'z01': dict({
'error': 0,
'maxDamper': 100,
'measuredTemp': 25,
'minDamper': 0,
'motion': 20,
'motionConfig': 2,
'name': 'Zone A',
'number': 1,
'rssi': 40,
'setTemp': 24,
'state': 'open',
'type': 1,
'value': 100,
}),
'z02': dict({
'error': 0,
'maxDamper': 100,
'measuredTemp': 26,
'minDamper': 0,
'motion': 21,
'motionConfig': 2,
'name': 'Zone B',
'number': 2,
'rssi': 10,
'setTemp': 23,
'state': 'open',
'type': 1,
'value': 50,
}),
}),
}),
'ac3': dict({
'info': dict({
'aaAutoFanModeEnabled': True,
'climateControlModeEnabled': False,
'climateControlModeIsRunning': False,
'countDownToOff': 0,
'countDownToOn': 0,
'fan': 'autoAA',
'filterCleanStatus': 1,
'freshAirStatus': 'none',
'mode': 'myauto',
'myAutoCoolTargetTemp': 24,
'myAutoHeatTargetTemp': 20,
'myAutoModeCurrentSetMode': 'cool',
'myAutoModeEnabled': True,
'myAutoModeIsRunning': True,
'myZone': 0,
'name': 'myauto',
'setTemp': 24,
'state': 'on',
}),
'zones': dict({
'z01': dict({
'error': 0,
'maxDamper': 100,
'measuredTemp': 0,
'minDamper': 0,
'motion': 0,
'motionConfig': 0,
'name': 'Zone Y',
'number': 1,
'rssi': 0,
'setTemp': 24,
'state': 'open',
'type': 0,
'value': 100,
}),
'z02': dict({
'error': 0,
'maxDamper': 100,
'measuredTemp': 0,
'minDamper': 0,
'motion': 0,
'motionConfig': 0,
'name': 'Zone Z',
'number': 2,
'rssi': 0,
'setTemp': 24,
'state': 'close',
'type': 0,
'value': 0,
}),
}),
}),
}),
'myLights': dict({
'lights': dict({
'100': dict({
'id': '100',
'moduleType': 'RM2',
'name': 'Light A',
'relay': True,
'state': 'off',
}),
'101': dict({
'id': '101',
'name': 'Light B',
'state': 'on',
'value': 50,
}),
}),
}),
'myThings': dict({
'things': dict({
'200': dict({
'buttonType': 'upDown',
'channelDipState': 1,
'id': '200',
'name': 'Blind 1',
'value': 100,
}),
'201': dict({
'buttonType': 'upDown',
'channelDipState': 2,
'id': '201',
'name': 'Blind 2',
'value': 0,
}),
'202': dict({
'buttonType': 'openClose',
'channelDipState': 3,
'id': '202',
'name': 'Garage',
'value': 100,
}),
'203': dict({
'buttonType': 'onOff',
'channelDipState': 4,
'id': '203',
'name': 'Thing Light',
'value': 100,
}),
'204': dict({
'buttonType': 'upDown',
'channelDipState': 5,
'id': '204',
'name': 'Thing Light Dimmable',
'value': 100,
}),
'205': dict({
'buttonType': 'onOff',
'channelDipState': 8,
'id': '205',
'name': 'Relay',
'value': 100,
}),
'206': dict({
'buttonType': 'onOff',
'channelDipState': 9,
'id': '206',
'name': 'Fan',
'value': 100,
}),
}),
}),
'system': dict({
'hasAircons': True,
'hasLights': True,
'hasSensors': False,
'hasThings': True,
'hasThingsBOG': False,
'hasThingsLight': False,
'myAppRev': '1.234',
'name': 'testname',
'needsUpdate': False,
'rid': '**REDACTED**',
'sysType': 'e-zone',
}),
})
# ---

View File

@ -0,0 +1,32 @@
"""Test the Advantage Air Diagnostics."""
from syrupy.assertion import SnapshotAssertion
from homeassistant.core import HomeAssistant
from . import (
TEST_SYSTEM_DATA,
TEST_SYSTEM_URL,
add_mock_config,
)
from tests.components.diagnostics import get_diagnostics_for_config_entry
from tests.test_util.aiohttp import AiohttpClientMocker
from tests.typing import ClientSessionGenerator
async def test_select_async_setup_entry(
hass: HomeAssistant,
hass_client: ClientSessionGenerator,
aioclient_mock: AiohttpClientMocker,
snapshot: SnapshotAssertion,
) -> None:
"""Test select platform."""
aioclient_mock.get(
TEST_SYSTEM_URL,
text=TEST_SYSTEM_DATA,
)
entry = await add_mock_config(hass)
diag = await get_diagnostics_for_config_entry(hass, hass_client, entry)
assert diag == snapshot