Add diagnostics to Enphase Envoy (#79950)

* Streamline Enphase Envoy config flow tests

* Don't test data results using constants

* Add diagnostics to Enphase Envoy

* Use whole config entry

* Redact serial number

* One call
This commit is contained in:
Aaron Bach 2022-10-18 10:25:07 -06:00 committed by GitHub
parent 414d478d3e
commit 78e66b6cbe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 94 additions and 0 deletions

View File

@ -0,0 +1,38 @@
"""Diagnostics support for Enphase Envoy."""
from __future__ import annotations
from typing import Any
from homeassistant.components.diagnostics import async_redact_data
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_NAME, CONF_PASSWORD, CONF_UNIQUE_ID, CONF_USERNAME
from homeassistant.core import HomeAssistant
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
from .const import COORDINATOR, DOMAIN
CONF_TITLE = "title"
TO_REDACT = {
CONF_NAME,
CONF_PASSWORD,
# Config entry title and unique ID may contain sensitive data:
CONF_TITLE,
CONF_UNIQUE_ID,
CONF_USERNAME,
}
async def async_get_config_entry_diagnostics(
hass: HomeAssistant, entry: ConfigEntry
) -> dict[str, Any]:
"""Return diagnostics for a config entry."""
coordinator: DataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id][COORDINATOR]
return async_redact_data(
{
"entry": entry.as_dict(),
"data": coordinator.data,
},
TO_REDACT,
)

View File

@ -0,0 +1,56 @@
"""Test Enphase Envoy diagnostics."""
from homeassistant.components.diagnostics import REDACTED
from tests.components.diagnostics import get_diagnostics_for_config_entry
async def test_entry_diagnostics(hass, config_entry, hass_client, setup_enphase_envoy):
"""Test config entry diagnostics."""
assert await get_diagnostics_for_config_entry(hass, hass_client, config_entry) == {
"entry": {
"entry_id": config_entry.entry_id,
"version": 1,
"domain": "enphase_envoy",
"title": REDACTED,
"data": {
"host": "1.1.1.1",
"name": REDACTED,
"username": REDACTED,
"password": REDACTED,
},
"options": {},
"pref_disable_new_entities": False,
"pref_disable_polling": False,
"source": "user",
"unique_id": REDACTED,
"disabled_by": None,
},
"data": {
"production": 1840,
"daily_production": 28223,
"seven_days_production": 174482,
"lifetime_production": 5924391,
"consumption": 1840,
"daily_consumption": 5923857,
"seven_days_consumption": 5923857,
"lifetime_consumption": 5923857,
"inverters_production": {
"202140024014": [136, "2022-10-08 16:43:36"],
"202140023294": [163, "2022-10-08 16:43:41"],
"202140013819": [130, "2022-10-08 16:43:31"],
"202140023794": [139, "2022-10-08 16:43:38"],
"202140023381": [130, "2022-10-08 16:43:47"],
"202140024176": [54, "2022-10-08 16:43:59"],
"202140003284": [132, "2022-10-08 16:43:55"],
"202140019854": [129, "2022-10-08 16:43:58"],
"202140020743": [131, "2022-10-08 16:43:49"],
"202140023531": [28, "2022-10-08 16:43:53"],
"202140024241": [164, "2022-10-08 16:43:33"],
"202140022963": [164, "2022-10-08 16:43:41"],
"202140023149": [118, "2022-10-08 16:43:47"],
"202140024828": [129, "2022-10-08 16:43:36"],
"202140023269": [133, "2022-10-08 16:43:43"],
"202140024157": [112, "2022-10-08 16:43:52"],
},
},
}