Replace/restructure HomeWizard device fixtures to reflect reality (#103311)

This commit is contained in:
Franck Nijhof 2023-11-04 13:37:08 +01:00 committed by GitHub
parent aa2a748235
commit 109944e4ff
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
23 changed files with 386 additions and 2404 deletions

View file

@ -3,6 +3,7 @@ from collections.abc import Generator
import json
from unittest.mock import AsyncMock, MagicMock, patch
from homewizard_energy.errors import NotFoundError
from homewizard_energy.models import Data, Device, State, System
import pytest
@ -10,39 +11,18 @@ from homeassistant.components.homewizard.const import DOMAIN
from homeassistant.const import CONF_IP_ADDRESS
from homeassistant.core import HomeAssistant
from tests.common import MockConfigEntry, load_fixture
from tests.common import MockConfigEntry, get_fixture_path, load_fixture
@pytest.fixture
def device_fixture() -> str:
"""Return the device fixture for a specific device."""
return "device-HWE-P1.json"
@pytest.fixture
def data_fixture() -> str:
"""Return the data fixture for a specific device."""
return "data-HWE-P1.json"
@pytest.fixture
def state_fixture() -> str:
"""Return the state fixture for a specific device."""
return "state.json"
@pytest.fixture
def system_fixture() -> str:
"""Return the system fixture for a specific device."""
return "system.json"
"""Return the device fixtures for a specific device."""
return "HWE-P1"
@pytest.fixture
def mock_homewizardenergy(
device_fixture: str,
data_fixture: str,
state_fixture: str,
system_fixture: str,
) -> MagicMock:
"""Return a mock bridge."""
with patch(
@ -53,18 +33,28 @@ def mock_homewizardenergy(
new=homewizard,
):
client = homewizard.return_value
client.device.return_value = Device.from_dict(
json.loads(load_fixture(device_fixture, DOMAIN))
json.loads(load_fixture(f"{device_fixture}/device.json", DOMAIN))
)
client.data.return_value = Data.from_dict(
json.loads(load_fixture(data_fixture, DOMAIN))
)
client.state.return_value = State.from_dict(
json.loads(load_fixture(state_fixture, DOMAIN))
)
client.system.return_value = System.from_dict(
json.loads(load_fixture(system_fixture, DOMAIN))
json.loads(load_fixture(f"{device_fixture}/data.json", DOMAIN))
)
if get_fixture_path(f"{device_fixture}/state.json", DOMAIN).exists():
client.state.return_value = State.from_dict(
json.loads(load_fixture(f"{device_fixture}/state.json", DOMAIN))
)
else:
client.state.side_effect = NotFoundError
if get_fixture_path(f"{device_fixture}/system.json", DOMAIN).exists():
client.system.return_value = System.from_dict(
json.loads(load_fixture(f"{device_fixture}/system.json", DOMAIN))
)
else:
client.system.side_effect = NotFoundError
yield client

View file

@ -0,0 +1,7 @@
{
"product_type": "HWE-P1",
"product_name": "P1 meter",
"serial": "3c39e7aabbcc",
"firmware_version": "4.19",
"api_version": "v1"
}

View file

@ -0,0 +1,3 @@
{
"cloud_enabled": true
}

View file

@ -0,0 +1,46 @@
{
"wifi_ssid": "My Wi-Fi",
"wifi_strength": 94,
"smr_version": null,
"meter_model": null,
"unique_meter_id": null,
"active_tariff": null,
"total_power_import_kwh": null,
"total_power_import_t1_kwh": 63.651,
"total_power_import_t2_kwh": null,
"total_power_import_t3_kwh": null,
"total_power_import_t4_kwh": null,
"total_power_export_kwh": null,
"total_power_export_t1_kwh": 0,
"total_power_export_t2_kwh": null,
"total_power_export_t3_kwh": null,
"total_power_export_t4_kwh": null,
"active_power_w": 1457.277,
"active_power_l1_w": 1457.277,
"active_power_l2_w": null,
"active_power_l3_w": null,
"active_voltage_l1_v": null,
"active_voltage_l2_v": null,
"active_voltage_l3_v": null,
"active_current_l1_a": null,
"active_current_l2_a": null,
"active_current_l3_a": null,
"active_frequency_hz": null,
"voltage_sag_l1_count": null,
"voltage_sag_l2_count": null,
"voltage_sag_l3_count": null,
"voltage_swell_l1_count": null,
"voltage_swell_l2_count": null,
"voltage_swell_l3_count": null,
"any_power_fail_count": null,
"long_power_fail_count": null,
"active_power_average_w": null,
"monthly_power_peak_w": null,
"monthly_power_peak_timestamp": null,
"total_gas_m3": null,
"gas_timestamp": null,
"gas_unique_id": null,
"active_liter_lpm": null,
"total_liter_m3": null,
"external_devices": null
}

View file

@ -0,0 +1,3 @@
{
"cloud_enabled": true
}

View file

@ -0,0 +1,46 @@
{
"wifi_ssid": "My Wi-Fi",
"wifi_strength": 92,
"smr_version": null,
"meter_model": null,
"unique_meter_id": null,
"active_tariff": null,
"total_power_import_kwh": 2.705,
"total_power_import_t1_kwh": 2.705,
"total_power_import_t2_kwh": null,
"total_power_import_t3_kwh": null,
"total_power_import_t4_kwh": null,
"total_power_export_kwh": 255.551,
"total_power_export_t1_kwh": 255.551,
"total_power_export_t2_kwh": null,
"total_power_export_t3_kwh": null,
"total_power_export_t4_kwh": null,
"active_power_w": -1058.296,
"active_power_l1_w": -1058.296,
"active_power_l2_w": null,
"active_power_l3_w": null,
"active_voltage_l1_v": null,
"active_voltage_l2_v": null,
"active_voltage_l3_v": null,
"active_current_l1_a": null,
"active_current_l2_a": null,
"active_current_l3_a": null,
"active_frequency_hz": null,
"voltage_sag_l1_count": null,
"voltage_sag_l2_count": null,
"voltage_sag_l3_count": null,
"voltage_swell_l1_count": null,
"voltage_swell_l2_count": null,
"voltage_swell_l3_count": null,
"any_power_fail_count": null,
"long_power_fail_count": null,
"active_power_average_w": null,
"monthly_power_peak_w": null,
"monthly_power_peak_timestamp": null,
"total_gas_m3": null,
"gas_timestamp": null,
"gas_unique_id": null,
"active_liter_lpm": null,
"total_liter_m3": null,
"external_devices": null
}

View file

@ -0,0 +1,3 @@
{
"cloud_enabled": true
}

View file

@ -1,75 +1,5 @@
# serializer version: 1
# name: test_diagnostics
dict({
'data': dict({
'data': dict({
'active_current_l1_a': -4,
'active_current_l2_a': 2,
'active_current_l3_a': 0,
'active_frequency_hz': 50,
'active_liter_lpm': 12.345,
'active_power_average_w': 123.0,
'active_power_l1_w': -123,
'active_power_l2_w': 456,
'active_power_l3_w': 123.456,
'active_power_w': -123,
'active_tariff': 2,
'active_voltage_l1_v': 230.111,
'active_voltage_l2_v': 230.222,
'active_voltage_l3_v': 230.333,
'any_power_fail_count': 4,
'external_devices': None,
'gas_timestamp': '2021-03-14T11:22:33',
'gas_unique_id': '**REDACTED**',
'long_power_fail_count': 5,
'meter_model': 'ISKRA 2M550T-101',
'monthly_power_peak_timestamp': '2023-01-01T08:00:10',
'monthly_power_peak_w': 1111.0,
'smr_version': 50,
'total_gas_m3': 1122.333,
'total_liter_m3': 1234.567,
'total_energy_export_kwh': 13086.777,
'total_energy_export_t1_kwh': 4321.333,
'total_energy_export_t2_kwh': 8765.444,
'total_energy_export_t3_kwh': None,
'total_energy_export_t4_kwh': None,
'total_energy_import_kwh': 13779.338,
'total_energy_import_t1_kwh': 10830.511,
'total_energy_import_t2_kwh': 2948.827,
'total_energy_import_t3_kwh': None,
'total_energy_import_t4_kwh': None,
'unique_meter_id': '**REDACTED**',
'voltage_sag_l1_count': 1,
'voltage_sag_l2_count': 2,
'voltage_sag_l3_count': 3,
'voltage_swell_l1_count': 4,
'voltage_swell_l2_count': 5,
'voltage_swell_l3_count': 6,
'wifi_ssid': '**REDACTED**',
'wifi_strength': 100,
}),
'device': dict({
'api_version': 'v1',
'firmware_version': '2.11',
'product_name': 'P1 Meter',
'product_type': 'HWE-SKT',
'serial': '**REDACTED**',
}),
'state': dict({
'brightness': 255,
'power_on': True,
'switch_lock': False,
}),
'system': dict({
'cloud_enabled': True,
}),
}),
'entry': dict({
'ip_address': '**REDACTED**',
}),
})
# ---
# name: test_diagnostics[device-HWE-P1.json]
# name: test_diagnostics[HWE-P1]
dict({
'data': dict({
'data': dict({
@ -138,54 +68,54 @@
}),
})
# ---
# name: test_diagnostics[device-HWE-SKT.json]
# name: test_diagnostics[HWE-SKT]
dict({
'data': dict({
'data': dict({
'active_current_l1_a': -4,
'active_current_l2_a': 2,
'active_current_l3_a': 0,
'active_frequency_hz': 50,
'active_liter_lpm': 12.345,
'active_power_average_w': 123.0,
'active_power_l1_w': -123,
'active_power_l2_w': 456,
'active_power_l3_w': 123.456,
'active_power_w': -123,
'active_tariff': 2,
'active_voltage_l1_v': 230.111,
'active_voltage_l2_v': 230.222,
'active_voltage_l3_v': 230.333,
'any_power_fail_count': 4,
'active_current_l1_a': None,
'active_current_l2_a': None,
'active_current_l3_a': None,
'active_frequency_hz': None,
'active_liter_lpm': None,
'active_power_average_w': None,
'active_power_l1_w': 1457.277,
'active_power_l2_w': None,
'active_power_l3_w': None,
'active_power_w': 1457.277,
'active_tariff': None,
'active_voltage_l1_v': None,
'active_voltage_l2_v': None,
'active_voltage_l3_v': None,
'any_power_fail_count': None,
'external_devices': None,
'gas_timestamp': '2021-03-14T11:22:33',
'gas_unique_id': '**REDACTED**',
'long_power_fail_count': 5,
'meter_model': 'ISKRA 2M550T-101',
'monthly_power_peak_timestamp': '2023-01-01T08:00:10',
'monthly_power_peak_w': 1111.0,
'smr_version': 50,
'total_energy_export_kwh': 13086.777,
'total_energy_export_t1_kwh': 4321.333,
'total_energy_export_t2_kwh': 8765.444,
'total_energy_export_t3_kwh': 8765.444,
'total_energy_export_t4_kwh': 8765.444,
'total_energy_import_kwh': 13779.338,
'total_energy_import_t1_kwh': 10830.511,
'total_energy_import_t2_kwh': 2948.827,
'total_energy_import_t3_kwh': 2948.827,
'total_energy_import_t4_kwh': 2948.827,
'total_gas_m3': 1122.333,
'total_liter_m3': 1234.567,
'unique_meter_id': '**REDACTED**',
'voltage_sag_l1_count': 1,
'voltage_sag_l2_count': 2,
'voltage_sag_l3_count': 3,
'voltage_swell_l1_count': 4,
'voltage_swell_l2_count': 5,
'voltage_swell_l3_count': 6,
'gas_timestamp': None,
'gas_unique_id': None,
'long_power_fail_count': None,
'meter_model': None,
'monthly_power_peak_timestamp': None,
'monthly_power_peak_w': None,
'smr_version': None,
'total_energy_export_kwh': None,
'total_energy_export_t1_kwh': 0,
'total_energy_export_t2_kwh': None,
'total_energy_export_t3_kwh': None,
'total_energy_export_t4_kwh': None,
'total_energy_import_kwh': None,
'total_energy_import_t1_kwh': 63.651,
'total_energy_import_t2_kwh': None,
'total_energy_import_t3_kwh': None,
'total_energy_import_t4_kwh': None,
'total_gas_m3': None,
'total_liter_m3': None,
'unique_meter_id': None,
'voltage_sag_l1_count': None,
'voltage_sag_l2_count': None,
'voltage_sag_l3_count': None,
'voltage_swell_l1_count': None,
'voltage_swell_l2_count': None,
'voltage_swell_l3_count': None,
'wifi_ssid': '**REDACTED**',
'wifi_strength': 100,
'wifi_strength': 94,
}),
'device': dict({
'api_version': 'v1',
@ -211,3 +141,72 @@
}),
})
# ---
# name: test_diagnostics[SDM230]
dict({
'data': dict({
'data': dict({
'active_current_l1_a': None,
'active_current_l2_a': None,
'active_current_l3_a': None,
'active_frequency_hz': None,
'active_liter_lpm': None,
'active_power_average_w': None,
'active_power_l1_w': -1058.296,
'active_power_l2_w': None,
'active_power_l3_w': None,
'active_power_w': -1058.296,
'active_tariff': None,
'active_voltage_l1_v': None,
'active_voltage_l2_v': None,
'active_voltage_l3_v': None,
'any_power_fail_count': None,
'external_devices': None,
'gas_timestamp': None,
'gas_unique_id': None,
'long_power_fail_count': None,
'meter_model': None,
'monthly_power_peak_timestamp': None,
'monthly_power_peak_w': None,
'smr_version': None,
'total_energy_export_kwh': 255.551,
'total_energy_export_t1_kwh': 255.551,
'total_energy_export_t2_kwh': None,
'total_energy_export_t3_kwh': None,
'total_energy_export_t4_kwh': None,
'total_energy_import_kwh': 2.705,
'total_energy_import_t1_kwh': 2.705,
'total_energy_import_t2_kwh': None,
'total_energy_import_t3_kwh': None,
'total_energy_import_t4_kwh': None,
'total_gas_m3': None,
'total_liter_m3': None,
'unique_meter_id': None,
'voltage_sag_l1_count': None,
'voltage_sag_l2_count': None,
'voltage_sag_l3_count': None,
'voltage_swell_l1_count': None,
'voltage_swell_l2_count': None,
'voltage_swell_l3_count': None,
'wifi_ssid': '**REDACTED**',
'wifi_strength': 92,
}),
'device': dict({
'api_version': 'v1',
'firmware_version': '3.06',
'product_name': 'kWh meter',
'product_type': 'SDM230-WIFI',
'serial': '**REDACTED**',
}),
'state': None,
'system': dict({
'cloud_enabled': True,
}),
}),
'entry': dict({
'ip_address': '**REDACTED**',
'product_name': 'Product name',
'product_type': 'product_type',
'serial': '**REDACTED**',
}),
})
# ---

View file

@ -1,5 +1,5 @@
# serializer version: 1
# name: test_number_entities[device-HWE-SKT.json]
# name: test_number_entities[HWE-SKT]
StateSnapshot({
'attributes': ReadOnlyDict({
'friendly_name': 'Device Status light brightness',
@ -17,7 +17,7 @@
'state': '100',
})
# ---
# name: test_number_entities[device-HWE-SKT.json].1
# name: test_number_entities[HWE-SKT].1
EntityRegistryEntrySnapshot({
'aliases': set({
}),
@ -53,7 +53,7 @@
'unit_of_measurement': '%',
})
# ---
# name: test_number_entities[device-HWE-SKT.json].2
# name: test_number_entities[HWE-SKT].2
DeviceRegistryEntrySnapshot({
'area_id': None,
'config_entries': <ANY>,

File diff suppressed because it is too large Load diff

View file

@ -1,5 +1,5 @@
# serializer version: 1
# name: test_switch_entities[switch.device-state_set-power_on-device-HWE-SKT.json]
# name: test_switch_entities[switch.device-state_set-power_on-HWE-SKT]
StateSnapshot({
'attributes': ReadOnlyDict({
'device_class': 'outlet',
@ -12,7 +12,7 @@
'state': 'on',
})
# ---
# name: test_switch_entities[switch.device-state_set-power_on-device-HWE-SKT.json].1
# name: test_switch_entities[switch.device-state_set-power_on-HWE-SKT].1
EntityRegistryEntrySnapshot({
'aliases': set({
}),
@ -43,7 +43,7 @@
'unit_of_measurement': None,
})
# ---
# name: test_switch_entities[switch.device-state_set-power_on-device-HWE-SKT.json].2
# name: test_switch_entities[switch.device-state_set-power_on-HWE-SKT].2
DeviceRegistryEntrySnapshot({
'area_id': None,
'config_entries': <ANY>,
@ -75,7 +75,7 @@
'via_device_id': None,
})
# ---
# name: test_switch_entities[switch.device_cloud_connection-system_set-cloud_enabled-device-HWE-SKT.json]
# name: test_switch_entities[switch.device_cloud_connection-system_set-cloud_enabled-HWE-SKT]
StateSnapshot({
'attributes': ReadOnlyDict({
'friendly_name': 'Device Cloud connection',
@ -88,7 +88,7 @@
'state': 'on',
})
# ---
# name: test_switch_entities[switch.device_cloud_connection-system_set-cloud_enabled-device-HWE-SKT.json].1
# name: test_switch_entities[switch.device_cloud_connection-system_set-cloud_enabled-HWE-SKT].1
EntityRegistryEntrySnapshot({
'aliases': set({
}),
@ -119,7 +119,7 @@
'unit_of_measurement': None,
})
# ---
# name: test_switch_entities[switch.device_cloud_connection-system_set-cloud_enabled-device-HWE-SKT.json].2
# name: test_switch_entities[switch.device_cloud_connection-system_set-cloud_enabled-HWE-SKT].2
DeviceRegistryEntrySnapshot({
'area_id': None,
'config_entries': <ANY>,
@ -151,7 +151,7 @@
'via_device_id': None,
})
# ---
# name: test_switch_entities[switch.device_switch_lock-state_set-switch_lock-device-HWE-SKT.json]
# name: test_switch_entities[switch.device_switch_lock-state_set-switch_lock-HWE-SKT]
StateSnapshot({
'attributes': ReadOnlyDict({
'friendly_name': 'Device Switch lock',
@ -164,7 +164,7 @@
'state': 'off',
})
# ---
# name: test_switch_entities[switch.device_switch_lock-state_set-switch_lock-device-HWE-SKT.json].1
# name: test_switch_entities[switch.device_switch_lock-state_set-switch_lock-HWE-SKT].1
EntityRegistryEntrySnapshot({
'aliases': set({
}),
@ -195,7 +195,7 @@
'unit_of_measurement': None,
})
# ---
# name: test_switch_entities[switch.device_switch_lock-state_set-switch_lock-device-HWE-SKT.json].2
# name: test_switch_entities[switch.device_switch_lock-state_set-switch_lock-HWE-SKT].2
DeviceRegistryEntrySnapshot({
'area_id': None,
'config_entries': <ANY>,

View file

@ -17,7 +17,7 @@ pytestmark = [
]
@pytest.mark.parametrize("device_fixture", ["device-sdm230.json"])
@pytest.mark.parametrize("device_fixture", ["SDM230"])
async def test_identify_button_entity_not_loaded_when_not_available(
hass: HomeAssistant,
) -> None:

View file

@ -10,9 +10,7 @@ from tests.components.diagnostics import get_diagnostics_for_config_entry
from tests.typing import ClientSessionGenerator
@pytest.mark.parametrize(
"device_fixture", ["device-HWE-P1.json", "device-HWE-SKT.json"]
)
@pytest.mark.parametrize("device_fixture", ["HWE-P1", "HWE-SKT", "SDM230"])
async def test_diagnostics(
hass: HomeAssistant,
hass_client: ClientSessionGenerator,

View file

@ -18,7 +18,7 @@ from tests.common import async_fire_time_changed
@pytest.mark.usefixtures("init_integration")
@pytest.mark.parametrize("device_fixture", ["device-HWE-SKT.json"])
@pytest.mark.parametrize("device_fixture", ["HWE-SKT"])
async def test_number_entities(
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,

View file

@ -21,11 +21,10 @@ pytestmark = [
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
@pytest.mark.parametrize(
("device_fixture", "data_fixture", "entity_ids"),
("device_fixture", "entity_ids"),
[
(
"device-HWE-P1.json",
"data-HWE-P1.json",
"HWE-P1",
[
"sensor.device_dsmr_version",
"sensor.device_smart_meter_model",
@ -116,7 +115,7 @@ async def test_disabled_by_default_sensors(
assert entry.disabled_by is er.RegistryEntryDisabler.INTEGRATION
@pytest.mark.parametrize("data_fixture", ["data-HWE-P1-unused-exports.json"])
@pytest.mark.parametrize("device_fixture", ["HWE-P1-unused-exports"])
@pytest.mark.parametrize(
"entity_id",
[

View file

@ -26,7 +26,7 @@ pytestmark = [
]
@pytest.mark.parametrize("device_fixture", ["device-HWE-SKT.json"])
@pytest.mark.parametrize("device_fixture", ["HWE-SKT"])
@pytest.mark.parametrize(
("entity_id", "method", "parameter"),
[
@ -119,7 +119,7 @@ async def test_switch_entities(
)
@pytest.mark.parametrize("device_fixture", ["device-HWE-SKT.json"])
@pytest.mark.parametrize("device_fixture", ["HWE-SKT"])
@pytest.mark.parametrize("exception", [RequestError, DisabledError, UnsupportedError])
@pytest.mark.parametrize(
("entity_id", "method"),