Use `entry.as_dict()` in RainMachine diagnostics (#80118)

* Use `entry.as_dict()` in RainMachine diagnostics

* One call
pull/80129/head^2
Aaron Bach 2022-10-11 12:15:07 -06:00 committed by GitHub
parent 8bc9aa9ea4
commit 687987f05b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 23 deletions

View File

@ -12,6 +12,7 @@ from homeassistant.const import (
CONF_LATITUDE, CONF_LATITUDE,
CONF_LONGITUDE, CONF_LONGITUDE,
CONF_PASSWORD, CONF_PASSWORD,
CONF_UNIQUE_ID,
) )
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
@ -32,6 +33,8 @@ TO_REDACT = {
CONF_STATION_NAME, CONF_STATION_NAME,
CONF_STATION_SOURCE, CONF_STATION_SOURCE,
CONF_TIMEZONE, CONF_TIMEZONE,
# Config entry unique ID may contain sensitive data:
CONF_UNIQUE_ID,
} }
@ -47,20 +50,16 @@ async def async_get_config_entry_diagnostics(
LOGGER.warning("Unable to download controller-specific diagnostics") LOGGER.warning("Unable to download controller-specific diagnostics")
controller_diagnostics = None controller_diagnostics = None
return { return async_redact_data(
"entry": { {
"title": entry.title, "entry": entry.as_dict(),
"data": async_redact_data(entry.data, TO_REDACT), "data": {
"options": dict(entry.options), "coordinator": {
},
"data": {
"coordinator": async_redact_data(
{
api_category: controller.data api_category: controller.data
for api_category, controller in data.coordinators.items() for api_category, controller in data.coordinators.items()
}, },
TO_REDACT, "controller_diagnostics": controller_diagnostics,
), },
"controller_diagnostics": controller_diagnostics,
}, },
} TO_REDACT,
)

View File

@ -10,6 +10,9 @@ async def test_entry_diagnostics(hass, config_entry, hass_client, setup_rainmach
"""Test config entry diagnostics.""" """Test config entry diagnostics."""
assert await get_diagnostics_for_config_entry(hass, hass_client, config_entry) == { assert await get_diagnostics_for_config_entry(hass, hass_client, config_entry) == {
"entry": { "entry": {
"entry_id": config_entry.entry_id,
"version": 2,
"domain": "rainmachine",
"title": "Mock Title", "title": "Mock Title",
"data": { "data": {
"ip_address": "192.168.1.100", "ip_address": "192.168.1.100",
@ -18,14 +21,15 @@ async def test_entry_diagnostics(hass, config_entry, hass_client, setup_rainmach
"ssl": True, "ssl": True,
}, },
"options": {}, "options": {},
"pref_disable_new_entities": False,
"pref_disable_polling": False,
"source": "user",
"unique_id": REDACTED,
"disabled_by": None,
}, },
"data": { "data": {
"coordinator": { "coordinator": {
"api.versions": { "api.versions": {"apiVer": "4.6.1", "hwVer": "3", "swVer": "4.0.1144"},
"apiVer": "4.6.1",
"hwVer": "3",
"swVer": "4.0.1144",
},
"machine.firmware_update_status": { "machine.firmware_update_status": {
"lastUpdateCheckTimestamp": 1657825288, "lastUpdateCheckTimestamp": 1657825288,
"packageDetails": [], "packageDetails": [],
@ -628,6 +632,9 @@ async def test_entry_diagnostics_failed_controller_diagnostics(
controller.diagnostics.current.side_effect = RainMachineError controller.diagnostics.current.side_effect = RainMachineError
assert await get_diagnostics_for_config_entry(hass, hass_client, config_entry) == { assert await get_diagnostics_for_config_entry(hass, hass_client, config_entry) == {
"entry": { "entry": {
"entry_id": config_entry.entry_id,
"version": 2,
"domain": "rainmachine",
"title": "Mock Title", "title": "Mock Title",
"data": { "data": {
"ip_address": "192.168.1.100", "ip_address": "192.168.1.100",
@ -636,14 +643,15 @@ async def test_entry_diagnostics_failed_controller_diagnostics(
"ssl": True, "ssl": True,
}, },
"options": {}, "options": {},
"pref_disable_new_entities": False,
"pref_disable_polling": False,
"source": "user",
"unique_id": REDACTED,
"disabled_by": None,
}, },
"data": { "data": {
"coordinator": { "coordinator": {
"api.versions": { "api.versions": {"apiVer": "4.6.1", "hwVer": "3", "swVer": "4.0.1144"},
"apiVer": "4.6.1",
"hwVer": "3",
"swVer": "4.0.1144",
},
"machine.firmware_update_status": { "machine.firmware_update_status": {
"lastUpdateCheckTimestamp": 1657825288, "lastUpdateCheckTimestamp": 1657825288,
"packageDetails": [], "packageDetails": [],