Debian Codegraph @

tests/sensors/test_daylight.py

raw symbols SCIP
1 """Test pydeCONZ daylight sensor."""
2
3 from pydeconz.models.sensor.daylight import DayLightStatus
4
5 DATA = {
6 "config": {
7 "configured": True,
8 "on": True,
9 "sunriseoffset": 30,
10 "sunsetoffset": -30,
11 },
12 "etag": "55047cf652a7e594d0ee7e6fae01dd38",
13 "manufacturername": "Philips",
14 "modelid": "PHDL00",
15 "name": "Daylight",
16 "state": {
17 "dark": False,
18 "daylight": True,
19 "lastupdated": "2022-08-07T10:54:55.021",
20 "status": 170,
21 "sunrise": "2022-08-07T02:47:23",
22 "sunset": "2022-08-07T19:02:23",
23 },
24 "swversion": "1.0",
25 "type": "Daylight",
26 "uniqueid": "xx:xx:xx:FF:FF:xx:xx:xx-01",
27 }
28
29
30 async def test_handler_daylight(mock_aioresponse, deconz_session, deconz_called_with):
31 """Verify that door lock sensor works."""
32 daylight = deconz_session.sensors.daylight
33
34 mock_aioresponse.put("http://host:80/api/apikey/sensors/0/config")
35 await daylight.set_config("0", sunrise_offset=100)
36 assert deconz_called_with(
37 "put", path="/sensors/0/config", json={"sunriseoffset": 100}
38 )
39
40 mock_aioresponse.put("http://host:80/api/apikey/sensors/0/config")
41 await daylight.set_config("0", sunset_offset=-100)
42 assert deconz_called_with(
43 "put", path="/sensors/0/config", json={"sunsetoffset": -100}
44 )
45
46
47 async def test_sensor_daylight(deconz_sensor):
48 """Verify that daylight sensor works."""
49 sensor = await deconz_sensor(DATA)
50
51 assert sensor.configured is True
52 assert sensor.dark is False
53 assert sensor.daylight is True
54 assert sensor.daylight_status == DayLightStatus.SOLAR_NOON
55 assert sensor.status == "solar_noon"
56 assert sensor.sunrise == "2022-08-07T02:47:23"
57 assert sensor.sunrise_offset == 30
58 assert sensor.sunset == "2022-08-07T19:02:23"
59 assert sensor.sunset_offset == -30
60
61 # DeconzSensor
62 assert sensor.battery is None
63 assert sensor.ep is None
64 assert sensor.low_battery is None
65 assert sensor.on is True
66 assert sensor.reachable is True
67 assert sensor.tampered is None
68 assert sensor.internal_temperature is None
69
70 # DeconzDevice
71 assert sensor.deconz_id == "/sensors/0"
72 assert sensor.etag == "55047cf652a7e594d0ee7e6fae01dd38"
73 assert sensor.manufacturer == "Philips"
74 assert sensor.model_id == "PHDL00"
75 assert sensor.name == "Daylight"
76 assert sensor.software_version == "1.0"
77 assert sensor.type == "Daylight"
78 assert sensor.unique_id == "xx:xx:xx:FF:FF:xx:xx:xx-01"
79
80 statuses = (100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200, 210, 220, 230, 0)
81
82 for status in statuses:
83 event = {"state": {"status": status}}
84 sensor.update(event)
85
86 assert sensor.changed_keys == {"state", "status"}
87 assert sensor.daylight_status == DayLightStatus(status)
88
89 sensor.update({"state": {"status": status}})
90 assert sensor.daylight_status == DayLightStatus.UNKNOWN