ics_2000_python 0.1.5__py3-none-any.whl → 0.1.6__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
ics_2000/hub.py CHANGED
@@ -1,4 +1,5 @@
1
1
  import json
2
+ import logging
2
3
  from datetime import datetime
3
4
 
4
5
  import requests
@@ -22,6 +23,8 @@ from .model.device_config import DeviceConfig
22
23
  from .model.device_data import DeviceData
23
24
  from .model.entity_type import Entity_Type
24
25
 
26
+ logger = logging.getLogger(__name__)
27
+
25
28
 
26
29
  class Hub:
27
30
  """KlikAanKlikUit ICS-2000 Control Station connection info
@@ -136,7 +139,6 @@ class Hub:
136
139
  raise NoHomeSelectedException()
137
140
 
138
141
  entities = self.get_raw_devices_data(True, False)
139
- print(entities)
140
142
  for device in entities:
141
143
  device_data = DeviceData(
142
144
  home_id=self.home_id,
@@ -270,13 +272,17 @@ class Hub:
270
272
  "home_id": "",
271
273
  "entity_id": ids_string,
272
274
  }
273
- status_list = requests.post(
275
+ response = requests.post(
274
276
  f"{API_URL}/entity.php",
275
277
  params,
276
- ).json()
278
+ )
279
+ if response.status_code != 200:
280
+ raise Exception(
281
+ f"Unknown error while fetching device statuses, {response.status_code} response: {response.content}"
282
+ )
283
+ status_list = response.json()
277
284
 
278
285
  if len(status_list) == 0:
279
- print(params)
280
286
  raise Exception(
281
287
  f"Unknown error while fetching device statuses, response json: {status_list}"
282
288
  )
@@ -299,14 +305,48 @@ class Hub:
299
305
 
300
306
  def get_all_device_statuses(self):
301
307
  status_list = self.get_raw_device_statuses(False, True)
308
+
309
+ if not isinstance(status_list, list):
310
+ logger.warning(
311
+ "ICS-2000: invalid device status response; type=%s",
312
+ type(status_list).__name__,
313
+ )
314
+ return
315
+
302
316
  for device in status_list:
303
- json_status = device["status"]
304
- if "module" in json_status.keys():
305
- self.device_statuses[device["id"]] = json_status["module"]["functions"]
306
- elif "group" in json_status.keys():
307
- self.device_statuses[device["id"]] = json_status["group"]["functions"]
317
+ if not isinstance(device, dict):
318
+ logger.debug("ICS-2000: skipping malformed device record")
319
+ continue
320
+
321
+ device_id = device.get("id")
322
+ json_status = device.get("status")
323
+
324
+ if device_id is None or not isinstance(json_status, dict):
325
+ logger.debug(
326
+ "ICS-2000: skipping device with invalid status; id=%s",
327
+ device_id,
328
+ )
329
+ continue
330
+
331
+ if "module" in json_status:
332
+ section = json_status["module"]
333
+ elif "group" in json_status:
334
+ section = json_status["group"]
308
335
  else:
309
- Exception("Module or group data not found")
336
+ logger.debug(
337
+ "ICS-2000: unsupported status structure; id=%s",
338
+ device_id,
339
+ )
340
+ continue
341
+
342
+ if not isinstance(section, dict) or "functions" not in section:
343
+ logger.debug(
344
+ "ICS-2000: missing device functions; id=%s",
345
+ device_id,
346
+ )
347
+ continue
348
+
349
+ self.device_statuses[device_id] = section["functions"]
310
350
 
311
351
  def change_status(
312
352
  self,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: ics_2000_python
3
- Version: 0.1.5
3
+ Version: 0.1.6
4
4
  Summary:
5
5
  Keywords: ics_2000,ics-2000,klikaanklikuit
6
6
  Author: iiTzArcur
@@ -10,14 +10,14 @@ ics_2000/entities/dim_device.py,sha256=aza_BKYk8QjLqbCJHFoWzbo_ZoJlObgPUIja1oKtA
10
10
  ics_2000/entities/entity.py,sha256=822GeRCE4RKuehe27EJ0PP6pQ-bDIHqPe8vdzCcXVvA,1152
11
11
  ics_2000/entities/switch_device.py,sha256=69E7VD2mrHQnngtyhGkYcC5kQEjPSirjHvo1oH5-Ccc,2244
12
12
  ics_2000/exceptions.py,sha256=kJeu9-uCZ0bqjzxkffF65m1Q7u4qEoEGTb0yZiUwGKA,353
13
- ics_2000/hub.py,sha256=wyDl5Bi1dceuptP-hYsHuXzdU_hjMBwuD9JRo1SsMwk,13745
13
+ ics_2000/hub.py,sha256=rdmVSbVbD9Ak7y7KNN9oW17YhDAJmNxkz4LP0qMKcdQ,14975
14
14
  ics_2000/model/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
15
15
  ics_2000/model/device_config.py,sha256=lULB6FWY2fKi3abHmtsDMZExEMlTLcWyxcp6bPsR9q4,941
16
16
  ics_2000/model/device_data.py,sha256=92P-uS1hTtNFlOpjNdKyf_Os4NEFMCK7vCsGzeLicW4,434
17
17
  ics_2000/model/entity_type.py,sha256=U58z4GiXma-MX6XQL6t1a3IVuubIoW5CwE71YmnmjBQ,191
18
18
  ics_2000/model/smart_meter_data.py,sha256=yH1yFnU51BmyrK-f5ez3YElAITDJFcEjDofu5JFgG_Y,633
19
19
  ics_2000/model/smart_meter_data_current.py,sha256=HajM_osqE7MqMwOXCoqBfkPInWgzJhsjtpezcCzVX1A,742
20
- ics_2000_python-0.1.5.dist-info/LICENSE,sha256=WYmcYJG1QFgu1hfo7qrEkZ3Jhcz8NUWe6XUraZvlIFs,10172
21
- ics_2000_python-0.1.5.dist-info/METADATA,sha256=F_VWrXUHX5AvVpTeKfDh7yHURL1MyFLg99qQ5J_q0eE,1464
22
- ics_2000_python-0.1.5.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
23
- ics_2000_python-0.1.5.dist-info/RECORD,,
20
+ ics_2000_python-0.1.6.dist-info/LICENSE,sha256=WYmcYJG1QFgu1hfo7qrEkZ3Jhcz8NUWe6XUraZvlIFs,10172
21
+ ics_2000_python-0.1.6.dist-info/METADATA,sha256=__y0xJzPdJ7Tgh51fN9niKNznXqIAQKkAdpompCOGJM,1464
22
+ ics_2000_python-0.1.6.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
23
+ ics_2000_python-0.1.6.dist-info/RECORD,,