Skip to content

Commit 1b11ac9

Browse files
authored
Add Homee general tests (home-assistant#137128)
1 parent 8d7e387 commit 1b11ac9

File tree

7 files changed

+427
-1
lines changed

7 files changed

+427
-1
lines changed

tests/components/homee/fixtures/cover_with_position_slats.json

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,55 @@
9696
"options": {
9797
"automations": ["step"]
9898
}
99+
},
100+
{
101+
"id": 4,
102+
"node_id": 3,
103+
"instance": 0,
104+
"minimum": -50,
105+
"maximum": 125,
106+
"current_value": 20.3,
107+
"target_value": 20.3,
108+
"last_value": 20.3,
109+
"unit": "°C",
110+
"step_value": 1.0,
111+
"editable": 0,
112+
"type": 5,
113+
"state": 1,
114+
"last_changed": 1709982925,
115+
"changed_by": 1,
116+
"changed_by_id": 0,
117+
"based_on": 1,
118+
"data": "",
119+
"name": "",
120+
"options": {
121+
"history": {
122+
"day": 1,
123+
"week": 26,
124+
"month": 6
125+
}
126+
}
127+
},
128+
{
129+
"id": 5,
130+
"node_id": 3,
131+
"instance": 0,
132+
"minimum": 0,
133+
"maximum": 0,
134+
"current_value": 0.0,
135+
"target_value": 0.0,
136+
"last_value": 0.0,
137+
"unit": "text",
138+
"step_value": 1.0,
139+
"editable": 0,
140+
"type": 44,
141+
"state": 1,
142+
"last_changed": 0,
143+
"changed_by": 1,
144+
"changed_by_id": 0,
145+
"based_on": 1,
146+
"data": "4.54",
147+
"name": ""
99148
}
100149
]
101150
}

tests/components/homee/fixtures/cover_without_position.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,27 @@
4343
"observes": [75],
4444
"automations": ["toggle"]
4545
}
46+
},
47+
{
48+
"id": 2,
49+
"node_id": 3,
50+
"instance": 0,
51+
"minimum": 0,
52+
"maximum": 0,
53+
"current_value": 0.0,
54+
"target_value": 0.0,
55+
"last_value": 0.0,
56+
"unit": "text",
57+
"step_value": 1.0,
58+
"editable": 0,
59+
"type": 45,
60+
"state": 1,
61+
"last_changed": 0,
62+
"changed_by": 1,
63+
"changed_by_id": 0,
64+
"based_on": 1,
65+
"data": "1.45",
66+
"name": ""
4667
}
4768
]
4869
}

tests/components/homee/snapshots/test_diagnostics.ambr

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,55 @@
689689
'type': 113,
690690
'unit': '°',
691691
}),
692+
dict({
693+
'based_on': 1,
694+
'changed_by': 1,
695+
'changed_by_id': 0,
696+
'current_value': 20.3,
697+
'data': '',
698+
'editable': 0,
699+
'id': 4,
700+
'instance': 0,
701+
'last_changed': 1709982925,
702+
'last_value': 20.3,
703+
'maximum': 125,
704+
'minimum': -50,
705+
'name': '',
706+
'node_id': 3,
707+
'options': dict({
708+
'history': dict({
709+
'day': 1,
710+
'month': 6,
711+
'week': 26,
712+
}),
713+
}),
714+
'state': 1,
715+
'step_value': 1.0,
716+
'target_value': 20.3,
717+
'type': 5,
718+
'unit': '°C',
719+
}),
720+
dict({
721+
'based_on': 1,
722+
'changed_by': 1,
723+
'changed_by_id': 0,
724+
'current_value': 0.0,
725+
'data': '4.54',
726+
'editable': 0,
727+
'id': 5,
728+
'instance': 0,
729+
'last_changed': 0,
730+
'last_value': 0.0,
731+
'maximum': 0,
732+
'minimum': 0,
733+
'name': '',
734+
'node_id': 3,
735+
'state': 1,
736+
'step_value': 1.0,
737+
'target_value': 0.0,
738+
'type': 44,
739+
'unit': 'text',
740+
}),
692741
]),
693742
'cube_type': 14,
694743
'favorite': 0,
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# serializer version: 1
2+
# name: test_general_data
3+
DeviceRegistryEntrySnapshot({
4+
'area_id': None,
5+
'config_entries': <ANY>,
6+
'config_entries_subentries': <ANY>,
7+
'configuration_url': None,
8+
'connections': set({
9+
tuple(
10+
'mac',
11+
'00:05:55:11:ee:cc',
12+
),
13+
}),
14+
'disabled_by': None,
15+
'entry_type': None,
16+
'hw_version': None,
17+
'id': <ANY>,
18+
'identifiers': set({
19+
tuple(
20+
'homee',
21+
'00055511EECC',
22+
),
23+
}),
24+
'is_new': False,
25+
'labels': set({
26+
}),
27+
'manufacturer': 'homee',
28+
'model': 'homee',
29+
'model_id': None,
30+
'name': 'TestHomee',
31+
'name_by_user': None,
32+
'primary_config_entry': <ANY>,
33+
'serial_number': None,
34+
'suggested_area': None,
35+
'sw_version': '1.2.3',
36+
'via_device_id': None,
37+
})
38+
# ---
39+
# name: test_general_data.1
40+
DeviceRegistryEntrySnapshot({
41+
'area_id': None,
42+
'config_entries': <ANY>,
43+
'config_entries_subentries': <ANY>,
44+
'configuration_url': None,
45+
'connections': set({
46+
}),
47+
'disabled_by': None,
48+
'entry_type': None,
49+
'hw_version': None,
50+
'id': <ANY>,
51+
'identifiers': set({
52+
tuple(
53+
'homee',
54+
'00055511EECC-3',
55+
),
56+
}),
57+
'is_new': False,
58+
'labels': set({
59+
}),
60+
'manufacturer': None,
61+
'model': 'shutter_position_switch',
62+
'model_id': None,
63+
'name': 'Test Cover',
64+
'name_by_user': None,
65+
'primary_config_entry': <ANY>,
66+
'serial_number': None,
67+
'suggested_area': None,
68+
'sw_version': '4.54',
69+
'via_device_id': <ANY>,
70+
})
71+
# ---

