ics_2000_python 0.1.0__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.
- ics_2000_python-0.1.0/LICENSE +176 -0
- ics_2000_python-0.1.0/PKG-INFO +14 -0
- ics_2000_python-0.1.0/README.md +0 -0
- ics_2000_python-0.1.0/ics_2000/__init__.py +0 -0
- ics_2000_python-0.1.0/ics_2000/command.py +87 -0
- ics_2000_python-0.1.0/ics_2000/config.py +211 -0
- ics_2000_python-0.1.0/ics_2000/encryption.py +25 -0
- ics_2000_python-0.1.0/ics_2000/entities/__init__.py +0 -0
- ics_2000_python-0.1.0/ics_2000/entities/color_temperature_device.py +28 -0
- ics_2000_python-0.1.0/ics_2000/entities/device.py +14 -0
- ics_2000_python-0.1.0/ics_2000/entities/dim_device.py +24 -0
- ics_2000_python-0.1.0/ics_2000/entities/entity.py +28 -0
- ics_2000_python-0.1.0/ics_2000/entities/switch_device.py +44 -0
- ics_2000_python-0.1.0/ics_2000/hub.py +343 -0
- ics_2000_python-0.1.0/ics_2000/model/__init__.py +0 -0
- ics_2000_python-0.1.0/ics_2000/model/device_config.py +21 -0
- ics_2000_python-0.1.0/ics_2000/model/device_data.py +21 -0
- ics_2000_python-0.1.0/ics_2000/model/entity_type.py +11 -0
- ics_2000_python-0.1.0/ics_2000/model/smart_meter_data.py +24 -0
- ics_2000_python-0.1.0/ics_2000/model/smart_meter_data_current.py +23 -0
- ics_2000_python-0.1.0/pyproject.toml +21 -0
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: ics_2000_python
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary:
|
|
5
|
+
Author: iiTzArcur
|
|
6
|
+
Author-email: zefanjaj@gmail.com
|
|
7
|
+
Requires-Python: >=3.12,<4.0
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
10
|
+
Requires-Dist: pycryptodome (>=3.21.0,<4.0.0)
|
|
11
|
+
Requires-Dist: requests (>=2.32.3,<3.0.0)
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
|
|
14
|
+
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import json
|
|
2
|
+
from typing import List
|
|
3
|
+
import socket
|
|
4
|
+
import requests
|
|
5
|
+
from .config import API_URL
|
|
6
|
+
from .encryption import encrypt
|
|
7
|
+
from .model.entity_type import Entity_Type
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class Command:
|
|
11
|
+
def __init__(
|
|
12
|
+
self,
|
|
13
|
+
hub_mac: str,
|
|
14
|
+
device_id: int,
|
|
15
|
+
device_function: int,
|
|
16
|
+
value: int,
|
|
17
|
+
aes_key: str,
|
|
18
|
+
entity_type: Entity_Type,
|
|
19
|
+
device_functions: List[int] = [],
|
|
20
|
+
):
|
|
21
|
+
self.hub_mac = hub_mac
|
|
22
|
+
self.device_id = device_id
|
|
23
|
+
self.device_function = device_function
|
|
24
|
+
self.value = value
|
|
25
|
+
self.aes_key = aes_key
|
|
26
|
+
self.entity_type = entity_type
|
|
27
|
+
self.device_functions = device_functions
|
|
28
|
+
|
|
29
|
+
data_object = {}
|
|
30
|
+
data_object[entity_type.value] = {
|
|
31
|
+
"id": device_id,
|
|
32
|
+
"function": device_function,
|
|
33
|
+
"value": value,
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if entity_type.value == "group":
|
|
37
|
+
data_object["group"]["update_group_members"] = True
|
|
38
|
+
device_functions[device_function] = value
|
|
39
|
+
data_object["group"]["functions"] = device_functions
|
|
40
|
+
|
|
41
|
+
encrypted_data = encrypt(json.dumps(data_object), aes_key)
|
|
42
|
+
# data = bytes.fromhex(encrypted_data)
|
|
43
|
+
header = bytearray(43)
|
|
44
|
+
header[0] = 1 # set frame
|
|
45
|
+
header[9:13] = (653213).to_bytes(4, byteorder="little") # set magic
|
|
46
|
+
header[2] = 128 # set type
|
|
47
|
+
header[41:43] = len(encrypted_data).to_bytes(
|
|
48
|
+
2, byteorder="little"
|
|
49
|
+
) # set data length
|
|
50
|
+
header[29:33] = device_id.to_bytes(4, byteorder="little") # set entityId
|
|
51
|
+
|
|
52
|
+
# set mac
|
|
53
|
+
mac_buffer = bytes.fromhex(hub_mac)
|
|
54
|
+
for i in range(len(mac_buffer)):
|
|
55
|
+
header[3 + i] = mac_buffer[i]
|
|
56
|
+
|
|
57
|
+
self.total_message = bytes(header) + encrypted_data
|
|
58
|
+
|
|
59
|
+
def send_to(self, host: str, port: int, send_timeout: int = 10000) -> None:
|
|
60
|
+
client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
|
61
|
+
client.settimeout(send_timeout / 1000)
|
|
62
|
+
|
|
63
|
+
try:
|
|
64
|
+
client.sendto(self.total_message, (host, port))
|
|
65
|
+
data, _ = client.recvfrom(1024)
|
|
66
|
+
except socket.timeout:
|
|
67
|
+
raise TimeoutError("Message timed out")
|
|
68
|
+
finally:
|
|
69
|
+
client.close()
|
|
70
|
+
|
|
71
|
+
def send_to_cloud(self, email: str, password: str) -> None:
|
|
72
|
+
params = {
|
|
73
|
+
"action": "add",
|
|
74
|
+
"email": email,
|
|
75
|
+
"mac": self.hub_mac,
|
|
76
|
+
"password_hash": password,
|
|
77
|
+
"device_unique_id": "",
|
|
78
|
+
"command": self.to_hex(),
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
response = requests.get(f"{API_URL}/command.php", params=params)
|
|
82
|
+
|
|
83
|
+
if response.status_code != 200:
|
|
84
|
+
raise Exception(f"Non 200 status returned: {response.status_code}")
|
|
85
|
+
|
|
86
|
+
def to_hex(self) -> str:
|
|
87
|
+
return self.total_message.hex()
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
from .model.device_config import DeviceConfig
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
API_URL = "https://trustsmartcloud2.com/ics2000_api"
|
|
5
|
+
device_configs: dict[int, DeviceConfig] = {
|
|
6
|
+
1: DeviceConfig(
|
|
7
|
+
model_name="APC3-2300R KAKU 443MHz Smartplug",
|
|
8
|
+
on_off_function=0,
|
|
9
|
+
),
|
|
10
|
+
2: DeviceConfig( # DeviceType 2 uses 0 to 15 for dim values
|
|
11
|
+
model_name="KAKU dimmable",
|
|
12
|
+
on_off_function=0,
|
|
13
|
+
dim_function=1,
|
|
14
|
+
max_brightness=15,
|
|
15
|
+
),
|
|
16
|
+
3: DeviceConfig(
|
|
17
|
+
disabled=True,
|
|
18
|
+
model_name="Actuator",
|
|
19
|
+
),
|
|
20
|
+
4: DeviceConfig(
|
|
21
|
+
disabled=True,
|
|
22
|
+
model_name="Trust wireless motion detector for outdoor use",
|
|
23
|
+
),
|
|
24
|
+
5: DeviceConfig(
|
|
25
|
+
disabled=True,
|
|
26
|
+
model_name="Contact sensor",
|
|
27
|
+
),
|
|
28
|
+
6: DeviceConfig(
|
|
29
|
+
disabled=True,
|
|
30
|
+
model_name="ACDB 7000A doorbell",
|
|
31
|
+
),
|
|
32
|
+
7: DeviceConfig(
|
|
33
|
+
disabled=True,
|
|
34
|
+
model_name="1 Channel wall control",
|
|
35
|
+
),
|
|
36
|
+
8: DeviceConfig(
|
|
37
|
+
disabled=True,
|
|
38
|
+
model_name="2 Channel wall control",
|
|
39
|
+
),
|
|
40
|
+
9: DeviceConfig(
|
|
41
|
+
disabled=True,
|
|
42
|
+
model_name="1 Channel remote control",
|
|
43
|
+
),
|
|
44
|
+
10: DeviceConfig(
|
|
45
|
+
disabled=True,
|
|
46
|
+
model_name="2 Channel remote control",
|
|
47
|
+
),
|
|
48
|
+
11: DeviceConfig(
|
|
49
|
+
disabled=True,
|
|
50
|
+
model_name="3 Channel remote control",
|
|
51
|
+
),
|
|
52
|
+
12: DeviceConfig(
|
|
53
|
+
disabled=True,
|
|
54
|
+
model_name="16 Channel remote control AYCT-102",
|
|
55
|
+
),
|
|
56
|
+
13: DeviceConfig(
|
|
57
|
+
disabled=True,
|
|
58
|
+
model_name="Wall mounted remote control AYCT_202",
|
|
59
|
+
),
|
|
60
|
+
14: DeviceConfig(
|
|
61
|
+
disabled=True,
|
|
62
|
+
model_name="Ambient light sensor",
|
|
63
|
+
),
|
|
64
|
+
15: DeviceConfig(
|
|
65
|
+
disabled=True,
|
|
66
|
+
model_name="Dusk sensor",
|
|
67
|
+
),
|
|
68
|
+
16: DeviceConfig(
|
|
69
|
+
disabled=True,
|
|
70
|
+
model_name="ARC Remote",
|
|
71
|
+
),
|
|
72
|
+
17: DeviceConfig(
|
|
73
|
+
disabled=True,
|
|
74
|
+
model_name="ARC Contact sensor",
|
|
75
|
+
),
|
|
76
|
+
18: DeviceConfig(
|
|
77
|
+
disabled=True,
|
|
78
|
+
model_name="ARC Motion sensor",
|
|
79
|
+
),
|
|
80
|
+
19: DeviceConfig(
|
|
81
|
+
disabled=True,
|
|
82
|
+
model_name="ARC Smoke sensor",
|
|
83
|
+
),
|
|
84
|
+
20: DeviceConfig(
|
|
85
|
+
disabled=True,
|
|
86
|
+
model_name="ARC Siren",
|
|
87
|
+
),
|
|
88
|
+
21: DeviceConfig(
|
|
89
|
+
disabled=True,
|
|
90
|
+
model_name="ACDB 7000B Doorbell",
|
|
91
|
+
),
|
|
92
|
+
22: DeviceConfig(
|
|
93
|
+
disabled=True,
|
|
94
|
+
model_name="AWMT Buil-in wall switch",
|
|
95
|
+
),
|
|
96
|
+
23: DeviceConfig(
|
|
97
|
+
disabled=True,
|
|
98
|
+
model_name="Somfy Actuator",
|
|
99
|
+
),
|
|
100
|
+
24: DeviceConfig(
|
|
101
|
+
model_name="KAKU dimmable lightbulb",
|
|
102
|
+
on_off_function=0,
|
|
103
|
+
dim_function=1,
|
|
104
|
+
max_brightness=15,
|
|
105
|
+
),
|
|
106
|
+
25: DeviceConfig(
|
|
107
|
+
disabled=True,
|
|
108
|
+
model_name="AGST 8800 KAKU 1 button wireless wall switch",
|
|
109
|
+
),
|
|
110
|
+
26: DeviceConfig(
|
|
111
|
+
disabled=True,
|
|
112
|
+
model_name="AGST 8802 KAKU 2 button wireless wall switch",
|
|
113
|
+
),
|
|
114
|
+
27: DeviceConfig(
|
|
115
|
+
disabled=True,
|
|
116
|
+
model_name="BREL Actuator",
|
|
117
|
+
),
|
|
118
|
+
28: DeviceConfig(
|
|
119
|
+
disabled=True,
|
|
120
|
+
model_name="Contact sensor 2",
|
|
121
|
+
),
|
|
122
|
+
29: DeviceConfig(
|
|
123
|
+
disabled=True,
|
|
124
|
+
model_name="ARC Keychain remote",
|
|
125
|
+
),
|
|
126
|
+
30: DeviceConfig(
|
|
127
|
+
disabled=True,
|
|
128
|
+
model_name="ARC Action button",
|
|
129
|
+
),
|
|
130
|
+
31: DeviceConfig(
|
|
131
|
+
disabled=True,
|
|
132
|
+
model_name="ARC Rotary dimmer",
|
|
133
|
+
),
|
|
134
|
+
32: DeviceConfig(
|
|
135
|
+
disabled=True,
|
|
136
|
+
model_name="Unkown Zigbee device",
|
|
137
|
+
),
|
|
138
|
+
33: DeviceConfig( # 0 for onOff not working, maybe this,
|
|
139
|
+
model_name="Zigbee (ledvance) smart plug",
|
|
140
|
+
on_off_function=3,
|
|
141
|
+
),
|
|
142
|
+
34: DeviceConfig( # not tested
|
|
143
|
+
model_name="Dimmable",
|
|
144
|
+
on_off_function=3,
|
|
145
|
+
dim_function=4,
|
|
146
|
+
),
|
|
147
|
+
35: DeviceConfig(
|
|
148
|
+
model_name="Zigbee RGB Light",
|
|
149
|
+
),
|
|
150
|
+
36: DeviceConfig(
|
|
151
|
+
model_name="Zigbee (ledvance) dimmable with color temperature",
|
|
152
|
+
on_off_function=3,
|
|
153
|
+
dim_function=4,
|
|
154
|
+
color_temperature_function=9,
|
|
155
|
+
),
|
|
156
|
+
37: DeviceConfig(
|
|
157
|
+
disabled=True,
|
|
158
|
+
model_name="Zigbee multi purpose dimmer",
|
|
159
|
+
),
|
|
160
|
+
38: DeviceConfig(
|
|
161
|
+
disabled=True,
|
|
162
|
+
model_name="Zigbee lock",
|
|
163
|
+
),
|
|
164
|
+
39: DeviceConfig(
|
|
165
|
+
disabled=True,
|
|
166
|
+
model_name="Zigbee light link remote",
|
|
167
|
+
),
|
|
168
|
+
40: DeviceConfig(
|
|
169
|
+
model_name="KAKU dimmable lightbulb",
|
|
170
|
+
on_off_function=3,
|
|
171
|
+
dim_function=4,
|
|
172
|
+
),
|
|
173
|
+
41: DeviceConfig( # same as 33
|
|
174
|
+
model_name="Zigbee (ledvance) smart plug",
|
|
175
|
+
on_off_function=3,
|
|
176
|
+
),
|
|
177
|
+
42: DeviceConfig(
|
|
178
|
+
disabled=True,
|
|
179
|
+
model_name="Zigbee lekkage sensor",
|
|
180
|
+
),
|
|
181
|
+
43: DeviceConfig(
|
|
182
|
+
disabled=True,
|
|
183
|
+
model_name="KAKU wireless smoke detector ZSDR-850",
|
|
184
|
+
),
|
|
185
|
+
44: DeviceConfig(
|
|
186
|
+
disabled=True,
|
|
187
|
+
model_name="Carbon monoxide sensor",
|
|
188
|
+
),
|
|
189
|
+
45: DeviceConfig(
|
|
190
|
+
disabled=True,
|
|
191
|
+
model_name="Zigbee temperature and humidity sensor",
|
|
192
|
+
),
|
|
193
|
+
46: DeviceConfig(
|
|
194
|
+
disabled=True,
|
|
195
|
+
model_name="Zigbee light group",
|
|
196
|
+
),
|
|
197
|
+
47: DeviceConfig(
|
|
198
|
+
disabled=True,
|
|
199
|
+
model_name="Zigbee fire angel sensor",
|
|
200
|
+
),
|
|
201
|
+
48: DeviceConfig(
|
|
202
|
+
model_name="KAKU group with dimmable lightbulb",
|
|
203
|
+
on_off_function=3,
|
|
204
|
+
dim_function=4,
|
|
205
|
+
),
|
|
206
|
+
238: DeviceConfig(disabled=True, model_name="P1 Module"),
|
|
207
|
+
240: DeviceConfig(disabled=True, model_name="Alarm Module"),
|
|
208
|
+
241: DeviceConfig(disabled=True, model_name="IPCam Module"),
|
|
209
|
+
242: DeviceConfig(disabled=True, model_name="Geofencing Module"),
|
|
210
|
+
243: DeviceConfig(disabled=True, model_name="System Module"),
|
|
211
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import base64
|
|
2
|
+
from Crypto.Cipher import AES
|
|
3
|
+
from Crypto.Util.Padding import unpad
|
|
4
|
+
from Crypto.Random import get_random_bytes
|
|
5
|
+
|
|
6
|
+
encoding = "utf-8"
|
|
7
|
+
block_size = 16
|
|
8
|
+
pad = lambda s: s + (block_size - len(s) % block_size) * chr(
|
|
9
|
+
block_size - len(s) % block_size
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def decrypt(string: str, aes: str) -> str:
|
|
14
|
+
base = base64.b64decode(string)
|
|
15
|
+
iv = base[:16]
|
|
16
|
+
inp = base[16:]
|
|
17
|
+
cipher = AES.new(bytes.fromhex(aes), AES.MODE_CBC, iv)
|
|
18
|
+
return unpad(cipher.decrypt(inp), 16).decode(encoding)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def encrypt(string: str, aes: str) -> bytearray:
|
|
22
|
+
base = pad(string).encode()
|
|
23
|
+
iv = bytearray(16)
|
|
24
|
+
cipher = AES.new(bytes.fromhex(aes), AES.MODE_CBC, iv)
|
|
25
|
+
return iv + cipher.encrypt(base)
|
|
File without changes
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
from ..model.device_data import DeviceData
|
|
2
|
+
from .dim_device import DimDevice
|
|
3
|
+
from ..model.device_config import DeviceConfig
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class ColorTemperatureDevice(DimDevice):
|
|
7
|
+
def __init__(self, hub, device_data: DeviceData, device_config: DeviceConfig):
|
|
8
|
+
super().__init__(hub, device_data, device_config)
|
|
9
|
+
|
|
10
|
+
if device_config.color_temperature_function is None:
|
|
11
|
+
raise ValueError(
|
|
12
|
+
f"Color temperature function not defined for '{self.device_data.name}'"
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
def change_color_temperature(
|
|
16
|
+
self, color_temperature: float, send_local: bool = True
|
|
17
|
+
) -> None:
|
|
18
|
+
return self.get_hub().change_color_temperature(
|
|
19
|
+
self.entity_id,
|
|
20
|
+
self.device_config.color_temperature_function,
|
|
21
|
+
color_temperature,
|
|
22
|
+
self.is_group,
|
|
23
|
+
send_local,
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
def get_color_temperature(self) -> float:
|
|
27
|
+
status = self.get_hub().get_device_status(self.entity_id)
|
|
28
|
+
return status[self.device_config.color_temperature_function]
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
from .entity import Entity
|
|
2
|
+
from ..model.device_data import DeviceData
|
|
3
|
+
from ..model.device_config import DeviceConfig
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class Device(Entity):
|
|
7
|
+
def __init__(self, hub, device_data: DeviceData, device_config: DeviceConfig):
|
|
8
|
+
super().__init__(
|
|
9
|
+
hub, device_data, "group" in device_data.data and "group" or "module"
|
|
10
|
+
)
|
|
11
|
+
self.device_config = device_config
|
|
12
|
+
self.disabled = (
|
|
13
|
+
device_config.disabled if device_config.disabled is not None else False
|
|
14
|
+
)
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
from ..model.device_data import DeviceData
|
|
2
|
+
from .switch_device import SwitchDevice
|
|
3
|
+
from ..model.device_config import DeviceConfig
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class DimDevice(SwitchDevice):
|
|
7
|
+
def __init__(self, hub, device_data: DeviceData, device_config: DeviceConfig):
|
|
8
|
+
super().__init__(hub, device_data, device_config)
|
|
9
|
+
|
|
10
|
+
if device_config.dim_function is None:
|
|
11
|
+
raise ValueError(f"Dim function not defined for '{self.device_data.name}'")
|
|
12
|
+
|
|
13
|
+
def dim(self, dim_level: int, send_local: bool = True) -> None:
|
|
14
|
+
return self.get_hub().dim_device(
|
|
15
|
+
self.entity_id,
|
|
16
|
+
self.device_config.dim_function,
|
|
17
|
+
dim_level,
|
|
18
|
+
self.is_group,
|
|
19
|
+
send_local,
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
def get_dim_level(self) -> int:
|
|
23
|
+
status = self.get_hub().get_device_status(self.entity_id)
|
|
24
|
+
return status[self.device_config.dim_function]
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
from typing import List
|
|
2
|
+
from ..model.device_data import DeviceData
|
|
3
|
+
from ..model.entity_type import EntityType
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class Entity:
|
|
7
|
+
def __init__(self, hub, device_data: DeviceData, entity_type: EntityType):
|
|
8
|
+
self._hub = hub
|
|
9
|
+
self.entity_id = int(device_data.id)
|
|
10
|
+
self.name = device_data.data[entity_type].get("name", "")
|
|
11
|
+
self.device_type = (
|
|
12
|
+
device_data.data[entity_type].get("device", "")
|
|
13
|
+
if "device" in device_data.data[entity_type]
|
|
14
|
+
else entity_type
|
|
15
|
+
)
|
|
16
|
+
self.device_data = device_data
|
|
17
|
+
self.is_group = entity_type == "group"
|
|
18
|
+
|
|
19
|
+
def get_status(self) -> List[int]:
|
|
20
|
+
return self._hub.get_device_status(self.entity_id)
|
|
21
|
+
|
|
22
|
+
def get_hub(self):
|
|
23
|
+
return self._hub
|
|
24
|
+
|
|
25
|
+
def change_status(self, device_function: int, value: int, send_local: bool) -> None:
|
|
26
|
+
self._hub.change_status(
|
|
27
|
+
self.entity_id, device_function, value, self.is_group, send_local
|
|
28
|
+
)
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
from ..model.device_data import DeviceData
|
|
2
|
+
from ..model.device_config import DeviceConfig
|
|
3
|
+
from .device import Device
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class SwitchDevice(Device):
|
|
7
|
+
def __init__(self, hub, device_data: DeviceData, device_config: DeviceConfig):
|
|
8
|
+
super().__init__(hub, device_data, device_config)
|
|
9
|
+
|
|
10
|
+
if device_config.on_off_function is None:
|
|
11
|
+
raise ValueError(
|
|
12
|
+
f"On/off function not defined for '{self.device_data.name}'"
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
def turn_on_off(self, on: bool, send_local: bool = True) -> None:
|
|
16
|
+
self.get_hub().turn_device_on_off(
|
|
17
|
+
self.entity_id,
|
|
18
|
+
on,
|
|
19
|
+
self.device_config.on_off_function,
|
|
20
|
+
self.is_group,
|
|
21
|
+
send_local,
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
def turn_on(self, send_local: bool = True) -> None:
|
|
25
|
+
self.get_hub().turn_device_on_off(
|
|
26
|
+
self.entity_id,
|
|
27
|
+
True,
|
|
28
|
+
self.device_config.on_off_function,
|
|
29
|
+
self.is_group,
|
|
30
|
+
send_local,
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
def turn_off(self, send_local: bool = True) -> None:
|
|
34
|
+
self.get_hub().turn_device_on_off(
|
|
35
|
+
self.entity_id,
|
|
36
|
+
False,
|
|
37
|
+
self.device_config.on_off_function,
|
|
38
|
+
self.is_group,
|
|
39
|
+
send_local,
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
def get_on_status(self) -> bool:
|
|
43
|
+
status = self.get_status()
|
|
44
|
+
return status[self.device_config.on_off_function] == 1
|
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
from datetime import datetime
|
|
2
|
+
import json
|
|
3
|
+
import requests
|
|
4
|
+
from .command import Command
|
|
5
|
+
from .encryption import decrypt
|
|
6
|
+
from .config import API_URL, device_configs
|
|
7
|
+
from .entities.color_temperature_device import ColorTemperatureDevice
|
|
8
|
+
from .entities.device import Device
|
|
9
|
+
from .entities.dim_device import DimDevice
|
|
10
|
+
from .entities.switch_device import SwitchDevice
|
|
11
|
+
from .model.device_config import DeviceConfig
|
|
12
|
+
from .model.device_data import DeviceData
|
|
13
|
+
from .model.entity_type import Entity_Type
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class Hub:
|
|
17
|
+
def __init__(self, email: str, password: str):
|
|
18
|
+
self.devices: list[
|
|
19
|
+
Device | DimDevice | SwitchDevice | ColorTemperatureDevice
|
|
20
|
+
] = []
|
|
21
|
+
self.aes_key: str | None = None
|
|
22
|
+
self.mac: str | None = None
|
|
23
|
+
self.home_name: str | None = None
|
|
24
|
+
self.home_id: str | None = None
|
|
25
|
+
self.email = email
|
|
26
|
+
self.password = password
|
|
27
|
+
self.local_address = ""
|
|
28
|
+
self.device_statuses: dict[int, list[int]] = {}
|
|
29
|
+
self.update_date = datetime.min
|
|
30
|
+
|
|
31
|
+
def login(self):
|
|
32
|
+
test = requests.post(
|
|
33
|
+
f"{API_URL}/account.php",
|
|
34
|
+
{
|
|
35
|
+
"action": "login",
|
|
36
|
+
"email": self.email,
|
|
37
|
+
"password_hash": self.password,
|
|
38
|
+
"device_unique_id": "android",
|
|
39
|
+
"platform": "",
|
|
40
|
+
"mac": "",
|
|
41
|
+
},
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
if test.status_code != 200:
|
|
45
|
+
if test.status_code == 401:
|
|
46
|
+
raise Exception("Incorrect username or password")
|
|
47
|
+
raise Exception(test.content)
|
|
48
|
+
|
|
49
|
+
response = test.json()
|
|
50
|
+
if len(response.get("homes", [])) > 0:
|
|
51
|
+
home: dict = response["homes"][0]
|
|
52
|
+
self.aes_key = home.get("aes_key", "")
|
|
53
|
+
self.mac = home.get("mac", "")
|
|
54
|
+
self.home_id = home.get("home_id")
|
|
55
|
+
self.home_name = home.get("home_name")
|
|
56
|
+
else:
|
|
57
|
+
raise Exception("No homes")
|
|
58
|
+
|
|
59
|
+
def get_raw_devices_data(self, decrypt_data, decrypt_status) -> list:
|
|
60
|
+
if self.aes_key is None or self.mac is None:
|
|
61
|
+
raise Exception("no mac or auth key")
|
|
62
|
+
|
|
63
|
+
device_info = requests.post(
|
|
64
|
+
f"{API_URL}/gateway.php",
|
|
65
|
+
{
|
|
66
|
+
"action": "sync",
|
|
67
|
+
"email": self.email,
|
|
68
|
+
"mac": self.mac,
|
|
69
|
+
"password_hash": self.password,
|
|
70
|
+
"home_id": "",
|
|
71
|
+
},
|
|
72
|
+
)
|
|
73
|
+
data = []
|
|
74
|
+
for device in device_info.json():
|
|
75
|
+
current_device = self.format_device_data(
|
|
76
|
+
device, decrypt_data, decrypt_status
|
|
77
|
+
)
|
|
78
|
+
current_device["isGroup"] = "group" in current_device.keys()
|
|
79
|
+
|
|
80
|
+
if (
|
|
81
|
+
"module" in current_device["data"].keys()
|
|
82
|
+
and "info" in current_device["data"]["module"].keys()
|
|
83
|
+
and any(i > 0 for i in current_device["data"]["module"]["info"])
|
|
84
|
+
):
|
|
85
|
+
data.append(current_device)
|
|
86
|
+
|
|
87
|
+
if "group" in current_device["data"].keys():
|
|
88
|
+
current_device["data"]["module"] = current_device["data"]["group"]
|
|
89
|
+
del current_device["data"]["group"]
|
|
90
|
+
data.append(current_device)
|
|
91
|
+
|
|
92
|
+
return data
|
|
93
|
+
|
|
94
|
+
def get_devices(self):
|
|
95
|
+
if self.home_id is None:
|
|
96
|
+
raise Exception("no home")
|
|
97
|
+
|
|
98
|
+
entities = self.get_raw_devices_data(True, False)
|
|
99
|
+
for device in entities:
|
|
100
|
+
device_data = DeviceData(
|
|
101
|
+
home_id=self.home_id,
|
|
102
|
+
name=device["data"]["module"]["name"],
|
|
103
|
+
id=device["data"]["module"]["id"],
|
|
104
|
+
device=device["data"]["module"]["device"],
|
|
105
|
+
isGroup=device.get("isGroup", False),
|
|
106
|
+
status=device.get("status", {}),
|
|
107
|
+
data=device.get("data", {}),
|
|
108
|
+
)
|
|
109
|
+
device_config = device_configs[device_data.device]
|
|
110
|
+
if device_config is None:
|
|
111
|
+
self.devices.append(
|
|
112
|
+
SwitchDevice(
|
|
113
|
+
self,
|
|
114
|
+
device_data,
|
|
115
|
+
DeviceConfig(
|
|
116
|
+
model_name="Unknown device type", on_off_function=0
|
|
117
|
+
),
|
|
118
|
+
)
|
|
119
|
+
)
|
|
120
|
+
elif device_config.color_temperature_function is not None:
|
|
121
|
+
self.devices.append(
|
|
122
|
+
ColorTemperatureDevice(self, device_data, device_config)
|
|
123
|
+
)
|
|
124
|
+
|
|
125
|
+
elif device_config.dim_function is not None:
|
|
126
|
+
self.devices.append(DimDevice(self, device_data, device_config))
|
|
127
|
+
|
|
128
|
+
elif device_config.on_off_function is not None:
|
|
129
|
+
self.devices.append(SwitchDevice(self, device_data, device_config))
|
|
130
|
+
else:
|
|
131
|
+
self.devices.append(Device(self, device_data, device_config))
|
|
132
|
+
|
|
133
|
+
def create_command(
|
|
134
|
+
self, device_id: int, device_function: int, value: int, entity_type: Entity_Type
|
|
135
|
+
) -> Command:
|
|
136
|
+
if self.aes_key is None or self.mac is None:
|
|
137
|
+
raise Exception("no mac or auth key")
|
|
138
|
+
|
|
139
|
+
device_functions: list[int] = []
|
|
140
|
+
|
|
141
|
+
# if entity_type == Entity_Type.Group:
|
|
142
|
+
# device_functions = self.device_statuses.get(device_id, [])
|
|
143
|
+
|
|
144
|
+
return Command(
|
|
145
|
+
self.mac,
|
|
146
|
+
device_id,
|
|
147
|
+
device_function,
|
|
148
|
+
value,
|
|
149
|
+
self.aes_key,
|
|
150
|
+
entity_type,
|
|
151
|
+
device_functions,
|
|
152
|
+
)
|
|
153
|
+
|
|
154
|
+
def turn_device_on_off(
|
|
155
|
+
self,
|
|
156
|
+
device_id: int,
|
|
157
|
+
on: bool,
|
|
158
|
+
on_function: int,
|
|
159
|
+
is_group: bool,
|
|
160
|
+
send_local: bool,
|
|
161
|
+
) -> None:
|
|
162
|
+
command = self.create_command(
|
|
163
|
+
device_id,
|
|
164
|
+
on_function,
|
|
165
|
+
1 if on else 0,
|
|
166
|
+
Entity_Type.Group if is_group else Entity_Type.Module,
|
|
167
|
+
)
|
|
168
|
+
return self.send_command(command, send_local)
|
|
169
|
+
|
|
170
|
+
def send_command(self, command: Command, send_local):
|
|
171
|
+
if send_local:
|
|
172
|
+
return self.send_command_to_hub(command, 2012)
|
|
173
|
+
else:
|
|
174
|
+
return self.send_command_to_cloud(command)
|
|
175
|
+
|
|
176
|
+
def send_command_to_hub(self, command: Command, port):
|
|
177
|
+
if self.local_address is None:
|
|
178
|
+
raise ValueError("Local address is undefined")
|
|
179
|
+
|
|
180
|
+
if not isinstance(port, int):
|
|
181
|
+
raise ValueError("Port needs to be an integer")
|
|
182
|
+
|
|
183
|
+
command.send_to(self.local_address, port)
|
|
184
|
+
|
|
185
|
+
def send_command_to_cloud(self, command: Command):
|
|
186
|
+
command.send_to_cloud(self.email, self.password)
|
|
187
|
+
|
|
188
|
+
def get_device_status(self, device_id: int) -> list[int]:
|
|
189
|
+
current_date = datetime.now()
|
|
190
|
+
update_date = self.update_date
|
|
191
|
+
self.update_date = datetime.now()
|
|
192
|
+
|
|
193
|
+
date_difference = (current_date - update_date).total_seconds() * 1000
|
|
194
|
+
|
|
195
|
+
if date_difference >= 2000 or len(self.device_statuses) == 0:
|
|
196
|
+
self.updating = True
|
|
197
|
+
self.get_all_device_statuses()
|
|
198
|
+
self.updating = False
|
|
199
|
+
|
|
200
|
+
# # Wait till the new data is fetched
|
|
201
|
+
# while self.updating:
|
|
202
|
+
# await asyncio.sleep(0.1)
|
|
203
|
+
|
|
204
|
+
return self.device_statuses.get(device_id, [])
|
|
205
|
+
|
|
206
|
+
def get_raw_device_statuses(
|
|
207
|
+
self, decrypt_data: bool, decrypt_status: bool
|
|
208
|
+
) -> list[dict]:
|
|
209
|
+
device_ids = [int(device.entity_id) for device in self.devices]
|
|
210
|
+
ids_string = json.dumps(device_ids)
|
|
211
|
+
|
|
212
|
+
params = {
|
|
213
|
+
"action": "get-multiple",
|
|
214
|
+
"email": self.email,
|
|
215
|
+
"mac": self.mac,
|
|
216
|
+
"password_hash": self.password,
|
|
217
|
+
"home_id": "",
|
|
218
|
+
"entity_id": ids_string,
|
|
219
|
+
}
|
|
220
|
+
status_list = requests.post(
|
|
221
|
+
f"{API_URL}/entity.php",
|
|
222
|
+
params,
|
|
223
|
+
).json()
|
|
224
|
+
|
|
225
|
+
if len(status_list) == 0:
|
|
226
|
+
print(params)
|
|
227
|
+
raise Exception(
|
|
228
|
+
f"Unknown error while fetching device statuses, response json: {status_list}"
|
|
229
|
+
)
|
|
230
|
+
return [
|
|
231
|
+
self.format_device_data(d, decrypt_data, decrypt_status)
|
|
232
|
+
for d in status_list
|
|
233
|
+
]
|
|
234
|
+
|
|
235
|
+
def format_device_data(
|
|
236
|
+
self, data: dict, decrypt_data: bool, decrypt_status: bool
|
|
237
|
+
) -> dict:
|
|
238
|
+
if self.aes_key is None or self.mac is None:
|
|
239
|
+
raise Exception("no mac or auth key")
|
|
240
|
+
|
|
241
|
+
if decrypt_data:
|
|
242
|
+
data["data"] = json.loads(decrypt(data.get("data", ""), self.aes_key))
|
|
243
|
+
if decrypt_status and data.get("status", None) is not None:
|
|
244
|
+
data["status"] = json.loads(decrypt(data.get("status", ""), self.aes_key))
|
|
245
|
+
return data
|
|
246
|
+
|
|
247
|
+
def get_all_device_statuses(self):
|
|
248
|
+
status_list = self.get_raw_device_statuses(False, True)
|
|
249
|
+
for device in status_list:
|
|
250
|
+
json_status = device["status"]
|
|
251
|
+
if "module" in json_status.keys():
|
|
252
|
+
self.device_statuses[device["id"]] = json_status["module"]["functions"]
|
|
253
|
+
elif "group" in json_status.keys():
|
|
254
|
+
self.device_statuses[device["id"]] = json_status["group"]["functions"]
|
|
255
|
+
else:
|
|
256
|
+
Exception("Module or group data not found")
|
|
257
|
+
|
|
258
|
+
def change_status(
|
|
259
|
+
self,
|
|
260
|
+
device_id: int,
|
|
261
|
+
device_function: int,
|
|
262
|
+
value: int,
|
|
263
|
+
is_group: bool,
|
|
264
|
+
send_local: bool,
|
|
265
|
+
):
|
|
266
|
+
command = self.create_command(
|
|
267
|
+
device_id,
|
|
268
|
+
device_function,
|
|
269
|
+
value,
|
|
270
|
+
Entity_Type.Group if is_group else Entity_Type.Module,
|
|
271
|
+
)
|
|
272
|
+
return self.send_command(command, send_local)
|
|
273
|
+
|
|
274
|
+
def dim_device(
|
|
275
|
+
self,
|
|
276
|
+
device_id: int,
|
|
277
|
+
dim_function: int,
|
|
278
|
+
dim_level: int,
|
|
279
|
+
is_group: bool,
|
|
280
|
+
send_local: bool,
|
|
281
|
+
):
|
|
282
|
+
if dim_level < 0 or dim_level > 255:
|
|
283
|
+
raise ValueError(f"Dim level {dim_level} is negative or greater than 255")
|
|
284
|
+
|
|
285
|
+
command = self.create_command(
|
|
286
|
+
device_id,
|
|
287
|
+
dim_function,
|
|
288
|
+
dim_level,
|
|
289
|
+
Entity_Type.Group if is_group else Entity_Type.Module,
|
|
290
|
+
)
|
|
291
|
+
return self.send_command(command, send_local)
|
|
292
|
+
|
|
293
|
+
def change_color_temperature(
|
|
294
|
+
self,
|
|
295
|
+
device_id: int,
|
|
296
|
+
color_temp_function: int,
|
|
297
|
+
color_temperature: int,
|
|
298
|
+
is_group: bool,
|
|
299
|
+
send_local: bool,
|
|
300
|
+
):
|
|
301
|
+
if color_temperature < 0 or color_temperature > 600:
|
|
302
|
+
raise ValueError(
|
|
303
|
+
f"Color temperature {color_temperature} is negative or greater than 600"
|
|
304
|
+
)
|
|
305
|
+
|
|
306
|
+
command = self.create_command(
|
|
307
|
+
device_id,
|
|
308
|
+
color_temp_function,
|
|
309
|
+
color_temperature,
|
|
310
|
+
Entity_Type.Group if is_group else Entity_Type.Module,
|
|
311
|
+
)
|
|
312
|
+
return self.send_command(command, send_local)
|
|
313
|
+
|
|
314
|
+
def generate_devices_json(self, decrypt_data: bool, decrypt_status: bool):
|
|
315
|
+
if not self.aes_key or not self.mac:
|
|
316
|
+
# print('MAC or AES key is null, so logging in!')
|
|
317
|
+
self.login()
|
|
318
|
+
|
|
319
|
+
devices = self.get_raw_devices_data(decrypt_data, decrypt_status)
|
|
320
|
+
with open("devices.json", "w") as f:
|
|
321
|
+
json.dump(devices, f, indent=2)
|
|
322
|
+
|
|
323
|
+
def generate_device_statuses_json(self, decrypt_data: bool, decrypt_status: bool):
|
|
324
|
+
if not self.aes_key or not self.mac:
|
|
325
|
+
# print('MAC or AES key is null, so logging in!')
|
|
326
|
+
self.login()
|
|
327
|
+
self.get_devices()
|
|
328
|
+
|
|
329
|
+
devices = self.get_raw_device_statuses(decrypt_data, decrypt_status)
|
|
330
|
+
with open("statuses.json", "w") as f:
|
|
331
|
+
json.dump(devices, f, indent=2)
|
|
332
|
+
|
|
333
|
+
def get_p1_entity_id(self):
|
|
334
|
+
raw_devices_data = self.get_raw_devices_data(True, False)
|
|
335
|
+
p1_entity = next(
|
|
336
|
+
(
|
|
337
|
+
d
|
|
338
|
+
for d in raw_devices_data
|
|
339
|
+
if d.get("data", {}).get("module", {}).get("name") == "P1 Module"
|
|
340
|
+
),
|
|
341
|
+
None,
|
|
342
|
+
)
|
|
343
|
+
return p1_entity.get("id") if p1_entity else None
|
|
File without changes
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
from typing import Optional
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class DeviceConfig:
|
|
5
|
+
def __init__(
|
|
6
|
+
self,
|
|
7
|
+
model_name: str,
|
|
8
|
+
disabled: Optional[bool] = None,
|
|
9
|
+
on_off_function: Optional[int] = None,
|
|
10
|
+
dim_function: Optional[int] = None,
|
|
11
|
+
color_temperature_function: Optional[int] = None,
|
|
12
|
+
max_brightness: Optional[int] = None,
|
|
13
|
+
max_color_temperature: Optional[int] = None,
|
|
14
|
+
):
|
|
15
|
+
self.disabled = disabled
|
|
16
|
+
self.model_name = model_name
|
|
17
|
+
self.on_off_function = on_off_function
|
|
18
|
+
self.dim_function = dim_function
|
|
19
|
+
self.color_temperature_function = color_temperature_function
|
|
20
|
+
self.max_brightness = max_brightness
|
|
21
|
+
self.max_color_temperature = max_color_temperature
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
from typing import Dict
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class DeviceData:
|
|
5
|
+
def __init__(
|
|
6
|
+
self,
|
|
7
|
+
home_id: str,
|
|
8
|
+
id: str,
|
|
9
|
+
name: str,
|
|
10
|
+
device: int,
|
|
11
|
+
isGroup: bool,
|
|
12
|
+
status: Dict[str, Dict[str, int]],
|
|
13
|
+
data: Dict[str, Dict[str, int]],
|
|
14
|
+
):
|
|
15
|
+
self.home_id = home_id
|
|
16
|
+
self.id = id
|
|
17
|
+
self.name = name
|
|
18
|
+
self.device = device
|
|
19
|
+
self.isGroup = isGroup
|
|
20
|
+
self.status = status
|
|
21
|
+
self.data = data
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
from typing import Union
|
|
2
|
+
from datetime import datetime
|
|
3
|
+
|
|
4
|
+
Precision = str
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class SmartMeterData:
|
|
8
|
+
def __init__(
|
|
9
|
+
self,
|
|
10
|
+
date: Union[datetime, str, int],
|
|
11
|
+
power_consumed_low_tariff: float,
|
|
12
|
+
power_consumed: float,
|
|
13
|
+
power_produced_low_tariff: float,
|
|
14
|
+
power_produced: float,
|
|
15
|
+
gas: float,
|
|
16
|
+
water: float,
|
|
17
|
+
):
|
|
18
|
+
self.date = date
|
|
19
|
+
self.power_consumed_low_tariff = power_consumed_low_tariff
|
|
20
|
+
self.power_consumed = power_consumed
|
|
21
|
+
self.power_produced_low_tariff = power_produced_low_tariff
|
|
22
|
+
self.power_produced = power_produced
|
|
23
|
+
self.gas = gas
|
|
24
|
+
self.water = water
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
from typing import List
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class SmartMeterDataCurrent:
|
|
5
|
+
def __init__(
|
|
6
|
+
self,
|
|
7
|
+
power_consumed_low_tariff: float,
|
|
8
|
+
power_consumed: float,
|
|
9
|
+
power_produced_low_tariff: float,
|
|
10
|
+
power_produced: float,
|
|
11
|
+
current_consumption: float,
|
|
12
|
+
current_production: float,
|
|
13
|
+
gas: float,
|
|
14
|
+
raw_data_array: List[float],
|
|
15
|
+
):
|
|
16
|
+
self.power_consumed_low_tariff = power_consumed_low_tariff
|
|
17
|
+
self.power_consumed = power_consumed
|
|
18
|
+
self.power_produced_low_tariff = power_produced_low_tariff
|
|
19
|
+
self.power_produced = power_produced
|
|
20
|
+
self.current_consumption = current_consumption
|
|
21
|
+
self.current_production = current_production
|
|
22
|
+
self.gas = gas
|
|
23
|
+
self.raw_data_array = raw_data_array
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
[tool.poetry]
|
|
2
|
+
name = "ics_2000_python"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = ""
|
|
5
|
+
authors = ["iiTzArcur <zefanjaj@gmail.com>"]
|
|
6
|
+
readme = "README.md"
|
|
7
|
+
packages = [{include = "ics_2000"}]
|
|
8
|
+
|
|
9
|
+
[tool.poetry.dependencies]
|
|
10
|
+
python = "^3.12"
|
|
11
|
+
requests = "^2.32.3"
|
|
12
|
+
pycryptodome = "^3.21.0"
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
[tool.poetry.group.test.dependencies]
|
|
16
|
+
pytest = "^8.3.3"
|
|
17
|
+
requests-mock = "^1.12.1"
|
|
18
|
+
|
|
19
|
+
[build-system]
|
|
20
|
+
requires = ["poetry-core"]
|
|
21
|
+
build-backend = "poetry.core.masonry.api"
|