|
1 | 1 | """Tests for Schneider Electric devices.""" |
2 | 2 |
|
3 | | -from unittest import mock |
4 | | - |
5 | 3 | import pytest |
6 | | -from zigpy.zcl import foundation |
7 | | -from zigpy.zcl.clusters.closures import WindowCovering |
8 | 4 | from zigpy.zcl.clusters.smartenergy import Metering |
9 | 5 |
|
10 | 6 | from tests.common import ClusterListener |
11 | 7 | import zhaquirks.schneiderelectric.outlet |
12 | | -import zhaquirks.schneiderelectric.shutters |
13 | 8 |
|
14 | 9 | zhaquirks.setup() |
15 | 10 |
|
16 | 11 |
|
17 | | -def test_1gang_shutter_1_signature(assert_signature_matches_quirk): |
18 | | - """Test signature.""" |
19 | | - signature = { |
20 | | - "node_descriptor": ( |
21 | | - "NodeDescriptor(logical_type=<LogicalType.Router: 1>, " |
22 | | - "complex_descriptor_available=0, user_descriptor_available=0, reserved=0, " |
23 | | - "aps_flags=0, frequency_band=<FrequencyBand.Freq2400MHz: 8>, " |
24 | | - "mac_capability_flags=<MACCapabilityFlags.FullFunctionDevice|MainsPowered" |
25 | | - "|RxOnWhenIdle|AllocateAddress: 142>, manufacturer_code=4190, " |
26 | | - "maximum_buffer_size=82, maximum_incoming_transfer_size=82, " |
27 | | - "server_mask=10752, maximum_outgoing_transfer_size=82, " |
28 | | - "descriptor_capability_field=<DescriptorCapability.NONE: 0>, " |
29 | | - "*allocate_address=True, *is_alternate_pan_coordinator=False, " |
30 | | - "*is_coordinator=False, *is_end_device=False, " |
31 | | - "*is_full_function_device=True, *is_mains_powered=True, " |
32 | | - "*is_receiver_on_when_idle=True, *is_router=True, " |
33 | | - "*is_security_capable=False)" |
34 | | - ), |
35 | | - "endpoints": { |
36 | | - "5": { |
37 | | - "profile_id": 0x0104, |
38 | | - "device_type": "0x0202", |
39 | | - "in_clusters": [ |
40 | | - "0x0000", |
41 | | - "0x0003", |
42 | | - "0x0004", |
43 | | - "0x0005", |
44 | | - "0x0102", |
45 | | - "0x0b05", |
46 | | - ], |
47 | | - "out_clusters": ["0x0019"], |
48 | | - }, |
49 | | - "21": { |
50 | | - "profile_id": 0x0104, |
51 | | - "device_type": "0x0104", |
52 | | - "in_clusters": [ |
53 | | - "0x0000", |
54 | | - "0x0003", |
55 | | - "0x0b05", |
56 | | - "0xff17", |
57 | | - ], |
58 | | - "out_clusters": [ |
59 | | - "0x0003", |
60 | | - "0x0005", |
61 | | - "0x0006", |
62 | | - "0x0008", |
63 | | - "0x0019", |
64 | | - "0x0102", |
65 | | - ], |
66 | | - }, |
67 | | - }, |
68 | | - "manufacturer": "Schneider Electric", |
69 | | - "model": "1GANG/SHUTTER/1", |
70 | | - "class": "zigpy.device.Device", |
71 | | - } |
72 | | - assert_signature_matches_quirk( |
73 | | - zhaquirks.schneiderelectric.shutters.OneGangShutter1, signature |
74 | | - ) |
75 | | - |
76 | | - |
77 | | -async def test_1gang_shutter_1_go_to_lift_percentage_cmd(zigpy_device_from_quirk): |
78 | | - """Asserts that the go_to_lift_percentage command inverts the percentage value.""" |
79 | | - |
80 | | - device = zigpy_device_from_quirk( |
81 | | - zhaquirks.schneiderelectric.shutters.OneGangShutter1 |
82 | | - ) |
83 | | - window_covering_cluster = device.endpoints[5].window_covering |
84 | | - |
85 | | - p = mock.patch.object(window_covering_cluster, "request", mock.AsyncMock()) |
86 | | - with p as request_mock: |
87 | | - request_mock.return_value = (foundation.Status.SUCCESS, "done") |
88 | | - |
89 | | - await window_covering_cluster.go_to_lift_percentage(58) |
90 | | - |
91 | | - assert request_mock.call_count == 1 |
92 | | - assert request_mock.call_args[0][1] == ( |
93 | | - WindowCovering.ServerCommandDefs.go_to_lift_percentage.id |
94 | | - ) |
95 | | - assert request_mock.call_args[0][3] == 42 # 100 - 58 |
96 | | - |
97 | | - |
98 | | -async def test_1gang_shutter_1_unpatched_cmd(zigpy_device_from_quirk): |
99 | | - """Asserts that unpatched ZCL commands keep working.""" |
100 | | - |
101 | | - device = zigpy_device_from_quirk( |
102 | | - zhaquirks.schneiderelectric.shutters.OneGangShutter1 |
103 | | - ) |
104 | | - window_covering_cluster = device.endpoints[5].window_covering |
105 | | - |
106 | | - p = mock.patch.object(window_covering_cluster, "request", mock.AsyncMock()) |
107 | | - with p as request_mock: |
108 | | - request_mock.return_value = (foundation.Status.SUCCESS, "done") |
109 | | - |
110 | | - await window_covering_cluster.up_open() |
111 | | - |
112 | | - assert request_mock.call_count == 1 |
113 | | - assert request_mock.call_args[0][1] == ( |
114 | | - WindowCovering.ServerCommandDefs.up_open.id |
115 | | - ) |
116 | | - |
117 | | - |
118 | | -async def test_1gang_shutter_1_lift_percentage_updates(zigpy_device_from_quirk): |
119 | | - """Asserts that updates to the ``current_position_lift_percentage`` attribute. |
120 | | -
|
121 | | - (e.g., by the device) invert the reported percentage value. |
122 | | - """ |
123 | | - |
124 | | - device = zigpy_device_from_quirk( |
125 | | - zhaquirks.schneiderelectric.shutters.OneGangShutter1 |
126 | | - ) |
127 | | - window_covering_cluster = device.endpoints[5].window_covering |
128 | | - cluster_listener = ClusterListener(window_covering_cluster) |
129 | | - |
130 | | - window_covering_cluster.update_attribute( |
131 | | - WindowCovering.AttributeDefs.current_position_lift_percentage.id, |
132 | | - 77, |
133 | | - ) |
134 | | - |
135 | | - assert len(cluster_listener.attribute_updates) == 1 |
136 | | - assert cluster_listener.attribute_updates[0] == ( |
137 | | - WindowCovering.AttributeDefs.current_position_lift_percentage.id, |
138 | | - 23, # 100 - 77 |
139 | | - ) |
140 | | - assert len(cluster_listener.cluster_commands) == 0 |
141 | | - |
142 | | - |
143 | 12 | @pytest.mark.parametrize("quirk", (zhaquirks.schneiderelectric.outlet.SocketOutlet,)) |
144 | 13 | async def test_schneider_device_temp(zigpy_device_from_quirk, quirk): |
145 | 14 | """Test that instant demand is divided by 1000.""" |
|
0 commit comments