tests/components/homee/test_cover.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
CoverEntityFeature,
1414
CoverState,
1515
)
16+
from homeassistant.components.homeassistant import (
17+
DOMAIN as HA_DOMAIN,
18+
SERVICE_UPDATE_ENTITY,
19+
)
1620
from homeassistant.components.homee.const import DOMAIN
1721
from homeassistant.const import (
1822
ATTR_ENTITY_ID,
@@ -23,9 +27,11 @@
2327
SERVICE_SET_COVER_POSITION,
2428
SERVICE_SET_COVER_TILT_POSITION,
2529
SERVICE_STOP_COVER,
30+
STATE_UNAVAILABLE,
2631
)
2732
from homeassistant.core import HomeAssistant
2833
from homeassistant.exceptions import HomeAssistantError
34+
from homeassistant.setup import async_setup_component
2935

3036
from . import build_mock_node, setup_integration
3137

@@ -39,6 +45,7 @@ async def test_open_close_stop_cover(
3945
) -> None:
4046
"""Test opening the cover."""
4147
mock_homee.nodes = [build_mock_node("cover_with_position_slats.json")]
48+
mock_homee.get_node_by_id.return_value = mock_homee.nodes[0]
4249

4350
await setup_integration(hass, mock_config_entry)
4451

@@ -73,6 +80,7 @@ async def test_open_close_reverse_cover(
7380
) -> None:
7481
"""Test opening the cover."""
7582
mock_homee.nodes = [build_mock_node("cover_with_position_slats.json")]
83+
mock_homee.get_node_by_id.return_value = mock_homee.nodes[0]
7684
mock_homee.nodes[0].attributes[0].is_reversed = True
7785

7886
await setup_integration(hass, mock_config_entry)
@@ -102,6 +110,7 @@ async def test_set_cover_position(
102110
) -> None:
103111
"""Test setting the cover position."""
104112
mock_homee.nodes = [build_mock_node("cover_with_position_slats.json")]
113+
mock_homee.get_node_by_id.return_value = mock_homee.nodes[0]
105114

106115
await setup_integration(hass, mock_config_entry)
107116

@@ -246,6 +255,7 @@ async def test_cover_positions(
246255
# Cover open, tilt open.
247256
# mock_homee.nodes = [cover]
248257
mock_homee.nodes = [build_mock_node("cover_with_position_slats.json")]
258+
mock_homee.get_node_by_id.return_value = mock_homee.nodes[0]
249259
cover = mock_homee.nodes[0]
250260

251261
await setup_integration(hass, mock_config_entry)
@@ -348,3 +358,50 @@ async def test_send_error(
348358

349359
assert exc_info.value.translation_domain == DOMAIN
350360
assert exc_info.value.translation_key == "connection_closed"
361+
362+
363+
async def test_node_entity_connection_listener(
364+
hass: HomeAssistant,
365+
mock_homee: MagicMock,
366+
mock_config_entry: MockConfigEntry,
367+
) -> None:
368+
"""Test if loss of connection is sensed correctly."""
369+
mock_homee.nodes = [build_mock_node("cover_with_position_slats.json")]
370+
mock_homee.get_node_by_id.return_value = mock_homee.nodes[0]
371+
await setup_integration(hass, mock_config_entry)
372+
373+
states = hass.states.get("cover.test_cover")
374+
assert states.state != STATE_UNAVAILABLE
375+
376+
await mock_homee.add_connection_listener.call_args_list[1][0][0](False)
377+
await hass.async_block_till_done()
378+
379+
states = hass.states.get("cover.test_cover")
380+
assert states.state == STATE_UNAVAILABLE
381+
382+
await mock_homee.add_connection_listener.call_args_list[1][0][0](True)
383+
await hass.async_block_till_done()
384+
385+
states = hass.states.get("cover.test_cover")
386+
assert states.state != STATE_UNAVAILABLE
387+
388+
389+
async def test_node_entity_update_action(
390+
hass: HomeAssistant,
391+
mock_homee: MagicMock,
392+
mock_config_entry: MockConfigEntry,
393+
) -> None:
394+
"""Test the update_entity action for a HomeeEntity."""
395+
mock_homee.nodes = [build_mock_node("cover_with_position_slats.json")]
396+
mock_homee.get_node_by_id.return_value = mock_homee.nodes[0]
397+
await setup_integration(hass, mock_config_entry)
398+
await async_setup_component(hass, HA_DOMAIN, {})
399+
400+
await hass.services.async_call(
401+
HA_DOMAIN,
402+
SERVICE_UPDATE_ENTITY,
403+
{ATTR_ENTITY_ID: "cover.test_cover"},
404+
blocking=True,
405+
)
406+
407+
mock_homee.update_node.assert_called_once_with(3)

0 commit comments

Comments
 (0)