Add diagnostic support to Rituals Perfume Genie (#94373)

This commit is contained in:
Franck Nijhof 2023-06-12 11:33:47 +02:00 committed by GitHub
parent ce02261303
commit eb2b1d2970
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 307 additions and 1 deletions

View file

@ -0,0 +1,31 @@
"""Diagnostics support for Rituals Perfume Genie."""
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
from .coordinator import RitualsDataUpdateCoordinator
TO_REDACT = {
"hublot",
"hash",
}
async def async_get_config_entry_diagnostics(
hass: HomeAssistant, entry: ConfigEntry
) -> dict[str, Any]:
"""Return diagnostics for a config entry."""
coordinators: dict[str, RitualsDataUpdateCoordinator] = hass.data[DOMAIN][
entry.entry_id
]
return {
"diffusers": [
async_redact_data(coordinator.diffuser.data, TO_REDACT)
for coordinator in coordinators.values()
]
}

View file

@ -7,7 +7,7 @@ from homeassistant.components.rituals_perfume_genie.const import ACCOUNT_HASH, D
from homeassistant.config_entries import ConfigEntryState
from homeassistant.core import HomeAssistant
from tests.common import MockConfigEntry
from tests.common import MockConfigEntry, load_json_object_fixture
def mock_config_entry(unique_id: str, entry_id: str = "an_entry_id") -> MockConfigEntry:
@ -58,6 +58,7 @@ def mock_diffuser(
diffuser_mock.update_data = AsyncMock()
diffuser_mock.version = version
diffuser_mock.wifi_percentage = wifi_percentage
diffuser_mock.data = load_json_object_fixture("data.json", DOMAIN)
return diffuser_mock

View file

@ -0,0 +1,121 @@
{
"hub": {
"hublot": "LOT123",
"hash": "1234567890abcdefgghijklmnopqrstuvwxyz",
"status": 1,
"title": null,
"current_time": "2023-06-09T20:50",
"cached_time": "2023-06-09T20:48",
"ping_update": "25",
"attributes": {
"roomc": "4",
"speedc": "3",
"fanc": "1",
"roomnamec": "Living room",
"resetc": "",
"fspacenamec": "",
"fspacetypec": ""
},
"sensors": {
"wific": {
"id": 10,
"sensor_id": 1,
"title": "High",
"description": "",
"icon": "icon-signal.png",
"image": "",
"discover_image": "",
"discover_url": null,
"min_value": "-69.99",
"max_value": "-0.00",
"interval": "1",
"created_at": "2017-03-10 16:17:30",
"updated_at": "2020-06-17 16:57:53",
"default": 0
},
"fillc": {
"id": 38,
"sensor_id": 3,
"title": "90-100%",
"description": "",
"icon": "icon-fill.png",
"image": "",
"discover_image": "",
"discover_url": "",
"min_value": "0",
"max_value": "2000",
"interval": "",
"created_at": "2017-10-16 07:50:23",
"updated_at": "2021-02-17 13:42:16",
"default": 0
},
"rfidc": {
"id": 54,
"sensor_id": 4,
"title": "Private Collection Sweet Jasmine",
"description": "",
"icon": "icon-jasmine.png",
"image": "background-jasmine.png",
"discover_image": "discover-jasmine.png",
"discover_url": "sweet-jasmine-cartridge-1105402.html",
"min_value": "05377650",
"max_value": "05377650",
"interval": "",
"created_at": "2019-04-04 07:53:32",
"updated_at": "2021-01-26 14:17:03",
"default": 0
},
"versionc": "5.2-rc15",
"ipc": "1682963060",
"rpsc": {
"id": 48,
"sensor_id": 12,
"title": "Fan on",
"description": "",
"icon": "",
"image": "",
"discover_image": "",
"discover_url": null,
"min_value": "5",
"max_value": "10000",
"interval": "",
"created_at": "2018-01-23 12:05:45",
"updated_at": "2019-08-01 14:54:53",
"default": 0
},
"resetc": "External System",
"chipidc": "9820410",
"errorc": "",
"onlinec": {
"id": 31,
"sensor_id": 16,
"title": "Online",
"description": "",
"icon": "",
"image": "",
"discover_image": "",
"discover_url": null,
"min_value": "1",
"max_value": "1",
"interval": "",
"created_at": "2017-09-07 08:23:30",
"updated_at": "2017-09-07 08:23:30",
"default": 0
}
},
"settings": [
{
"schedule_id": 1835730,
"start": "07:30",
"end": "08:30",
"mon": 1,
"tue": 1,
"wed": 1,
"thu": 1,
"fri": 1,
"sat": 1,
"sun": 1
}
]
}
}

View file

@ -0,0 +1,128 @@
# serializer version: 1
# name: test_diagnostics
dict({
'diffusers': list([
dict({
'hub': dict({
'attributes': dict({
'fanc': '1',
'fspacenamec': '',
'fspacetypec': '',
'resetc': '',
'roomc': '4',
'roomnamec': 'Living room',
'speedc': '3',
}),
'cached_time': '2023-06-09T20:48',
'current_time': '2023-06-09T20:50',
'hash': '**REDACTED**',
'hublot': '**REDACTED**',
'ping_update': '25',
'sensors': dict({
'chipidc': '9820410',
'errorc': '',
'fillc': dict({
'created_at': '2017-10-16 07:50:23',
'default': 0,
'description': '',
'discover_image': '',
'discover_url': '',
'icon': 'icon-fill.png',
'id': 38,
'image': '',
'interval': '',
'max_value': '2000',
'min_value': '0',
'sensor_id': 3,
'title': '90-100%',
'updated_at': '2021-02-17 13:42:16',
}),
'ipc': '1682963060',
'onlinec': dict({
'created_at': '2017-09-07 08:23:30',
'default': 0,
'description': '',
'discover_image': '',
'discover_url': None,
'icon': '',
'id': 31,
'image': '',
'interval': '',
'max_value': '1',
'min_value': '1',
'sensor_id': 16,
'title': 'Online',
'updated_at': '2017-09-07 08:23:30',
}),
'resetc': 'External System',
'rfidc': dict({
'created_at': '2019-04-04 07:53:32',
'default': 0,
'description': '',
'discover_image': 'discover-jasmine.png',
'discover_url': 'sweet-jasmine-cartridge-1105402.html',
'icon': 'icon-jasmine.png',
'id': 54,
'image': 'background-jasmine.png',
'interval': '',
'max_value': '05377650',
'min_value': '05377650',
'sensor_id': 4,
'title': 'Private Collection Sweet Jasmine',
'updated_at': '2021-01-26 14:17:03',
}),
'rpsc': dict({
'created_at': '2018-01-23 12:05:45',
'default': 0,
'description': '',
'discover_image': '',
'discover_url': None,
'icon': '',
'id': 48,
'image': '',
'interval': '',
'max_value': '10000',
'min_value': '5',
'sensor_id': 12,
'title': 'Fan on',
'updated_at': '2019-08-01 14:54:53',
}),
'versionc': '5.2-rc15',
'wific': dict({
'created_at': '2017-03-10 16:17:30',
'default': 0,
'description': '',
'discover_image': '',
'discover_url': None,
'icon': 'icon-signal.png',
'id': 10,
'image': '',
'interval': '1',
'max_value': '-0.00',
'min_value': '-69.99',
'sensor_id': 1,
'title': 'High',
'updated_at': '2020-06-17 16:57:53',
}),
}),
'settings': list([
dict({
'end': '08:30',
'fri': 1,
'mon': 1,
'sat': 1,
'schedule_id': 1835730,
'start': '07:30',
'sun': 1,
'thu': 1,
'tue': 1,
'wed': 1,
}),
]),
'status': 1,
'title': None,
}),
}),
]),
})
# ---

View file

@ -0,0 +1,25 @@
"""Tests for the diagnostics data provided by the Rituals Perfume Genie integration."""
from syrupy.assertion import SnapshotAssertion
from homeassistant.core import HomeAssistant
from .common import init_integration, mock_config_entry, mock_diffuser
from tests.components.diagnostics import get_diagnostics_for_config_entry
from tests.typing import ClientSessionGenerator
async def test_diagnostics(
hass: HomeAssistant,
hass_client: ClientSessionGenerator,
snapshot: SnapshotAssertion,
) -> None:
"""Test diagnostics."""
config_entry = mock_config_entry(unique_id="number_test")
diffuser = mock_diffuser(hublot="lot123", perfume_amount=2)
await init_integration(hass, config_entry, [diffuser])
assert (
await get_diagnostics_for_config_entry(hass, hass_client, config_entry)
== snapshot
)