ics_2000_python 0.1.2__tar.gz → 0.1.3__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 (22) hide show
  1. {ics_2000_python-0.1.2 → ics_2000_python-0.1.3}/PKG-INFO +6 -4
  2. {ics_2000_python-0.1.2 → ics_2000_python-0.1.3}/README.md +3 -1
  3. ics_2000_python-0.1.3/ics_2000/exceptions.py +12 -0
  4. {ics_2000_python-0.1.2 → ics_2000_python-0.1.3}/ics_2000/hub.py +28 -20
  5. {ics_2000_python-0.1.2 → ics_2000_python-0.1.3}/pyproject.toml +1 -1
  6. {ics_2000_python-0.1.2 → ics_2000_python-0.1.3}/LICENSE +0 -0
  7. {ics_2000_python-0.1.2 → ics_2000_python-0.1.3}/ics_2000/__init__.py +0 -0
  8. {ics_2000_python-0.1.2 → ics_2000_python-0.1.3}/ics_2000/command.py +0 -0
  9. {ics_2000_python-0.1.2 → ics_2000_python-0.1.3}/ics_2000/config.py +0 -0
  10. {ics_2000_python-0.1.2 → ics_2000_python-0.1.3}/ics_2000/encryption.py +0 -0
  11. {ics_2000_python-0.1.2 → ics_2000_python-0.1.3}/ics_2000/entities/__init__.py +0 -0
  12. {ics_2000_python-0.1.2 → ics_2000_python-0.1.3}/ics_2000/entities/color_temperature_device.py +0 -0
  13. {ics_2000_python-0.1.2 → ics_2000_python-0.1.3}/ics_2000/entities/device.py +0 -0
  14. {ics_2000_python-0.1.2 → ics_2000_python-0.1.3}/ics_2000/entities/dim_device.py +0 -0
  15. {ics_2000_python-0.1.2 → ics_2000_python-0.1.3}/ics_2000/entities/entity.py +0 -0
  16. {ics_2000_python-0.1.2 → ics_2000_python-0.1.3}/ics_2000/entities/switch_device.py +0 -0
  17. {ics_2000_python-0.1.2 → ics_2000_python-0.1.3}/ics_2000/model/__init__.py +0 -0
  18. {ics_2000_python-0.1.2 → ics_2000_python-0.1.3}/ics_2000/model/device_config.py +0 -0
  19. {ics_2000_python-0.1.2 → ics_2000_python-0.1.3}/ics_2000/model/device_data.py +0 -0
  20. {ics_2000_python-0.1.2 → ics_2000_python-0.1.3}/ics_2000/model/entity_type.py +0 -0
  21. {ics_2000_python-0.1.2 → ics_2000_python-0.1.3}/ics_2000/model/smart_meter_data.py +0 -0
  22. {ics_2000_python-0.1.2 → ics_2000_python-0.1.3}/ics_2000/model/smart_meter_data_current.py +0 -0
@@ -1,14 +1,14 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.3
2
2
  Name: ics_2000_python
3
- Version: 0.1.2
3
+ Version: 0.1.3
4
4
  Summary:
5
- Home-page: https://github.com/zefanjajobse/ics_2000_python
6
5
  Keywords: ics_2000,ics-2000,klikaanklikuit
7
6
  Author: iiTzArcur
8
7
  Author-email: zefanjaj@gmail.com
9
8
  Requires-Python: >=3.12,<4.0
10
9
  Classifier: Programming Language :: Python :: 3
11
10
  Classifier: Programming Language :: Python :: 3.12
11
+ Classifier: Programming Language :: Python :: 3.13
12
12
  Requires-Dist: pycryptodome (>=3.21.0,<4.0.0)
13
13
  Requires-Dist: requests (>=2.32.3,<3.0.0)
14
14
  Project-URL: Repository, https://github.com/zefanjajobse/ics_2000_python
@@ -24,7 +24,9 @@ from ics_2000.entities.switch_device import SwitchDevice
24
24
  from ics_2000.hub import Hub
25
25
 
26
26
  hub = Hub("example@email.com", "password")
27
- hub.login() # Authenticate
27
+ homes = hub.login() # Authenticate
28
+ print(homes) # returns a dictionary of homes, ex: {"0": "test home}
29
+ hub.select_home("132829") # Select the right home by id
28
30
  hub.get_devices() # request devices
29
31
  for device in hub.devices:
30
32
  if type(device) is SwitchDevice or type(device) is DimDevice:
@@ -8,7 +8,9 @@ from ics_2000.entities.switch_device import SwitchDevice
8
8
  from ics_2000.hub import Hub
9
9
 
10
10
  hub = Hub("example@email.com", "password")
11
- hub.login() # Authenticate
11
+ homes = hub.login() # Authenticate
12
+ print(homes) # returns a dictionary of homes, ex: {"0": "test home}
13
+ hub.select_home("132829") # Select the right home by id
12
14
  hub.get_devices() # request devices
13
15
  for device in hub.devices:
