hass-core/tests/components/discovergy/test_diagnostics.py

79 lines
2.5 KiB
Python
Raw Normal View History

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 19:44:00 +02:00
"""Test Discovergy diagnostics."""
from homeassistant.components.diagnostics import REDACTED
from homeassistant.core import HomeAssistant
from . import init_integration
from tests.components.diagnostics import get_diagnostics_for_config_entry
from tests.typing import ClientSessionGenerator
async def test_entry_diagnostics(
hass: HomeAssistant, hass_client: ClientSessionGenerator
) -> None:
"""Test config entry diagnostics."""
entry = await init_integration(hass)
result = await get_diagnostics_for_config_entry(hass, hass_client, entry)
assert result["entry"] == {
"entry_id": entry.entry_id,
"version": 1,
"domain": "discovergy",
"title": REDACTED,
"data": {"email": REDACTED, "password": REDACTED},
"options": {},
"pref_disable_new_entities": False,
"pref_disable_polling": False,
"source": "user",
"unique_id": REDACTED,
"disabled_by": None,
}
assert result["meters"] == [
{
"additional": {
"administrationNumber": REDACTED,
"currentScalingFactor": 1,
"firstMeasurementTime": 1517569090926,
"fullSerialNumber": REDACTED,
"internalMeters": 1,
"lastMeasurementTime": 1678430543742,
"loadProfileType": "SLP",
"manufacturerId": "TST",
"printedFullSerialNumber": REDACTED,
"scalingFactor": 1,
"type": "TST",
"voltageScalingFactor": 1,
},
"full_serial_number": REDACTED,
"load_profile_type": "SLP",
"location": REDACTED,
"measurement_type": "ELECTRICITY",
"meter_id": "f8d610b7a8cc4e73939fa33b990ded54",
"serial_number": REDACTED,
"type": "TST",
}
]
assert result["readings"] == {
"f8d610b7a8cc4e73939fa33b990ded54": {
"time": "2023-03-10T07:32:06.702000",
"values": {
"energy": 119348699715000.0,
"energy1": 2254180000.0,
"energy2": 119346445534000.0,
"energyOut": 55048723044000.0,
"energyOut1": 0.0,
"energyOut2": 0.0,
"power": 531750.0,
"power1": 142680.0,
"power2": 138010.0,
"power3": 251060.0,
"voltage1": 239800.0,
"voltage2": 239700.0,
"voltage3": 239000.0,
},
}
}