| 1 |
"""Test pydeCONZ ancillary control.""" |
| 2 |
|
| 3 |
import pytest |
| 4 |
|
| 5 |
from pydeconz.models.sensor.ancillary_control import ( |
| 6 |
AncillaryControlAction, |
| 7 |
AncillaryControlPanel, |
| 8 |
) |
| 9 |
|
| 10 |
DATA = { |
| 11 |
"config": { |
| 12 |
"battery": 95, |
| 13 |
"enrolled": 1, |
| 14 |
"on": True, |
| 15 |
"pending": [], |
| 16 |
"reachable": True, |
| 17 |
}, |
| 18 |
"ep": 1, |
| 19 |
"etag": "5aaa1c6bae8501f59929539c6e8f44d6", |
| 20 |
"lastseen": "2021-07-25T18:07Z", |
| 21 |
"manufacturername": "lk", |
| 22 |
"modelid": "ZB-KeypadGeneric-D0002", |
| 23 |
"name": "Keypad", |
| 24 |
"state": { |
| 25 |
"action": "armed_stay", |
| 26 |
"lastupdated": "2021-07-25T18:02:51.172", |
| 27 |
"lowbattery": False, |
| 28 |
"panel": "exit_delay", |
| 29 |
"seconds_remaining": 55, |
| 30 |
"tampered": False, |
| 31 |
}, |
| 32 |
"swversion": "3.13", |
| 33 |
"type": "ZHAAncillaryControl", |
| 34 |
"uniqueid": "ec:1b:bd:ff:fe:6f:c3:4d-01-0501", |
| 35 |
} |
| 36 |
|
| 37 |
|
| 38 |
async def test_sensor_ancillary_control(deconz_sensor): |
| 39 |
"""Verify that ancillary control sensor works.""" |
| 40 |
sensor = await deconz_sensor(DATA) |
| 41 |
|
| 42 |
assert sensor.action == AncillaryControlAction.ARMED_STAY |
| 43 |
assert sensor.panel == AncillaryControlPanel.EXIT_DELAY |
| 44 |
assert sensor.seconds_remaining == 55 |
| 45 |
|
| 46 |
|
| 47 |
assert sensor.battery == 95 |
| 48 |
assert sensor.ep == 1 |
| 49 |
assert not sensor.low_battery |
| 50 |
assert sensor.on |
| 51 |
assert sensor.reachable |
| 52 |
assert not sensor.tampered |
| 53 |
assert not sensor.internal_temperature |
| 54 |
|
| 55 |
|
| 56 |
assert sensor.deconz_id == "/sensors/0" |
| 57 |
assert sensor.etag == "5aaa1c6bae8501f59929539c6e8f44d6" |
| 58 |
assert sensor.manufacturer == "lk" |
| 59 |
assert sensor.model_id == "ZB-KeypadGeneric-D0002" |
| 60 |
assert sensor.name == "Keypad" |
| 61 |
assert sensor.software_version == "3.13" |
| 62 |
assert sensor.type == "ZHAAncillaryControl" |
| 63 |
assert sensor.unique_id == "ec:1b:bd:ff:fe:6f:c3:4d-01-0501" |
| 64 |
|
| 65 |
|
| 66 |
ENUM_PROPERTY_DATA = [ |
| 67 |
( |
| 68 |
("state", "panel"), |
| 69 |
"panel", |
| 70 |
{ |
| 71 |
"armed_away": AncillaryControlPanel.ARMED_AWAY, |
| 72 |
"unsupported": AncillaryControlPanel.UNKNOWN, |
| 73 |
None: AncillaryControlPanel.UNKNOWN, |
| 74 |
}, |
| 75 |
), |
| 76 |
] |
| 77 |
|
| 78 |
|
| 79 |
@pytest.mark.parametrize(("path", "property", "data"), ENUM_PROPERTY_DATA) |
| 80 |
async def test_enum_ancillary_control_properties(deconz_sensor, path, property, data): |
| 81 |
"""Verify enum properties return expected values or None.""" |
| 82 |
sensor = await deconz_sensor( |
| 83 |
{"config": {}, "state": {}, "type": "ZHAAncillaryControl"} |
| 84 |
) |
| 85 |
|
| 86 |
assert getattr(sensor, property) is None |
| 87 |
|
| 88 |
for input, output in data.items(): |
| 89 |
sensor.update({path[0]: {path[1]: input}}) |
| 90 |
assert getattr(sensor, property) == output |