14
16
  if type(device) is SwitchDevice or type(device) is DimDevice:
@@ -0,0 +1,12 @@
1
+
2
+ class InvalidAuthException(Exception):
3
+ """When the authentication failed"""
4
+
5
+ class InvalidHomeException(Exception):
6
+ """When selected home does not exist as a option"""
7
+
8
+ class InvalidMacOrAuthException(Exception):
9
+ """When the auth or mac address is not set"""
10
+
11
+ class NoHomeSelectedException(Exception):
12
+ """When no home is selected"""
@@ -1,6 +1,8 @@
1
1
  from datetime import datetime
2
2
  import json
3
3
  import requests
4
+
5
+ from ics_2000.exceptions import InvalidAuthException, InvalidHomeException, InvalidMacOrAuthException, NoHomeSelectedException
4
6
  from .command import Command
5
7
  from .encryption import decrypt
6
8
  from .config import API_URL, device_configs
@@ -23,6 +25,7 @@ class Hub:
23
25
  """
24
26
 
25
27
  def __init__(self, email: str, password: str):
28
+ self.homes = []
26
29
  self.devices: list[
27
30
  Device | DimDevice | SwitchDevice | ColorTemperatureDevice
28
31
  ] = []
@@ -46,9 +49,10 @@ class Hub:
46
49
  self.update_date = datetime.min
47
50
  """When the device statuses were last updated"""
48
51
 
49
- def login(self) -> None:
52
+ def login(self) -> dict[str, str]:
50
53
  """Logs in to the account given"""
51
- test = requests.post(
54
+ self.homes = []
55
+ response = requests.post(
52
56
  f"{API_URL}/account.php",
53
57
  {
54
58
  "action": "login",
@@ -60,24 +64,28 @@ class Hub:
60
64
  },
61
65
  )
62
66
 
63
- if test.status_code != 200:
64
- if test.status_code == 401:
65
- raise Exception("Incorrect username or password")
66
- raise Exception(test.content)
67
-
68
- response = test.json()
69
- if len(response.get("homes", [])) > 0:
70
- home: dict = response["homes"][0]
71
- self.aes_key = home.get("aes_key", "")
72
- self.mac = home.get("mac", "")
73
- self.home_id = home.get("home_id")
74
- self.home_name = home.get("home_name")
75
- else:
76
- raise Exception("No homes")
67
+ if response.status_code != 200:
68
+ if response.status_code == 401:
69
+ raise InvalidAuthException("Incorrect username or password")
70
+ raise InvalidAuthException(response.content)
71
+
72
+ data = response.json()
73
+ if data is not None:
74
+ self.homes = data.get("homes", [])
75
+ return dict([(home.get("home_id"), home.get("home_name"))for home in self.homes])
76
+
77
+ def select_home(self, home_id: str) -> None:
78
+ home = next(home for home in self.homes if home.get("home_id") == home_id)
79
+ if home is None:
80
+ raise InvalidHomeException()
81
+ self.aes_key = home.get("aes_key", "")
82
+ self.mac = home.get("mac", "")
83
+ self.home_id = home.get("home_id")
84
+ self.home_name = home.get("home_name")
77
85
 
78
86
  def get_raw_devices_data(self, decrypt_data, decrypt_status) -> list:
79
87
  if self.aes_key is None or self.mac is None:
80
- raise Exception("no mac or auth key")
88
+ raise InvalidMacOrAuthException()
81
89
 
82
90
  device_info = requests.post(
83
91
  f"{API_URL}/gateway.php",
@@ -115,7 +123,7 @@ class Hub:
115
123
  ) -> list[Device | DimDevice | SwitchDevice | ColorTemperatureDevice]:
116
124
  """Gets all devices connected to the hub"""
117
125
  if self.home_id is None:
118
- raise Exception("no home")
126
+ raise NoHomeSelectedException()
119
127
 
120
128
  entities = self.get_raw_devices_data(True, False)
121
129
  for device in entities:
@@ -161,7 +169,7 @@ class Hub:
161
169
  entity_type: Entity_Type,
162
170
  ) -> Command:
163
171
  if self.aes_key is None or self.mac is None:
164
- raise Exception("no mac or auth key")
172
+ raise InvalidMacOrAuthException()
165
173
 
166
174
  device_functions: list[int | float] = []
167
175
 
@@ -264,7 +272,7 @@ class Hub:
264
272
  self, data: dict, decrypt_data: bool, decrypt_status: bool
265
273
  ) -> dict:
266
274
  if self.aes_key is None or self.mac is None:
267
- raise Exception("no mac or auth key")
275
+ raise InvalidMacOrAuthException()
268
276
 
269
277
  if decrypt_data:
270
278
  data["data"] = json.loads(decrypt(data.get("data", ""), self.aes_key))
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "ics_2000_python"
3
- version = "0.1.2"
3
+ version = "0.1.3"
4
4
  description = ""
5
5
  authors = ["iiTzArcur <zefanjaj@gmail.com>"]
6
6
  readme = "README.md"
File without changes