| 1 |
"""Test pydeCONZ switch.""" |
| 2 |
|
| 3 |
from pydeconz.models.sensor.switch import ( |
| 4 |
SwitchDeviceMode, |
| 5 |
SwitchMode, |
| 6 |
SwitchWindowCoveringType, |
| 7 |
) |
| 8 |
|
| 9 |
DATA = { |
| 10 |
"config": { |
| 11 |
"battery": 90, |
| 12 |
"group": "201", |
| 13 |
"on": True, |
| 14 |
"reachable": True, |
| 15 |
}, |
| 16 |
"ep": 2, |
| 17 |
"etag": "233ae541bbb7ac98c42977753884b8d2", |
| 18 |
"manufacturername": "Philips", |
| 19 |
"mode": 1, |
| 20 |
"modelid": "RWL021", |
| 21 |
"name": "Dimmer switch 3", |
| 22 |
"state": { |
| 23 |
"buttonevent": 1002, |
| 24 |
"lastupdated": "2019-04-28T20:29:13", |
| 25 |
}, |
| 26 |
"swversion": "5.45.1.17846", |
| 27 |
"type": "ZHASwitch", |
| 28 |
"uniqueid": "00:17:88:01:02:0e:32:a3-02-fc00", |
| 29 |
} |
| 30 |
|
| 31 |
DATA_CUBE = { |
| 32 |
"config": { |
| 33 |
"battery": 90, |
| 34 |
"on": True, |
| 35 |
"reachable": True, |
| 36 |
"temperature": 1100, |
| 37 |
}, |
| 38 |
"ep": 3, |
| 39 |
"etag": "e34fa1c7a19d960e35a1f4d56ac475af", |
| 40 |
"manufacturername": "LUMI", |
| 41 |
"mode": 1, |
| 42 |
"modelid": "lumi.sensor_cube.aqgl01", |
| 43 |
"name": "Mi Magic Cube", |
| 44 |
"state": { |
| 45 |
"buttonevent": 747, |
| 46 |
"gesture": 7, |
| 47 |
"lastupdated": "2019-12-12T18:50:40", |
| 48 |
}, |
| 49 |
"swversion": "20160704", |
| 50 |
"type": "ZHASwitch", |
| 51 |
"uniqueid": "00:15:8d:00:02:8b:3b:24-03-000c", |
| 52 |
} |
| 53 |
DATA_HUE_WALL_SWITCH = { |
| 54 |
"config": { |
| 55 |
"battery": 100, |
| 56 |
"devicemode": "dualrocker", |
| 57 |
"on": True, |
| 58 |
"pending": [], |
| 59 |
"reachable": True, |
| 60 |
}, |
| 61 |
"ep": 1, |
| 62 |
"etag": "01173dc5b19bb0a976006eee8d0d3718", |
| 63 |
"lastseen": "2021-03-12T22:55Z", |
| 64 |
"manufacturername": "Signify Netherlands B.V.", |
| 65 |
"mode": 1, |
| 66 |
"modelid": "RDM001", |
| 67 |
"name": "RDM001 15", |
| 68 |
"state": { |
| 69 |
"buttonevent": 1002, |
| 70 |
"eventduration": 1, |
| 71 |
"lastupdated": "2021-03-12T22:21:20.017", |
| 72 |
}, |
| 73 |
"swversion": "20210115", |
| 74 |
"type": "ZHASwitch", |
| 75 |
"uniqueid": "00:17:88:01:0b:00:05:5d-01-fc00", |
| 76 |
} |
| 77 |
|
| 78 |
DATA_TINT_REMOTE = { |
| 79 |
"config": { |
| 80 |
"group": "16388,16389,16390", |
| 81 |
"on": True, |
| 82 |
"reachable": True, |
| 83 |
}, |
| 84 |
"ep": 1, |
| 85 |
"etag": "b1336f750d31300afa441a04f2c69b68", |
| 86 |
"manufacturername": "MLI", |
| 87 |
"mode": 1, |
| 88 |
"modelid": "ZBT-Remote-ALL-RGBW", |
| 89 |
"name": "ZHA Remote 1", |
| 90 |
"state": { |
| 91 |
"angle": 10, |
| 92 |
"buttonevent": 6002, |
| 93 |
"lastupdated": "2020-09-08T18:58:24.193", |
| 94 |
"xy": [0.3381, 0.1627], |
| 95 |
}, |
| 96 |
"swversion": "2.0", |
| 97 |
"type": "ZHASwitch", |
| 98 |
"uniqueid": "00:11:22:33:44:55:66:77-01-1000", |
| 99 |
} |
| 100 |
|
| 101 |
DATA_UBISYS_J1 = { |
| 102 |
"config": { |
| 103 |
"mode": "momentary", |
| 104 |
"on": True, |
| 105 |
"reachable": False, |
| 106 |
"windowcoveringtype": 0, |
| 107 |
}, |
| 108 |
"ep": 2, |
| 109 |
"etag": "da5fbb89eca4133b6949537e73b31f77", |
| 110 |
"lastseen": "2020-11-21T15:47Z", |
| 111 |
"manufacturername": "ubisys", |
| 112 |
"mode": 1, |
| 113 |
"modelid": "J1 (5502)", |
| 114 |
"name": "J1", |
| 115 |
"state": { |
| 116 |
"buttonevent": None, |
| 117 |
"lastupdated": "none", |
| 118 |
}, |
| 119 |
"swversion": "20190129-DE-FB0", |
| 120 |
"type": "ZHASwitch", |
| 121 |
"uniqueid": "00:1f:ee:00:00:00:00:09-02-0102", |
| 122 |
} |
| 123 |
|
| 124 |
|
| 125 |
async def test_handler_switch(mock_aioresponse, deconz_session, deconz_called_with): |
| 126 |
"""Verify that configuring presence sensor works.""" |
| 127 |
switch = deconz_session.sensors.switch |
| 128 |
|
| 129 |
mock_aioresponse.put("http://host:80/api/apikey/sensors/0/config") |
| 130 |
await switch.set_config("0", device_mode=SwitchDeviceMode.DUAL_ROCKER) |
| 131 |
assert deconz_called_with( |
| 132 |
"put", |
| 133 |
path="/sensors/0/config", |
| 134 |
json={"devicemode": "dualrocker"}, |
| 135 |
) |
| 136 |
|
| 137 |
mock_aioresponse.put("http://host:80/api/apikey/sensors/0/config") |
| 138 |
await switch.set_config("0", mode=SwitchMode.ROCKER) |
| 139 |
assert deconz_called_with( |
| 140 |
"put", |
| 141 |
path="/sensors/0/config", |
| 142 |
json={"mode": "rocker"}, |
| 143 |
) |
| 144 |
|
| 145 |
mock_aioresponse.put("http://host:80/api/apikey/sensors/0/config") |
| 146 |
await switch.set_config("0", window_covering_type=SwitchWindowCoveringType.DRAPERY) |
| 147 |
assert deconz_called_with( |
| 148 |
"put", |
| 149 |
path="/sensors/0/config", |
| 150 |
json={"windowcoveringtype": 4}, |
| 151 |
) |
| 152 |
|
| 153 |
|
| 154 |
async def test_sensor_switch(deconz_sensor): |
| 155 |
"""Verify that switch sensor works.""" |
| 156 |
sensor = await deconz_sensor(DATA) |
| 157 |
|
| 158 |
assert sensor.button_event == 1002 |
| 159 |
assert sensor.gesture is None |
| 160 |
assert sensor.angle is None |
| 161 |
assert sensor.xy is None |
| 162 |
assert sensor.device_mode is None |
| 163 |
|
| 164 |
|
| 165 |
assert sensor.battery == 90 |
| 166 |
assert sensor.ep == 2 |
| 167 |
assert sensor.low_battery is None |
| 168 |
assert sensor.on is True |
| 169 |
assert sensor.reachable is True |
| 170 |
assert sensor.tampered is None |
| 171 |
assert sensor.internal_temperature is None |
| 172 |
|
| 173 |
|
| 174 |
assert sensor.deconz_id == "/sensors/0" |
| 175 |
assert sensor.etag == "233ae541bbb7ac98c42977753884b8d2" |
| 176 |
assert sensor.manufacturer == "Philips" |
| 177 |
assert sensor.model_id == "RWL021" |
| 178 |
assert sensor.name == "Dimmer switch 3" |
| 179 |
assert sensor.software_version == "5.45.1.17846" |
| 180 |
assert sensor.type == "ZHASwitch" |
| 181 |
assert sensor.unique_id == "00:17:88:01:02:0e:32:a3-02-fc00" |
| 182 |
|
| 183 |
|
| 184 |
async def test_sensor_switch_sensor_cube(deconz_sensor): |
| 185 |
"""Verify that cube switch sensor works.""" |
| 186 |
sensor = await deconz_sensor(DATA_CUBE) |
| 187 |
|
| 188 |
assert sensor.button_event == 747 |
| 189 |
assert sensor.gesture == 7 |
| 190 |
|
| 191 |
|
| 192 |
assert sensor.battery == 90 |
| 193 |
assert sensor.ep == 3 |
| 194 |
assert sensor.low_battery is None |
| 195 |
assert sensor.on is True |
| 196 |
assert sensor.reachable is True |
| 197 |
assert sensor.tampered is None |
| 198 |
assert sensor.internal_temperature == 11.0 |
| 199 |
|
| 200 |
|
| 201 |
assert sensor.deconz_id == "/sensors/0" |
| 202 |
assert sensor.etag == "e34fa1c7a19d960e35a1f4d56ac475af" |
| 203 |
assert sensor.manufacturer == "LUMI" |
| 204 |
assert sensor.model_id == "lumi.sensor_cube.aqgl01" |
| 205 |
assert sensor.name == "Mi Magic Cube" |
| 206 |
assert sensor.software_version == "20160704" |
| 207 |
assert sensor.type == "ZHASwitch" |
| 208 |
assert sensor.unique_id == "00:15:8d:00:02:8b:3b:24-03-000c" |
| 209 |
|
| 210 |
|
| 211 |
async def test_sensor_switch_hue_wall_switch_module(deconz_sensor): |
| 212 |
"""Verify that cube switch sensor works.""" |
| 213 |
sensor = await deconz_sensor(DATA_HUE_WALL_SWITCH) |
| 214 |
|
| 215 |
assert sensor.button_event == 1002 |
| 216 |
assert sensor.event_duration == 1 |
| 217 |
assert sensor.device_mode == SwitchDeviceMode.DUAL_ROCKER |
| 218 |
assert not sensor.angle |
| 219 |
assert not sensor.gesture |
| 220 |
assert not sensor.mode |
| 221 |
assert not sensor.window_covering_type |
| 222 |
assert not sensor.xy |
| 223 |
|
| 224 |
|
| 225 |
assert sensor.battery == 100 |
| 226 |
assert sensor.ep == 1 |
| 227 |
assert not sensor.low_battery |
| 228 |
assert sensor.on |
| 229 |
assert sensor.reachable |
| 230 |
assert not sensor.tampered |
| 231 |
assert not sensor.internal_temperature |
| 232 |
|
| 233 |
|
| 234 |
assert sensor.deconz_id == "/sensors/0" |
| 235 |
assert sensor.etag == "01173dc5b19bb0a976006eee8d0d3718" |
| 236 |
assert sensor.manufacturer == "Signify Netherlands B.V." |
| 237 |
assert sensor.model_id == "RDM001" |
| 238 |
assert sensor.name == "RDM001 15" |
| 239 |
assert sensor.software_version == "20210115" |
| 240 |
assert sensor.type == "ZHASwitch" |
| 241 |
assert sensor.unique_id == "00:17:88:01:0b:00:05:5d-01-fc00" |
| 242 |
|
| 243 |
|
| 244 |
async def test_sensor_switch_tint_remote(deconz_sensor): |
| 245 |
"""Verify that tint remote sensor works.""" |
| 246 |
sensor = await deconz_sensor(DATA_TINT_REMOTE) |
| 247 |
|
| 248 |
assert sensor.button_event == 6002 |
| 249 |
assert sensor.angle == 10 |
| 250 |
assert sensor.xy == [0.3381, 0.1627] |
| 251 |
|
| 252 |
|
| 253 |
assert sensor.ep == 1 |
| 254 |
assert sensor.low_battery is None |
| 255 |
assert sensor.on is True |
| 256 |
assert sensor.reachable is True |
| 257 |
assert sensor.tampered is None |
| 258 |
|
| 259 |
|
| 260 |
assert sensor.deconz_id == "/sensors/0" |
| 261 |
assert sensor.etag == "b1336f750d31300afa441a04f2c69b68" |
| 262 |
assert sensor.manufacturer == "MLI" |
| 263 |
assert sensor.model_id == "ZBT-Remote-ALL-RGBW" |
| 264 |
assert sensor.name == "ZHA Remote 1" |
| 265 |
assert sensor.software_version == "2.0" |
| 266 |
assert sensor.type == "ZHASwitch" |
| 267 |
assert sensor.unique_id == "00:11:22:33:44:55:66:77-01-1000" |
| 268 |
|
| 269 |
|
| 270 |
async def test_sensor_switch_ubisys_j1(deconz_sensor): |
| 271 |
"""Verify that tint remote sensor works.""" |
| 272 |
sensor = await deconz_sensor(DATA_UBISYS_J1) |
| 273 |
|
| 274 |
assert sensor.button_event is None |
| 275 |
assert sensor.angle is None |
| 276 |
assert sensor.xy is None |
| 277 |
assert sensor.mode == SwitchMode.MOMENTARY |
| 278 |
assert sensor.window_covering_type == SwitchWindowCoveringType.ROLLER_SHADE |
| 279 |
|
| 280 |
|
| 281 |
assert sensor.ep == 2 |
| 282 |
assert sensor.low_battery is None |
| 283 |
assert sensor.on is True |
| 284 |
assert sensor.reachable is False |
| 285 |
assert sensor.tampered is None |
| 286 |
|
| 287 |
|
| 288 |
assert sensor.deconz_id == "/sensors/0" |
| 289 |
assert sensor.etag == "da5fbb89eca4133b6949537e73b31f77" |
| 290 |
assert sensor.manufacturer == "ubisys" |
| 291 |
assert sensor.model_id == "J1 (5502)" |
| 292 |
assert sensor.name == "J1" |
| 293 |
assert sensor.software_version == "20190129-DE-FB0" |
| 294 |
assert sensor.type == "ZHASwitch" |
| 295 |
assert sensor.unique_id == "00:1f:ee:00:00:00:00:09-02-0102" |