mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 05:37:44 +00:00
Add diagnostic to Peblar Rocksolid EV Chargers integration (#133706)
This commit is contained in:
parent
5c2d769b54
commit
7326555f03
23
homeassistant/components/peblar/diagnostics.py
Normal file
23
homeassistant/components/peblar/diagnostics.py
Normal file
@ -0,0 +1,23 @@
|
||||
"""Diagnostics support for Peblar."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .coordinator import PeblarConfigEntry
|
||||
|
||||
|
||||
async def async_get_config_entry_diagnostics(
|
||||
hass: HomeAssistant, entry: PeblarConfigEntry
|
||||
) -> dict[str, Any]:
|
||||
"""Return diagnostics for a config entry."""
|
||||
return {
|
||||
"system_information": entry.runtime_data.system_information.to_dict(),
|
||||
"meter": entry.runtime_data.meter_coordinator.data.to_dict(),
|
||||
"versions": {
|
||||
"available": entry.runtime_data.version_coordinator.data.available.to_dict(),
|
||||
"current": entry.runtime_data.version_coordinator.data.current.to_dict(),
|
||||
},
|
||||
}
|
@ -40,7 +40,7 @@ rules:
|
||||
test-coverage: todo
|
||||
# Gold
|
||||
devices: todo
|
||||
diagnostics: todo
|
||||
diagnostics: done
|
||||
discovery-update-info: todo
|
||||
discovery: todo
|
||||
docs-data-update: todo
|
||||
|
@ -5,11 +5,12 @@ from __future__ import annotations
|
||||
from collections.abc import Generator
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
from peblar.models import PeblarSystemInformation
|
||||
from peblar import PeblarMeter, PeblarSystemInformation, PeblarVersions
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.peblar.const import DOMAIN
|
||||
from homeassistant.const import CONF_HOST, CONF_PASSWORD
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from tests.common import MockConfigEntry, load_fixture
|
||||
|
||||
@ -43,7 +44,34 @@ def mock_peblar() -> Generator[MagicMock]:
|
||||
patch("homeassistant.components.peblar.config_flow.Peblar", new=peblar_mock),
|
||||
):
|
||||
peblar = peblar_mock.return_value
|
||||
peblar.available_versions.return_value = PeblarVersions.from_json(
|
||||
load_fixture("available_versions.json", DOMAIN)
|
||||
)
|
||||
peblar.current_versions.return_value = PeblarVersions.from_json(
|
||||
load_fixture("current_versions.json", DOMAIN)
|
||||
)
|
||||
peblar.system_information.return_value = PeblarSystemInformation.from_json(
|
||||
load_fixture("system_information.json", DOMAIN)
|
||||
)
|
||||
|
||||
api = peblar.rest_api.return_value
|
||||
api.meter.return_value = PeblarMeter.from_json(
|
||||
load_fixture("meter.json", DOMAIN)
|
||||
)
|
||||
|
||||
yield peblar
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def init_integration(
|
||||
hass: HomeAssistant,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
mock_peblar: MagicMock,
|
||||
) -> MockConfigEntry:
|
||||
"""Set up the Peblar integration for testing."""
|
||||
mock_config_entry.add_to_hass(hass)
|
||||
|
||||
await hass.config_entries.async_setup(mock_config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
return mock_config_entry
|
||||
|
4
tests/components/peblar/fixtures/available_versions.json
Normal file
4
tests/components/peblar/fixtures/available_versions.json
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"Customization": "Peblar-1.9",
|
||||
"Firmware": "1.6.2+1+WL-1"
|
||||
}
|
4
tests/components/peblar/fixtures/current_versions.json
Normal file
4
tests/components/peblar/fixtures/current_versions.json
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"Customization": "Peblar-1.9",
|
||||
"Firmware": "1.6.1+1+WL-1"
|
||||
}
|
14
tests/components/peblar/fixtures/meter.json
Normal file
14
tests/components/peblar/fixtures/meter.json
Normal file
@ -0,0 +1,14 @@
|
||||
{
|
||||
"CurrentPhase1": 0,
|
||||
"CurrentPhase2": 0,
|
||||
"CurrentPhase3": 0,
|
||||
"EnergySession": 0,
|
||||
"EnergyTotal": 880321,
|
||||
"PowerPhase1": 0,
|
||||
"PowerPhase2": 0,
|
||||
"PowerPhase3": 0,
|
||||
"PowerTotal": 0,
|
||||
"VoltagePhase1": 230,
|
||||
"VoltagePhase2": null,
|
||||
"VoltagePhase3": null
|
||||
}
|
93
tests/components/peblar/snapshots/test_diagnostics.ambr
Normal file
93
tests/components/peblar/snapshots/test_diagnostics.ambr
Normal file
@ -0,0 +1,93 @@
|
||||
# serializer version: 1
|
||||
# name: test_diagnostics
|
||||
dict({
|
||||
'meter': dict({
|
||||
'CurrentPhase1': 0,
|
||||
'CurrentPhase2': 0,
|
||||
'CurrentPhase3': 0,
|
||||
'EnergySession': 0,
|
||||
'EnergyTotal': 880321,
|
||||
'PowerPhase1': 0,
|
||||
'PowerPhase2': 0,
|
||||
'PowerPhase3': 0,
|
||||
'PowerTotal': 0,
|
||||
'VoltagePhase1': 230,
|
||||
}),
|
||||
'system_information': dict({
|
||||
'BopCalIGainA': 264625,
|
||||
'BopCalIGainB': 267139,
|
||||
'BopCalIGainC': 239155,
|
||||
'CanChangeChargingPhases': False,
|
||||
'CanChargeSinglePhase': True,
|
||||
'CanChargeThreePhases': False,
|
||||
'CustomerId': 'PBLR-0000645',
|
||||
'CustomerUpdatePackagePubKey': '''
|
||||
-----BEGIN PUBLIC KEY-----
|
||||
lorem ipsum
|
||||
-----END PUBLIC KEY-----
|
||||
|
||||
''',
|
||||
'EthMacAddr': '00:0F:11:58:86:97',
|
||||
'FwIdent': '1.6.1+1+WL-1',
|
||||
'Hostname': 'PBLR-0000645',
|
||||
'HwFixedCableRating': 20,
|
||||
'HwFwCompat': 'wlac-2',
|
||||
'HwHas4pRelay': False,
|
||||
'HwHasBop': True,
|
||||
'HwHasBuzzer': True,
|
||||
'HwHasDualSocket': False,
|
||||
'HwHasEichrechtLaserMarking': False,
|
||||
'HwHasEthernet': True,
|
||||
'HwHasLed': True,
|
||||
'HwHasLte': False,
|
||||
'HwHasMeter': True,
|
||||
'HwHasMeterDisplay': True,
|
||||
'HwHasPlc': False,
|
||||
'HwHasRfid': True,
|
||||
'HwHasRs485': True,
|
||||
'HwHasShutter': False,
|
||||
'HwHasSocket': False,
|
||||
'HwHasTpm': False,
|
||||
'HwHasWlan': True,
|
||||
'HwMaxCurrent': 16,
|
||||
'HwOneOrThreePhase': 3,
|
||||
'HwUKCompliant': False,
|
||||
'MainboardPn': '6004-2300-7600',
|
||||
'MainboardSn': '23-38-A4E-2MC',
|
||||
'MeterCalIGainA': 267369,
|
||||
'MeterCalIGainB': 228286,
|
||||
'MeterCalIGainC': 246455,
|
||||
'MeterCalIRmsOffsetA': 15573,
|
||||
'MeterCalIRmsOffsetB': 268422963,
|
||||
'MeterCalIRmsOffsetC': 9082,
|
||||
'MeterCalPhaseA': 250,
|
||||
'MeterCalPhaseB': 271,
|
||||
'MeterCalPhaseC': 271,
|
||||
'MeterCalVGainA': 250551,
|
||||
'MeterCalVGainB': 246074,
|
||||
'MeterCalVGainC': 230191,
|
||||
'MeterFwIdent': 'b9cbcd',
|
||||
'NorFlash': 'True',
|
||||
'ProductModelName': 'WLAC1-H11R0WE0ICR00',
|
||||
'ProductPn': '6004-2300-8002',
|
||||
'ProductSn': '23-45-A4O-MOF',
|
||||
'ProductVendorName': 'Peblar',
|
||||
'WlanApMacAddr': '00:0F:11:58:86:98',
|
||||
'WlanStaMacAddr': '00:0F:11:58:86:99',
|
||||
}),
|
||||
'versions': dict({
|
||||
'available': dict({
|
||||
'Customization': 'Peblar-1.9',
|
||||
'Firmware': '1.6.2+1+WL-1',
|
||||
'customization_version': '1.9',
|
||||
'firmware_version': '1.6.2',
|
||||
}),
|
||||
'current': dict({
|
||||
'Customization': 'Peblar-1.9',
|
||||
'Firmware': '1.6.1+1+WL-1',
|
||||
'customization_version': '1.9',
|
||||
'firmware_version': '1.6.1',
|
||||
}),
|
||||
}),
|
||||
})
|
||||
# ---
|
22
tests/components/peblar/test_diagnostics.py
Normal file
22
tests/components/peblar/test_diagnostics.py
Normal file
@ -0,0 +1,22 @@
|
||||
"""Tests for the diagnostics data provided by the Peblar integration."""
|
||||
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
from tests.components.diagnostics import get_diagnostics_for_config_entry
|
||||
from tests.typing import ClientSessionGenerator
|
||||
|
||||
|
||||
async def test_diagnostics(
|
||||
hass: HomeAssistant,
|
||||
hass_client: ClientSessionGenerator,
|
||||
init_integration: MockConfigEntry,
|
||||
snapshot: SnapshotAssertion,
|
||||
) -> None:
|
||||
"""Test diagnostics."""
|
||||
assert (
|
||||
await get_diagnostics_for_config_entry(hass, hass_client, init_integration)
|
||||
== snapshot
|
||||
)
|
Loading…
x
Reference in New Issue
Block a user