| 1 |
"""Test pydeCONZ light level.""" |
| 2 |
|
| 3 |
DATA = { |
| 4 |
"config": { |
| 5 |
"alert": "none", |
| 6 |
"battery": 100, |
| 7 |
"ledindication": False, |
| 8 |
"on": True, |
| 9 |
"pending": [], |
| 10 |
"reachable": True, |
| 11 |
"tholddark": 12000, |
| 12 |
"tholdoffset": 7000, |
| 13 |
"usertest": False, |
| 14 |
}, |
| 15 |
"ep": 2, |
| 16 |
"etag": "5cfb81765e86aa53ace427cfd52c6d52", |
| 17 |
"manufacturername": "Philips", |
| 18 |
"modelid": "SML001", |
| 19 |
"name": "Motion sensor 4", |
| 20 |
"state": { |
| 21 |
"dark": True, |
| 22 |
"daylight": False, |
| 23 |
"lastupdated": "2019-05-05T14:37:06", |
| 24 |
"lightlevel": 6955, |
| 25 |
"lux": 5, |
| 26 |
}, |
| 27 |
"swversion": "6.1.0.18912", |
| 28 |
"type": "ZHALightLevel", |
| 29 |
"uniqueid": "00:17:88:01:03:28:8c:9b-02-0400", |
| 30 |
} |
| 31 |
|
| 32 |
|
| 33 |
async def test_handler_light_level( |
| 34 |
mock_aioresponse, deconz_session, deconz_called_with |
| 35 |
): |
| 36 |
"""Verify that configuring light level sensors works.""" |
| 37 |
light_level = deconz_session.sensors.light_level |
| 38 |
|
| 39 |
mock_aioresponse.put("http://host:80/api/apikey/sensors/0/config") |
| 40 |
await light_level.set_config("0", threshold_dark=10, threshold_offset=20) |
| 41 |
assert deconz_called_with( |
| 42 |
"put", |
| 43 |
path="/sensors/0/config", |
| 44 |
json={"tholddark": 10, "tholdoffset": 20}, |
| 45 |
) |
| 46 |
|
| 47 |
mock_aioresponse.put("http://host:80/api/apikey/sensors/0/config") |
| 48 |
await light_level.set_config("0", threshold_dark=1) |
| 49 |
assert deconz_called_with( |
| 50 |
"put", |
| 51 |
path="/sensors/0/config", |
| 52 |
json={"tholddark": 1}, |
| 53 |
) |
| 54 |
|
| 55 |
mock_aioresponse.put("http://host:80/api/apikey/sensors/0/config") |
| 56 |
await light_level.set_config("0", threshold_offset=2) |
| 57 |
assert deconz_called_with( |
| 58 |
"put", |
| 59 |
path="/sensors/0/config", |
| 60 |
json={"tholdoffset": 2}, |
| 61 |
) |
| 62 |
|
| 63 |
|
| 64 |
async def test_sensor_light_level(deconz_sensor): |
| 65 |
"""Verify that light level sensor works.""" |
| 66 |
sensor = await deconz_sensor(DATA) |
| 67 |
|
| 68 |
assert sensor.dark is True |
| 69 |
assert sensor.daylight is False |
| 70 |
assert sensor.light_level == 6955 |
| 71 |
assert sensor.lux == 5 |
| 72 |
assert sensor.scaled_light_level == 5 |
| 73 |
assert sensor.threshold_dark == 12000 |
| 74 |
assert sensor.threshold_offset == 7000 |
| 75 |
|
| 76 |
|
| 77 |
assert sensor.battery == 100 |
| 78 |
assert sensor.ep == 2 |
| 79 |
assert sensor.low_battery is None |
| 80 |
assert sensor.on is True |
| 81 |
assert sensor.reachable is True |
| 82 |
assert sensor.tampered is None |
| 83 |
assert sensor.internal_temperature is None |
| 84 |
|
| 85 |
|
| 86 |
assert sensor.deconz_id == "/sensors/0" |
| 87 |
assert sensor.etag == "5cfb81765e86aa53ace427cfd52c6d52" |
| 88 |
assert sensor.manufacturer == "Philips" |
| 89 |
assert sensor.model_id == "SML001" |
| 90 |
assert sensor.name == "Motion sensor 4" |
| 91 |
assert sensor.software_version == "6.1.0.18912" |
| 92 |
assert sensor.type == "ZHALightLevel" |
| 93 |
assert sensor.unique_id == "00:17:88:01:03:28:8c:9b-02-0400" |