Skip to content

Commit a7a673d

Browse files
authored
Use snapshot assertion in switcher_kis diagnostics test (home-assistant#155273)
1 parent 196d7bb commit a7a673d

File tree

3 files changed

+60
-49
lines changed

3 files changed

+60
-49
lines changed

tests/components/switcher_kis/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@ async def init_integration(
1717
if token is not None:
1818
data[CONF_TOKEN] = token
1919

20-
entry = MockConfigEntry(domain=DOMAIN, data=data, unique_id=DOMAIN)
20+
entry = MockConfigEntry(
21+
domain=DOMAIN,
22+
data=data,
23+
entry_id="01K8K1GVZQW5RF1SMCEF1D55NE",
24+
unique_id=DOMAIN,
25+
)
2126
entry.add_to_hass(hass)
2227

2328
await hass.config_entries.async_setup(entry.entry_id)
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# serializer version: 1
2+
# name: test_diagnostics
3+
dict({
4+
'devices': list([
5+
dict({
6+
'auto_shutdown': '02:00:00',
7+
'device_id': '**REDACTED**',
8+
'device_key': '**REDACTED**',
9+
'device_state': dict({
10+
'__type': "<enum 'DeviceState'>",
11+
'repr': "<DeviceState.ON: ('01', 'on')>",
12+
}),
13+
'device_type': dict({
14+
'__type': "<enum 'DeviceType'>",
15+
'repr': "<DeviceType.V4: ('Switcher V4', '0317', 1, <DeviceCategory.WATER_HEATER: 1>, False)>",
16+
}),
17+
'electric_current': 12.8,
18+
'ip_address': '**REDACTED**',
19+
'last_data_update': '2022-09-28T16:42:12.706017',
20+
'mac_address': '**REDACTED**',
21+
'name': 'Heater FE12',
22+
'power_consumption': 2780,
23+
'remaining_time': '01:29:32',
24+
'token_needed': False,
25+
}),
26+
]),
27+
'entry': dict({
28+
'data': dict({
29+
}),
30+
'disabled_by': None,
31+
'discovery_keys': dict({
32+
}),
33+
'domain': 'switcher_kis',
34+
'entry_id': '01K8K1GVZQW5RF1SMCEF1D55NE',
35+
'minor_version': 1,
36+
'options': dict({
37+
}),
38+
'pref_disable_new_entities': False,
39+
'pref_disable_polling': False,
40+
'source': 'user',
41+
'subentries': list([
42+
]),
43+
'title': 'Mock Title',
44+
'unique_id': 'switcher_kis',
45+
'version': 1,
46+
}),
47+
})
48+
# ---
Lines changed: 6 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
"""Tests for the diagnostics data provided by Switcher."""
22

33
import pytest
4+
from syrupy.assertion import SnapshotAssertion
5+
from syrupy.filters import props
46

5-
from homeassistant.components.diagnostics import REDACTED
67
from homeassistant.core import HomeAssistant
78

89
from . import init_integration
910
from .consts import DUMMY_WATER_HEATER_DEVICE
1011

11-
from tests.common import ANY
1212
from tests.components.diagnostics import get_diagnostics_for_config_entry
1313
from tests.typing import ClientSessionGenerator
1414

@@ -18,6 +18,7 @@ async def test_diagnostics(
1818
hass_client: ClientSessionGenerator,
1919
mock_bridge,
2020
monkeypatch: pytest.MonkeyPatch,
21+
snapshot: SnapshotAssertion,
2122
) -> None:
2223
"""Test diagnostics."""
2324
entry = await init_integration(hass)
@@ -26,49 +27,6 @@ async def test_diagnostics(
2627
mock_bridge.mock_callbacks([device])
2728
await hass.async_block_till_done()
2829

29-
assert await get_diagnostics_for_config_entry(hass, hass_client, entry) == {
30-
"devices": [
31-
{
32-
"auto_shutdown": "02:00:00",
33-
"device_id": REDACTED,
34-
"device_key": REDACTED,
35-
"device_state": {
36-
"__type": "<enum 'DeviceState'>",
37-
"repr": "<DeviceState.ON: ('01', 'on')>",
38-
},
39-
"device_type": {
40-
"__type": "<enum 'DeviceType'>",
41-
"repr": (
42-
"<DeviceType.V4: ('Switcher V4', '0317', "
43-
"1, <DeviceCategory.WATER_HEATER: 1>, False)>"
44-
),
45-
},
46-
"electric_current": 12.8,
47-
"ip_address": REDACTED,
48-
"last_data_update": "2022-09-28T16:42:12.706017",
49-
"mac_address": REDACTED,
50-
"name": "Heater FE12",
51-
"power_consumption": 2780,
52-
"remaining_time": "01:29:32",
53-
"token_needed": False,
54-
}
55-
],
56-
"entry": {
57-
"entry_id": entry.entry_id,
58-
"version": 1,
59-
"minor_version": 1,
60-
"domain": "switcher_kis",
61-
"title": "Mock Title",
62-
"data": {},
63-
"options": {},
64-
"pref_disable_new_entities": False,
65-
"pref_disable_polling": False,
66-
"source": "user",
67-
"unique_id": "switcher_kis",
68-
"disabled_by": None,
69-
"created_at": ANY,
70-
"modified_at": ANY,
71-
"discovery_keys": {},
72-
"subentries": [],
73-
},
74-
}
30+
assert await get_diagnostics_for_config_entry(hass, hass_client, entry) == snapshot(
31+
exclude=props("created_at", "modified_at")
32+
)

0 commit comments

Comments
 (0)