Enhance diagnostics for Sensibo (#96150)

* Diag Sensibo

* Fix snapshot
This commit is contained in:
G Johansson 2023-07-09 22:50:12 +02:00 committed by GitHub
parent c720658c0f
commit 0546e7601c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 276 additions and 9 deletions

View File

@ -33,4 +33,8 @@ async def async_get_config_entry_diagnostics(
) -> dict[str, Any]:
"""Return diagnostics for Sensibo config entry."""
coordinator: SensiboDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
return async_redact_data(coordinator.data.raw, TO_REDACT)
diag_data = {}
diag_data["raw"] = async_redact_data(coordinator.data.raw, TO_REDACT)
for device, device_data in coordinator.data.parsed.items():
diag_data[device] = async_redact_data(device_data.__dict__, TO_REDACT)
return diag_data

View File

@ -0,0 +1,257 @@
# serializer version: 1
# name: test_diagnostics
dict({
'fanLevel': 'high',
'horizontalSwing': 'stopped',
'light': 'on',
'mode': 'heat',
'on': True,
'swing': 'stopped',
'targetTemperature': 25,
'timestamp': dict({
'secondsAgo': -1,
'time': '2022-04-30T11:23:30.019722Z',
}),
})
# ---
# name: test_diagnostics.1
dict({
'modes': dict({
'auto': dict({
'fanLevels': list([
'quiet',
'low',
'medium',
]),
'horizontalSwing': list([
'stopped',
'fixedLeft',
'fixedCenterLeft',
]),
'light': list([
'on',
'off',
]),
'swing': list([
'stopped',
'fixedTop',
'fixedMiddleTop',
]),
'temperatures': dict({
'C': dict({
'isNative': True,
'values': list([
10,
16,
17,
18,
19,
20,
]),
}),
'F': dict({
'isNative': False,
'values': list([
64,
66,
68,
]),
}),
}),
}),
'cool': dict({
'fanLevels': list([
'quiet',
'low',
'medium',
]),
'horizontalSwing': list([
'stopped',
'fixedLeft',
'fixedCenterLeft',
]),
'light': list([
'on',
'off',
]),
'swing': list([
'stopped',
'fixedTop',
'fixedMiddleTop',
]),
'temperatures': dict({
'C': dict({
'isNative': True,
'values': list([
10,
16,
17,
18,
19,
20,
]),
}),
'F': dict({
'isNative': False,
'values': list([
64,
66,
68,
]),
}),
}),
}),
'dry': dict({
'horizontalSwing': list([
'stopped',
'fixedLeft',
'fixedCenterLeft',
]),
'light': list([
'on',
'off',
]),
'swing': list([
'stopped',
'fixedTop',
'fixedMiddleTop',
]),
'temperatures': dict({
'C': dict({
'isNative': True,
'values': list([
10,
16,
17,
18,
19,
20,
]),
}),
'F': dict({
'isNative': False,
'values': list([
64,
66,
68,
]),
}),
}),
}),
'fan': dict({
'fanLevels': list([
'quiet',
'low',
'medium',
]),
'horizontalSwing': list([
'stopped',
'fixedLeft',
'fixedCenterLeft',
]),
'light': list([
'on',
'off',
]),
'swing': list([
'stopped',
'fixedTop',
'fixedMiddleTop',
]),
'temperatures': dict({
}),
}),
'heat': dict({
'fanLevels': list([
'quiet',
'low',
'medium',
]),
'horizontalSwing': list([
'stopped',
'fixedLeft',
'fixedCenterLeft',
]),
'light': list([
'on',
'off',
]),
'swing': list([
'stopped',
'fixedTop',
'fixedMiddleTop',
]),
'temperatures': dict({
'C': dict({
'isNative': True,
'values': list([
10,
16,
17,
18,
19,
20,
]),
}),
'F': dict({
'isNative': False,
'values': list([
63,
64,
66,
]),
}),
}),
}),
}),
})
# ---
# name: test_diagnostics.2
dict({
'low': 'low',
'medium': 'medium',
'quiet': 'quiet',
})
# ---
# name: test_diagnostics.3
dict({
'fixedmiddletop': 'fixedMiddleTop',
'fixedtop': 'fixedTop',
'stopped': 'stopped',
})
# ---
# name: test_diagnostics.4
dict({
'fixedcenterleft': 'fixedCenterLeft',
'fixedleft': 'fixedLeft',
'stopped': 'stopped',
})
# ---
# name: test_diagnostics.5
dict({
'fanlevel': 'low',
'horizontalswing': 'stopped',
'light': 'on',
'mode': 'heat',
'on': True,
'swing': 'stopped',
'targettemperature': 21,
'temperatureunit': 'c',
})
# ---
# name: test_diagnostics.6
dict({
'fanlevel': 'high',
'horizontalswing': 'stopped',
'light': 'on',
'mode': 'cool',
'on': True,
'swing': 'stopped',
'targettemperature': 21,
'temperatureunit': 'c',
})
# ---
# name: test_diagnostics.7
dict({
})
# ---

View File

@ -1,6 +1,8 @@
"""Test Sensibo diagnostics."""
from __future__ import annotations
from syrupy.assertion import SnapshotAssertion
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
@ -9,17 +11,21 @@ from tests.typing import ClientSessionGenerator
async def test_diagnostics(
hass: HomeAssistant, hass_client: ClientSessionGenerator, load_int: ConfigEntry
hass: HomeAssistant,
hass_client: ClientSessionGenerator,
load_int: ConfigEntry,
snapshot: SnapshotAssertion,
) -> None:
"""Test generating diagnostics for a config entry."""
entry = load_int
diag = await get_diagnostics_for_config_entry(hass, hass_client, entry)
assert diag["status"] == "success"
for device in diag["result"]:
assert device["id"] == "**REDACTED**"
assert device["qrId"] == "**REDACTED**"
assert device["macAddress"] == "**REDACTED**"
assert device["location"] == "**REDACTED**"
assert device["productModel"] in ["skyv2", "pure"]
assert diag["ABC999111"]["ac_states"] == snapshot
assert diag["ABC999111"]["full_capabilities"] == snapshot
assert diag["ABC999111"]["fan_modes_translated"] == snapshot
assert diag["ABC999111"]["swing_modes_translated"] == snapshot
assert diag["ABC999111"]["horizontal_swing_modes_translated"] == snapshot
assert diag["ABC999111"]["smart_low_state"] == snapshot
assert diag["ABC999111"]["smart_high_state"] == snapshot
assert diag["ABC999111"]["pure_conf"] == snapshot