| 1 |
"""Test pydeCONZ vibration sensor.""" |
| 2 |
|
| 3 |
from unittest.mock import Mock |
| 4 |
|
| 5 |
DATA = { |
| 6 |
"config": { |
| 7 |
"battery": 91, |
| 8 |
"on": True, |
| 9 |
"pending": [], |
| 10 |
"reachable": True, |
| 11 |
"sensitivity": 21, |
| 12 |
"sensitivitymax": 21, |
| 13 |
"temperature": 3200, |
| 14 |
}, |
| 15 |
"ep": 1, |
| 16 |
"etag": "b7599df551944df97b2aa87d160b9c45", |
| 17 |
"manufacturername": "LUMI", |
| 18 |
"modelid": "lumi.vibration.aq1", |
| 19 |
"name": "Vibration 1", |
| 20 |
"state": { |
| 21 |
"lastupdated": "2019-03-09T15:53:07", |
| 22 |
"orientation": [10, 1059, 0], |
| 23 |
"tiltangle": 83, |
| 24 |
"vibration": True, |
| 25 |
"vibrationstrength": 114, |
| 26 |
}, |
| 27 |
"swversion": "20180130", |
| 28 |
"type": "ZHAVibration", |
| 29 |
"uniqueid": "xx:xx:xx:xx:xx:xx:xx:xx-01-0101", |
| 30 |
} |
| 31 |
|
| 32 |
|
| 33 |
async def test_sensor_vibration(deconz_sensor): |
| 34 |
"""Verify that vibration sensor works.""" |
| 35 |
sensor = await deconz_sensor(DATA) |
| 36 |
|
| 37 |
assert sensor.orientation == [10, 1059, 0] |
| 38 |
assert sensor.sensitivity == 21 |
| 39 |
assert sensor.max_sensitivity == 21 |
| 40 |
assert sensor.tilt_angle == 83 |
| 41 |
assert sensor.vibration is True |
| 42 |
assert sensor.vibration_strength == 114 |
| 43 |
|
| 44 |
|
| 45 |
assert sensor.battery == 91 |
| 46 |
assert sensor.ep == 1 |
| 47 |
assert sensor.low_battery is None |
| 48 |
assert sensor.on is True |
| 49 |
assert sensor.reachable is True |
| 50 |
assert sensor.tampered is None |
| 51 |
assert sensor.internal_temperature == 32 |
| 52 |
|
| 53 |
|
| 54 |
assert sensor.deconz_id == "/sensors/0" |
| 55 |
assert sensor.etag == "b7599df551944df97b2aa87d160b9c45" |
| 56 |
assert sensor.manufacturer == "LUMI" |
| 57 |
assert sensor.model_id == "lumi.vibration.aq1" |
| 58 |
assert sensor.name == "Vibration 1" |
| 59 |
assert sensor.software_version == "20180130" |
| 60 |
assert sensor.type == "ZHAVibration" |
| 61 |
assert sensor.unique_id == "xx:xx:xx:xx:xx:xx:xx:xx-01-0101" |
| 62 |
|
| 63 |
sensor.register_callback(mock_callback := Mock()) |
| 64 |
assert sensor._callbacks |
| 65 |
|
| 66 |
event = {"state": {"lastupdated": "2019-03-15T10:15:17", "orientation": [0, 84, 6]}} |
| 67 |
sensor.update(event) |
| 68 |
|
| 69 |
mock_callback.assert_called_once() |
| 70 |
assert sensor.changed_keys == {"state", "lastupdated", "orientation"} |
| 71 |
|
| 72 |
sensor.remove_callback(mock_callback) |
| 73 |
assert not sensor._callbacks |