Fix homewizard diagnostics and add tests (#72611)
parent
ce4825c9e2
commit
f41b2fa2cf
homeassistant/components/homewizard
tests/components/homewizard
|
@ -491,7 +491,6 @@ omit =
|
|||
homeassistant/components/homematic/*
|
||||
homeassistant/components/home_plus_control/api.py
|
||||
homeassistant/components/home_plus_control/switch.py
|
||||
homeassistant/components/homewizard/diagnostics.py
|
||||
homeassistant/components/homeworks/*
|
||||
homeassistant/components/honeywell/__init__.py
|
||||
homeassistant/components/honeywell/climate.py
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
"""Diagnostics support for P1 Monitor."""
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import asdict
|
||||
from typing import Any
|
||||
|
||||
from homeassistant.components.diagnostics import async_redact_data
|
||||
|
@ -21,10 +22,10 @@ async def async_get_config_entry_diagnostics(
|
|||
coordinator: HWEnergyDeviceUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
|
||||
|
||||
meter_data = {
|
||||
"device": coordinator.api.device.todict(),
|
||||
"data": coordinator.api.data.todict(),
|
||||
"state": coordinator.api.state.todict()
|
||||
if coordinator.api.state is not None
|
||||
"device": asdict(coordinator.data["device"]),
|
||||
"data": asdict(coordinator.data["data"]),
|
||||
"state": asdict(coordinator.data["state"])
|
||||
if coordinator.data["state"] is not None
|
||||
else None,
|
||||
}
|
||||
|
||||
|
|
|
@ -1,10 +1,15 @@
|
|||
"""Fixtures for HomeWizard integration tests."""
|
||||
import json
|
||||
from unittest.mock import AsyncMock, patch
|
||||
|
||||
from homewizard_energy.models import Data, Device, State
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.homewizard.const import DOMAIN
|
||||
from homeassistant.const import CONF_IP_ADDRESS
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
from tests.common import MockConfigEntry, load_fixture
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
@ -25,6 +30,46 @@ def mock_config_entry() -> MockConfigEntry:
|
|||
return MockConfigEntry(
|
||||
title="Product Name (aabbccddeeff)",
|
||||
domain=DOMAIN,
|
||||
data={},
|
||||
data={CONF_IP_ADDRESS: "1.2.3.4"},
|
||||
unique_id="aabbccddeeff",
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_homewizardenergy():
|
||||
"""Return a mocked P1 meter."""
|
||||
with patch(
|
||||
"homeassistant.components.homewizard.coordinator.HomeWizardEnergy",
|
||||
) as device:
|
||||
client = device.return_value
|
||||
client.device = AsyncMock(
|
||||
return_value=Device.from_dict(
|
||||
json.loads(load_fixture("homewizard/device.json"))
|
||||
)
|
||||
)
|
||||
client.data = AsyncMock(
|
||||
return_value=Data.from_dict(
|
||||
json.loads(load_fixture("homewizard/data.json"))
|
||||
)
|
||||
)
|
||||
client.state = AsyncMock(
|
||||
return_value=State.from_dict(
|
||||
json.loads(load_fixture("homewizard/state.json"))
|
||||
)
|
||||
)
|
||||
yield device
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def init_integration(
|
||||
hass: HomeAssistant,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
mock_homewizardenergy: AsyncMock,
|
||||
) -> MockConfigEntry:
|
||||
"""Set up the HomeWizard 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
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
"smr_version": 50,
|
||||
"meter_model": "ISKRA 2M550T-101",
|
||||
"wifi_ssid": "My Wi-Fi",
|
||||
"wifi_strength": 100,
|
||||
"total_power_import_t1_kwh": 1234.111,
|
||||
"total_power_import_t2_kwh": 5678.222,
|
||||
"total_power_export_t1_kwh": 4321.333,
|
||||
"total_power_export_t2_kwh": 8765.444,
|
||||
"active_power_w": -123,
|
||||
"active_power_l1_w": -123,
|
||||
"active_power_l2_w": 456,
|
||||
"active_power_l3_w": 123.456,
|
||||
"total_gas_m3": 1122.333,
|
||||
"gas_timestamp": 210314112233
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"product_type": "HWE-P1",
|
||||
"product_name": "P1 Meter",
|
||||
"serial": "3c39e7aabbcc",
|
||||
"firmware_version": "2.11",
|
||||
"api_version": "v1"
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"power_on": true,
|
||||
"switch_lock": false,
|
||||
"brightness": 255
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
"""Tests for diagnostics data."""
|
||||
from aiohttp import ClientSession
|
||||
|
||||
from homeassistant.components.diagnostics import REDACTED
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
from tests.components.diagnostics import get_diagnostics_for_config_entry
|
||||
|
||||
|
||||
async def test_diagnostics(
|
||||
hass: HomeAssistant,
|
||||
hass_client: ClientSession,
|
||||
init_integration: MockConfigEntry,
|
||||
):
|
||||
"""Test diagnostics."""
|
||||
assert await get_diagnostics_for_config_entry(
|
||||
hass, hass_client, init_integration
|
||||
) == {
|
||||
"entry": {"ip_address": REDACTED},
|
||||
"data": {
|
||||
"device": {
|
||||
"product_name": "P1 Meter",
|
||||
"product_type": "HWE-P1",
|
||||
"serial": REDACTED,
|
||||
"api_version": "v1",
|
||||
"firmware_version": "2.11",
|
||||
},
|
||||
"data": {
|
||||
"smr_version": 50,
|
||||
"meter_model": "ISKRA 2M550T-101",
|
||||
"wifi_ssid": REDACTED,
|
||||
"wifi_strength": 100,
|
||||
"total_power_import_t1_kwh": 1234.111,
|
||||
"total_power_import_t2_kwh": 5678.222,
|
||||
"total_power_export_t1_kwh": 4321.333,
|
||||
"total_power_export_t2_kwh": 8765.444,
|
||||
"active_power_w": -123,
|
||||
"active_power_l1_w": -123,
|
||||
"active_power_l2_w": 456,
|
||||
"active_power_l3_w": 123.456,
|
||||
"total_gas_m3": 1122.333,
|
||||
"gas_timestamp": "2021-03-14T11:22:33",
|
||||
},
|
||||
"state": {"power_on": True, "switch_lock": False, "brightness": 255},
|
||||
},
|
||||
}
|
Loading…
Reference in New Issue