* 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
76 lines
2.2 KiB
Python
76 lines
2.2 KiB
Python
"""Tests for the Discovergy integration."""
|
|
import datetime
|
|
from unittest.mock import patch
|
|
|
|
from pydiscovergy.models import Meter, Reading
|
|
|
|
from homeassistant.components.discovergy import DOMAIN
|
|
from homeassistant.const import CONF_EMAIL, CONF_PASSWORD
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
from tests.common import MockConfigEntry
|
|
|
|
GET_METERS = [
|
|
Meter(
|
|
meterId="f8d610b7a8cc4e73939fa33b990ded54",
|
|
serialNumber="abc123",
|
|
fullSerialNumber="abc123",
|
|
type="TST",
|
|
measurementType="ELECTRICITY",
|
|
loadProfileType="SLP",
|
|
location={
|
|
"city": "Testhause",
|
|
"street": "Teststraße",
|
|
"streetNumber": "1",
|
|
"country": "Germany",
|
|
},
|
|
manufacturerId="TST",
|
|
printedFullSerialNumber="abc123",
|
|
administrationNumber="12345",
|
|
scalingFactor=1,
|
|
currentScalingFactor=1,
|
|
voltageScalingFactor=1,
|
|
internalMeters=1,
|
|
firstMeasurementTime=1517569090926,
|
|
lastMeasurementTime=1678430543742,
|
|
),
|
|
]
|
|
|
|
LAST_READING = Reading(
|
|
time=datetime.datetime(2023, 3, 10, 7, 32, 6, 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,
|
|
},
|
|
)
|
|
|
|
|
|
async def init_integration(hass: HomeAssistant) -> MockConfigEntry:
|
|
"""Set up the Discovergy integration in Home Assistant."""
|
|
entry = MockConfigEntry(
|
|
domain=DOMAIN,
|
|
title="user@example.org",
|
|
unique_id="user@example.org",
|
|
data={CONF_EMAIL: "user@example.org", CONF_PASSWORD: "supersecretpassword"},
|
|
)
|
|
|
|
with patch("pydiscovergy.Discovergy.get_meters", return_value=GET_METERS), patch(
|
|
"pydiscovergy.Discovergy.get_last_reading", return_value=LAST_READING
|
|
):
|
|
entry.add_to_hass(hass)
|
|
await hass.config_entries.async_setup(entry.entry_id)
|
|
await hass.async_block_till_done()
|
|
|
|
return entry
|