Files
core/homeassistant/components/discovergy/diagnostics.py
Jan-Philipp Benecke d8ceb6463e Add new integration Discovergy (#54280)
* Add discovergy integration

* Capitalize measurement type as it is in uppercase

* Some logging and typing

* Add all-time total production power and check if meter has value before adding it

* Add tests for Discovergy and changing therefor library import

* Disable phase-specific sensor per default, set user_input as default for schema and implement some other suggestions form code review

* Removing translation, fixing import and some more review implementation

* Fixing CI issues

* Check if acces token keys are in dict the correct way

* Implement suggestions after code review

* Correcting property function

* Change state class to STATE_CLASS_TOTAL_INCREASING

* Add reauth workflow for Discovergy

* Bump pydiscovergy

* Implement code review

* Remove _meter from __init__

* Bump pydiscovergy & minor changes

* Add gas meter support

* bump pydiscovergy & error handling

* Add myself to CODEOWNERS for test directory

* Resorting CODEOWNERS

* Implement diagnostics and reduce API use

* Make homeassistant imports absolute

* Exclude diagnostics.py from coverage report

* Add sensors with different keys

* Reformatting files

* Use new naming style

* Refactoring and moving to basic auth for API authentication

* Remove device name form entity name

* Add integration type to discovergy and implement new unit of measurement

* Add system health to discovergy integration

* Use right array key when using an alternative_key & using UnitOfElectricPotential.VOLT

* Add options for precision and update interval to Discovergy

* Remove precision config option and let it handle HA

* Rename precision attribute and remove translation file

* Some formatting tweaks

* Some more tests

* Move sensor names to strings.json

* Redacting title and unique_id as it contains user email address
2023-06-06 13:44:00 -04:00

51 lines
1.6 KiB
Python

"""Diagnostics support for discovergy."""
from __future__ import annotations
from typing import Any
from pydiscovergy.models import Meter
from homeassistant.components.diagnostics import async_redact_data
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_EMAIL, CONF_PASSWORD, CONF_UNIQUE_ID
from homeassistant.core import HomeAssistant
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
from . import DiscovergyData
from .const import DOMAIN
TO_REDACT_CONFIG_ENTRY = {CONF_EMAIL, CONF_PASSWORD, CONF_UNIQUE_ID, "title"}
TO_REDACT_METER = {
"serial_number",
"full_serial_number",
"location",
"fullSerialNumber",
"printedFullSerialNumber",
"administrationNumber",
}
async def async_get_config_entry_diagnostics(
hass: HomeAssistant, entry: ConfigEntry
) -> dict[str, Any]:
"""Return diagnostics for a config entry."""
flattened_meter: list[dict] = []
last_readings: dict[str, dict] = {}
data: DiscovergyData = hass.data[DOMAIN][entry.entry_id]
meters: list[Meter] = data.meters # always returns a list
for meter in meters:
# make a dict of meter data and redact some data
flattened_meter.append(async_redact_data(meter.__dict__, TO_REDACT_METER))
# get last reading for meter and make a dict of it
coordinator: DataUpdateCoordinator = data.coordinators[meter.get_meter_id()]
last_readings[meter.get_meter_id()] = coordinator.data.__dict__
return {
"entry": async_redact_data(entry.as_dict(), TO_REDACT_CONFIG_ENTRY),
"meters": flattened_meter,
"readings": last_readings,
}