ics_2000_python 0.1.5__tar.gz → 0.1.6__tar.gz

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.
Files changed (23) hide show
  1. {ics_2000_python-0.1.5 → ics_2000_python-0.1.6}/PKG-INFO +1 -1
  2. {ics_2000_python-0.1.5 → ics_2000_python-0.1.6}/ics_2000/hub.py +50 -10
  3. {ics_2000_python-0.1.5 → ics_2000_python-0.1.6}/pyproject.toml +1 -1
  4. {ics_2000_python-0.1.5 → ics_2000_python-0.1.6}/LICENSE +0 -0
  5. {ics_2000_python-0.1.5 → ics_2000_python-0.1.6}/README.md +0 -0
  6. {ics_2000_python-0.1.5 → ics_2000_python-0.1.6}/ics_2000/__init__.py +0 -0
  7. {ics_2000_python-0.1.5 → ics_2000_python-0.1.6}/ics_2000/command.py +0 -0
  8. {ics_2000_python-0.1.5 → ics_2000_python-0.1.6}/ics_2000/config.py +0 -0
  9. {ics_2000_python-0.1.5 → ics_2000_python-0.1.6}/ics_2000/encryption.py +0 -0
  10. {ics_2000_python-0.1.5 → ics_2000_python-0.1.6}/ics_2000/entities/__init__.py +0 -0
  11. {ics_2000_python-0.1.5 → ics_2000_python-0.1.6}/ics_2000/entities/blind_device.py +0 -0
  12. {ics_2000_python-0.1.5 → ics_2000_python-0.1.6}/ics_2000/entities/color_temperature_device.py +0 -0
  13. {ics_2000_python-0.1.5 → ics_2000_python-0.1.6}/ics_2000/entities/device.py +0 -0
  14. {ics_2000_python-0.1.5 → ics_2000_python-0.1.6}/ics_2000/entities/dim_device.py +0 -0
  15. {ics_2000_python-0.1.5 → ics_2000_python-0.1.6}/ics_2000/entities/entity.py +0 -0
  16. {ics_2000_python-0.1.5 → ics_2000_python-0.1.6}/ics_2000/entities/switch_device.py +0 -0
  17. {ics_2000_python-0.1.5 → ics_2000_python-0.1.6}/ics_2000/exceptions.py +0 -0
  18. {ics_2000_python-0.1.5 → ics_2000_python-0.1.6}/ics_2000/model/__init__.py +0 -0
  19. {ics_2000_python-0.1.5 → ics_2000_python-0.1.6}/ics_2000/model/device_config.py +0 -0
  20. {ics_2000_python-0.1.5 → ics_2000_python-0.1.6}/ics_2000/model/device_data.py +0 -0
  21. {ics_2000_python-0.1.5 → ics_2000_python-0.1.6}/ics_2000/model/entity_type.py +0 -0
  22. {ics_2000_python-0.1.5 → ics_2000_python-0.1.6}/ics_2000/model/smart_meter_data.py +0 -0
  23. {ics_2000_python-0.1.5 → ics_2000_python-0.1.6}/ics_2000/model/smart_meter_data_current.py +0 -0
@@ -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
@@ -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
  [tool.poetry]
2
2
  name = "ics_2000_python"
3
- version = "0.1.5"
3
+ version = "0.1.6"
4
4
  description = ""
5
5
  authors = ["iiTzArcur <zefanjaj@gmail.com>"]
6
6
  readme = "README.md"
File without changes