Debian Codegraph @

tests/test_config.py

raw symbols SCIP
1 """Test pydeCONZ config.
2
3 pytest --cov-report term-missing --cov=pydeconz.config tests/test_config.py
4 """
5
6 from pydeconz.config import (
7 ConfigDeviceName,
8 ConfigNTP,
9 ConfigTimeFormat,
10 ConfigUpdateChannel,
11 ConfigZigbeeChannel,
12 )
13
14
15 async def test_create_config(
16 mock_aioresponse, deconz_refresh_state, deconz_called_with
17 ):
18 """Verify that creating a config works."""
19 deconz_session = await deconz_refresh_state(config=FIXTURE_CONFIG)
20 config = deconz_session.config
21
22 assert config.api_version == "1.0.4"
23 assert config.bridge_id == "0123456789AB"
24 assert config.device_name == ConfigDeviceName.UNKNOWN
25 assert config.dhcp
26 assert config.firmware_version == "0x26490700"
27 assert config.gateway == "192.168.0.1"
28 assert config.ip_address == "192.168.0.90"
29 assert config.link_button is False
30 assert config.local_time == "2017-11-04T13:01:19"
31 assert config.mac == "00:11:22:33:44:55"
32 assert config.model_id == "deCONZ"
33 assert config.name == "deCONZ-GW"
34 assert config.network_mask == "255.255.255.0"
35 assert config.network_open_duration == 60
36 assert not config.ntp
37 assert config.pan_id == 50436
38 assert not config.portal_services
39 assert config.rf_connected
40 assert config.software_update == {
41 "checkforupdate": False,
42 "devicetypes": {"bridge": False, "lights": [], "sensors": []},
43 "notify": False,
44 "text": "",
45 "updatestate": 0,
46 "url": "",
47 }
48 assert config.software_version == "2.4.82"
49 assert config.time_format == ConfigTimeFormat.FORMAT_24H
50 assert config.time_zone == "Europe/Stockholm"
51 assert not config.utc
52 assert config.uuid == "12345678-90AB-CDEF-1234-1234567890AB"
53 assert config.websocket_notify_all
54 assert config.websocket_port == 443
55 assert config.whitelist == {
56 "1234567890": {
57 "create date": "2017-11-02T23:13:13",
58 "last use date": "2017-11-04T12:00:03",
59 "name": "deCONZ WebApp",
60 }
61 }
62 assert config.zigbee_channel == ConfigZigbeeChannel.CHANNEL_11
63
64 del config.raw["bridgeid"]
65 assert config.bridge_id == "0000000000000000"
66
67 config.raw["bridgeid"] = "00212EFFFF012345"
68 assert config.bridge_id == "00212E012345"
69
70 config.raw["ntp"] = "synced"
71 assert config.ntp == ConfigNTP.SYNCED
72
73 mock_aioresponse.put("http://host:80/api/apikey/config")
74 await config.set_config(
75 discovery=True,
76 group_delay=1000,
77 light_last_seen_interval=100,
78 name="ABC",
79 network_open_duration=10,
80 otau_active=False,
81 permit_join=111,
82 rf_connected=True,
83 time_format=ConfigTimeFormat.FORMAT_24H,
84 time_zone="Europe/Stockholm",
85 unlock=200,
86 update_channel=ConfigUpdateChannel.BETA,
87 utc="2017-11-04T12:01:19",
88 zigbee_channel=ConfigZigbeeChannel.CHANNEL_15,
89 websocket_notify_all=False,
90 )
91 assert deconz_called_with(
92 "put",
93 path="/config",
94 json={
95 "discovery": True,
96 "groupdelay": 1000,
97 "lightlastseeninterval": 100,
98 "name": "ABC",
99 "networkopenduration": 10,
100 "otauactive": False,
101 "permitjoin": 111,
102 "rfconnected": True,
103 "timeformat": "24h",
104 "timezone": "Europe/Stockholm",
105 "unlock": 200,
106 "updatechannel": "beta",
107 "utc": "2017-11-04T12:01:19",
108 "zigbeechannel": 15,
109 "websocketnotifyall": False,
110 },
111 )
112
113
114 FIXTURE_CONFIG = {
115 "UTC": "2017-11-04T12:01:19",
116 "apiversion": "1.0.4",
117 "backup": {"errorcode": 0, "status": "idle"},
118 "bridgeid": "0123456789AB",
119 "datastoreversion": "60",
120 "devicename": "",
121 "dhcp": True,
122 "disablePermitJoinAutoOff": False,
123 "factorynew": False,
124 "fwversion": "0x26490700",
125 "gateway": "192.168.0.1",
126 "internetservices": {"remoteaccess": "disconnected"},
127 "ipaddress": "192.168.0.90",
128 "lightlastseeninterval": 60,
129 "linkbutton": False,
130 "localtime": "2017-11-04T13:01:19",
131 "mac": "00:11:22:33:44:55",
132 "modelid": "deCONZ",
133 "name": "deCONZ-GW",
134 "netmask": "255.255.255.0",
135 "networkopenduration": 60,
136 "panid": 50436,
137 "portalconnection": "disconnected",
138 "portalservices": False,
139 "portalstate": {
140 "communication": "disconnected",
141 "incoming": False,
142 "outgoing": False,
143 "signedon": False,
144 },
145 "proxyaddress": "none",
146 "proxyport": 0,
147 "replacesbridgeid": None,
148 "rfconnected": True,
149 "starterkitid": "",
150 "swupdate": {
151 "checkforupdate": False,
152 "devicetypes": {"bridge": False, "lights": [], "sensors": []},
153 "notify": False,
154 "text": "",
155 "updatestate": 0,
156 "url": "",
157 },
158 "swversion": "2.4.82",
159 "timeformat": "24h",
160 "timezone": "Europe/Stockholm",
161 "uuid": "12345678-90AB-CDEF-1234-1234567890AB",
162 "websocketnotifyall": True,
163 "websocketport": 443,
164 "whitelist": {
165 "1234567890": {
166 "create date": "2017-11-02T23:13:13",
167 "last use date": "2017-11-04T12:00:03",
168 "name": "deCONZ WebApp",
169 }
170 },
171 "wifi": "not-installed",
172 "wifiappw": "",
173 "wifichannel": "1",
174 "wifiip": "192.168.8.1",
175 "wifiname": "Not set",
176 "wifitype": "accesspoint",
177 "zigbeechannel": 11,
178 }