pyelectrasmart 1.0.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.
- pyelectrasmart-1.0.0/LICENSE +201 -0
- pyelectrasmart-1.0.0/PKG-INFO +119 -0
- pyelectrasmart-1.0.0/README.md +95 -0
- pyelectrasmart-1.0.0/pyproject.toml +34 -0
- pyelectrasmart-1.0.0/setup.cfg +4 -0
- pyelectrasmart-1.0.0/src/electrasmart/__init__.py +3 -0
- pyelectrasmart-1.0.0/src/electrasmart/api/__init__.py +225 -0
- pyelectrasmart-1.0.0/src/electrasmart/api/const.py +18 -0
- pyelectrasmart-1.0.0/src/electrasmart/api/utils.py +8 -0
- pyelectrasmart-1.0.0/src/electrasmart/device/__init__.py +154 -0
- pyelectrasmart-1.0.0/src/electrasmart/device/const.py +26 -0
- pyelectrasmart-1.0.0/src/electrasmart/py.typed +0 -0
- pyelectrasmart-1.0.0/src/pyelectrasmart.egg-info/PKG-INFO +119 -0
- pyelectrasmart-1.0.0/src/pyelectrasmart.egg-info/SOURCES.txt +16 -0
- pyelectrasmart-1.0.0/src/pyelectrasmart.egg-info/dependency_links.txt +1 -0
- pyelectrasmart-1.0.0/src/pyelectrasmart.egg-info/requires.txt +1 -0
- pyelectrasmart-1.0.0/src/pyelectrasmart.egg-info/top_level.txt +1 -0
- pyelectrasmart-1.0.0/tests/test_electrasmart.py +66 -0
|
@@ -0,0 +1,201 @@
|
|
|
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
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pyelectrasmart
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Python API library for Electra Smart air conditioners (maintained fork of pyElectra).
|
|
5
|
+
Author: Noam Okman
|
|
6
|
+
Author-email: Jafar Atili <at.jafar@outlook.com>
|
|
7
|
+
Maintainer: Noam Okman
|
|
8
|
+
License: Apache-2.0
|
|
9
|
+
Project-URL: homepage, https://github.com/noamokman/pyelectrasmart
|
|
10
|
+
Project-URL: repository, https://github.com/noamokman/pyelectrasmart
|
|
11
|
+
Project-URL: changelog, https://github.com/noamokman/pyelectrasmart/blob/main/CHANGELOG.md
|
|
12
|
+
Keywords: home,automation,Electra,smart,Electra Smart,Air Condition,aiohttp
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Topic :: Home Automation
|
|
16
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
17
|
+
Classifier: Typing :: Typed
|
|
18
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
19
|
+
Requires-Python: >=3.11
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
License-File: LICENSE
|
|
22
|
+
Requires-Dist: aiohttp
|
|
23
|
+
Dynamic: license-file
|
|
24
|
+
|
|
25
|
+
# pyElectraSmart
|
|
26
|
+
|
|
27
|
+
[](https://pypi.org/project/pyelectrasmart)
|
|
28
|
+
[](https://pypi.org/project/pyelectrasmart)
|
|
29
|
+
|
|
30
|
+
A **maintained fork** of [`pyElectra`](https://pypi.org/project/pyelectra/) — a Python
|
|
31
|
+
library to control **Electra Smart** air conditioners.
|
|
32
|
+
|
|
33
|
+
The original `pyElectra` (last release **1.2.4**, July 2024) is unmaintained and its
|
|
34
|
+
pinned release ships a `KeyError: 'deviceToken'` setup crash and a wrong
|
|
35
|
+
current-temperature reading. This fork keeps the same public API and import name
|
|
36
|
+
(`electrasmart`), fixes those bugs, and applies several code-quality corrections so
|
|
37
|
+
projects can pick up the fixes with a one-line dependency bump.
|
|
38
|
+
|
|
39
|
+
## Install
|
|
40
|
+
|
|
41
|
+
```sh
|
|
42
|
+
pip install pyelectrasmart
|
|
43
|
+
# or, if you use uv:
|
|
44
|
+
uv add pyelectrasmart
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
> Drop-in replacement: swap `pyElectra==1.2.4` → `pyelectrasmart==1.0.0`. The import
|
|
48
|
+
> name stays `electrasmart`, so no source changes are needed.
|
|
49
|
+
|
|
50
|
+
## Usage
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
import asyncio
|
|
54
|
+
|
|
55
|
+
import aiohttp
|
|
56
|
+
|
|
57
|
+
from electrasmart import ElectraAPI, ElectraApiError
|
|
58
|
+
from electrasmart.api.utils import generate_imei
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
async def main():
|
|
62
|
+
session = aiohttp.ClientSession(
|
|
63
|
+
connector=aiohttp.TCPConnector(ssl=False),
|
|
64
|
+
timeout=aiohttp.ClientTimeout(total=10),
|
|
65
|
+
)
|
|
66
|
+
api = ElectraAPI(session)
|
|
67
|
+
|
|
68
|
+
# 1. Register your phone number
|
|
69
|
+
imei = generate_imei()
|
|
70
|
+
resp = await api.generate_new_token(phone_number="0521234567", imei=imei)
|
|
71
|
+
print(resp)
|
|
72
|
+
|
|
73
|
+
# 2. Confirm the OTP you received by SMS
|
|
74
|
+
resp = await api.validate_one_time_password(
|
|
75
|
+
otp="123456", imei=imei, phone_number="0521234567"
|
|
76
|
+
)
|
|
77
|
+
token = resp["data"]["token"]
|
|
78
|
+
|
|
79
|
+
# 3. Connect with the token and enumerate devices
|
|
80
|
+
api = ElectraAPI(session, imei=imei, token=token)
|
|
81
|
+
await api.fetch_devices()
|
|
82
|
+
for ac in api.devices:
|
|
83
|
+
print(ac.name, ac.get_temperature(), ac.get_sensor_temperature())
|
|
84
|
+
|
|
85
|
+
await session.close()
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
asyncio.run(main())
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Changes vs. upstream `pyElectra` 1.2.4
|
|
92
|
+
|
|
93
|
+
- **Fix: `KeyError: 'deviceToken'` crash** — the token field is not present in every
|
|
94
|
+
device record; it is now read tolerantly (`data.get("deviceToken", "")`).
|
|
95
|
+
- **Fix: current-temperature miscalculation** — `I_RAT` / `I_CALC_AT` telemetry is a
|
|
96
|
+
×256 left-shifted integer (raw `5632` == `22` °C); it is now normalized back to
|
|
97
|
+
Celsius inside the library.
|
|
98
|
+
- **Fix: correct API error messages** — exception messages are now formatted as `f`
|
|
99
|
+
strings instead of leaving `%s` unsubstituted, and `Recieved` → `Received`.
|
|
100
|
+
- **Fix: don't leak the session ID into logs** — the `SID`, which authorizes cloud
|
|
101
|
+
requests, is no longer logged.
|
|
102
|
+
- **Fix: don't log full device records** — `GET_DEVICES` payloads may contain
|
|
103
|
+
`deviceToken` and device identifiers; only the device type is logged.
|
|
104
|
+
- **Fix: structured concurrency in `fetch_devices()`** — telemetry requests run in an
|
|
105
|
+
`asyncio.TaskGroup` so a failing task can't leave siblings orphaned, and the
|
|
106
|
+
underlying `ElectraApiError` is preserved for callers.
|
|
107
|
+
- Requires Python **>= 3.11** (for `asyncio.TaskGroup` / `ExceptionGroup`).
|
|
108
|
+
|
|
109
|
+
## Development
|
|
110
|
+
|
|
111
|
+
```sh
|
|
112
|
+
uv sync
|
|
113
|
+
uv run pytest
|
|
114
|
+
uv build
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## License
|
|
118
|
+
|
|
119
|
+
Apache-2.0 — the same as the upstream `pyElectra` project. Original author: Jafar Atili.
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# pyElectraSmart
|
|
2
|
+
|
|
3
|
+
[](https://pypi.org/project/pyelectrasmart)
|
|
4
|
+
[](https://pypi.org/project/pyelectrasmart)
|
|
5
|
+
|
|
6
|
+
A **maintained fork** of [`pyElectra`](https://pypi.org/project/pyelectra/) — a Python
|
|
7
|
+
library to control **Electra Smart** air conditioners.
|
|
8
|
+
|
|
9
|
+
The original `pyElectra` (last release **1.2.4**, July 2024) is unmaintained and its
|
|
10
|
+
pinned release ships a `KeyError: 'deviceToken'` setup crash and a wrong
|
|
11
|
+
current-temperature reading. This fork keeps the same public API and import name
|
|
12
|
+
(`electrasmart`), fixes those bugs, and applies several code-quality corrections so
|
|
13
|
+
projects can pick up the fixes with a one-line dependency bump.
|
|
14
|
+
|
|
15
|
+
## Install
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
pip install pyelectrasmart
|
|
19
|
+
# or, if you use uv:
|
|
20
|
+
uv add pyelectrasmart
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
> Drop-in replacement: swap `pyElectra==1.2.4` → `pyelectrasmart==1.0.0`. The import
|
|
24
|
+
> name stays `electrasmart`, so no source changes are needed.
|
|
25
|
+
|
|
26
|
+
## Usage
|
|
27
|
+
|
|
28
|
+
```python
|
|
29
|
+
import asyncio
|
|
30
|
+
|
|
31
|
+
import aiohttp
|
|
32
|
+
|
|
33
|
+
from electrasmart import ElectraAPI, ElectraApiError
|
|
34
|
+
from electrasmart.api.utils import generate_imei
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
async def main():
|
|
38
|
+
session = aiohttp.ClientSession(
|
|
39
|
+
connector=aiohttp.TCPConnector(ssl=False),
|
|
40
|
+
timeout=aiohttp.ClientTimeout(total=10),
|
|
41
|
+
)
|
|
42
|
+
api = ElectraAPI(session)
|
|
43
|
+
|
|
44
|
+
# 1. Register your phone number
|
|
45
|
+
imei = generate_imei()
|
|
46
|
+
resp = await api.generate_new_token(phone_number="0521234567", imei=imei)
|
|
47
|
+
print(resp)
|
|
48
|
+
|
|
49
|
+
# 2. Confirm the OTP you received by SMS
|
|
50
|
+
resp = await api.validate_one_time_password(
|
|
51
|
+
otp="123456", imei=imei, phone_number="0521234567"
|
|
52
|
+
)
|
|
53
|
+
token = resp["data"]["token"]
|
|
54
|
+
|
|
55
|
+
# 3. Connect with the token and enumerate devices
|
|
56
|
+
api = ElectraAPI(session, imei=imei, token=token)
|
|
57
|
+
await api.fetch_devices()
|
|
58
|
+
for ac in api.devices:
|
|
59
|
+
print(ac.name, ac.get_temperature(), ac.get_sensor_temperature())
|
|
60
|
+
|
|
61
|
+
await session.close()
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
asyncio.run(main())
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Changes vs. upstream `pyElectra` 1.2.4
|
|
68
|
+
|
|
69
|
+
- **Fix: `KeyError: 'deviceToken'` crash** — the token field is not present in every
|
|
70
|
+
device record; it is now read tolerantly (`data.get("deviceToken", "")`).
|
|
71
|
+
- **Fix: current-temperature miscalculation** — `I_RAT` / `I_CALC_AT` telemetry is a
|
|
72
|
+
×256 left-shifted integer (raw `5632` == `22` °C); it is now normalized back to
|
|
73
|
+
Celsius inside the library.
|
|
74
|
+
- **Fix: correct API error messages** — exception messages are now formatted as `f`
|
|
75
|
+
strings instead of leaving `%s` unsubstituted, and `Recieved` → `Received`.
|
|
76
|
+
- **Fix: don't leak the session ID into logs** — the `SID`, which authorizes cloud
|
|
77
|
+
requests, is no longer logged.
|
|
78
|
+
- **Fix: don't log full device records** — `GET_DEVICES` payloads may contain
|
|
79
|
+
`deviceToken` and device identifiers; only the device type is logged.
|
|
80
|
+
- **Fix: structured concurrency in `fetch_devices()`** — telemetry requests run in an
|
|
81
|
+
`asyncio.TaskGroup` so a failing task can't leave siblings orphaned, and the
|
|
82
|
+
underlying `ElectraApiError` is preserved for callers.
|
|
83
|
+
- Requires Python **>= 3.11** (for `asyncio.TaskGroup` / `ExceptionGroup`).
|
|
84
|
+
|
|
85
|
+
## Development
|
|
86
|
+
|
|
87
|
+
```sh
|
|
88
|
+
uv sync
|
|
89
|
+
uv run pytest
|
|
90
|
+
uv build
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## License
|
|
94
|
+
|
|
95
|
+
Apache-2.0 — the same as the upstream `pyElectra` project. Original author: Jafar Atili.
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0.0", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "pyelectrasmart"
|
|
7
|
+
version = "1.0.0"
|
|
8
|
+
description = "Python API library for Electra Smart air conditioners (maintained fork of pyElectra)."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
authors = [
|
|
11
|
+
{ name = "Noam Okman" },
|
|
12
|
+
{ name = "Jafar Atili", email = "at.jafar@outlook.com" },
|
|
13
|
+
]
|
|
14
|
+
maintainers = [{ name = "Noam Okman" }]
|
|
15
|
+
license = { text = "Apache-2.0" }
|
|
16
|
+
keywords = [ "home", "automation", "Electra", "smart", "Electra Smart", "Air Condition", "aiohttp" ]
|
|
17
|
+
classifiers = [
|
|
18
|
+
"Intended Audience :: Developers",
|
|
19
|
+
"Operating System :: OS Independent",
|
|
20
|
+
"Topic :: Home Automation",
|
|
21
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
22
|
+
"Typing :: Typed",
|
|
23
|
+
"License :: OSI Approved :: Apache Software License",
|
|
24
|
+
]
|
|
25
|
+
dependencies = ["aiohttp"]
|
|
26
|
+
requires-python = ">=3.11"
|
|
27
|
+
|
|
28
|
+
[project.urls]
|
|
29
|
+
homepage = "https://github.com/noamokman/pyelectrasmart"
|
|
30
|
+
repository = "https://github.com/noamokman/pyelectrasmart"
|
|
31
|
+
changelog = "https://github.com/noamokman/pyelectrasmart/blob/main/CHANGELOG.md"
|
|
32
|
+
|
|
33
|
+
[tool.setuptools.packages.find]
|
|
34
|
+
where = ["src"]
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import builtins
|
|
4
|
+
from asyncio import TaskGroup, TimeoutError
|
|
5
|
+
from datetime import datetime
|
|
6
|
+
from json import JSONDecodeError
|
|
7
|
+
from logging import getLogger
|
|
8
|
+
from typing import Any, List
|
|
9
|
+
|
|
10
|
+
from aiohttp import ClientError, ClientSession
|
|
11
|
+
|
|
12
|
+
from electrasmart.device import ElectraAirConditioner
|
|
13
|
+
|
|
14
|
+
from .const import (
|
|
15
|
+
DELAY_BETWEEM_SID_REQUESTS,
|
|
16
|
+
SID_EXPIRATION,
|
|
17
|
+
STATUS_SUCCESS,
|
|
18
|
+
Attributes,
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
logger = getLogger(__name__)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class ElectraApiError(Exception):
|
|
25
|
+
pass
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class ElectraAPI:
|
|
29
|
+
def __init__(
|
|
30
|
+
self,
|
|
31
|
+
websession: ClientSession,
|
|
32
|
+
imei: str | None = None,
|
|
33
|
+
token: str | None = None,
|
|
34
|
+
) -> None:
|
|
35
|
+
self._base_url = "https://app.ecpiot.co.il/mobile/mobilecommand"
|
|
36
|
+
self._sid = None
|
|
37
|
+
self._imei = imei
|
|
38
|
+
self._token = token
|
|
39
|
+
self._sid_expiration = 0
|
|
40
|
+
self._last_sid_request_ts = 0
|
|
41
|
+
self._session = websession
|
|
42
|
+
self._phone_number = None
|
|
43
|
+
self._devices: list[ElectraAirConditioner] = []
|
|
44
|
+
|
|
45
|
+
logger.debug("Initialized Electra API object")
|
|
46
|
+
|
|
47
|
+
@property
|
|
48
|
+
def devices(self) -> list[ElectraAirConditioner]:
|
|
49
|
+
return self._devices
|
|
50
|
+
|
|
51
|
+
async def _send_request(self, payload: dict[str, Any]) -> dict[str, Any]:
|
|
52
|
+
try:
|
|
53
|
+
resp = await self._session.post(
|
|
54
|
+
url=self._base_url,
|
|
55
|
+
json=payload,
|
|
56
|
+
headers={"user-agent": "Electra Client"},
|
|
57
|
+
)
|
|
58
|
+
json_resp: dict[str, Any] = await resp.json(content_type=None)
|
|
59
|
+
except builtins.TimeoutError as ex:
|
|
60
|
+
raise ElectraApiError(
|
|
61
|
+
f"Failed to communicate with Electra API due to time out: ({ex!s})"
|
|
62
|
+
)
|
|
63
|
+
except ClientError as ex:
|
|
64
|
+
raise ElectraApiError(
|
|
65
|
+
f"Failed to communicate with Electra API due to ClientError: ({ex!s})"
|
|
66
|
+
)
|
|
67
|
+
except JSONDecodeError as ex:
|
|
68
|
+
raise ElectraApiError(f"Received invalid response from Electra API: {ex!s}")
|
|
69
|
+
|
|
70
|
+
return json_resp
|
|
71
|
+
|
|
72
|
+
async def generate_new_token(self, phone_number: str, imei: str) -> dict[str, Any]:
|
|
73
|
+
payload = {
|
|
74
|
+
"pvdid": 1,
|
|
75
|
+
"id": 99,
|
|
76
|
+
"cmd": "SEND_OTP",
|
|
77
|
+
"data": {"imei": imei, "phone": phone_number},
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return await self._send_request(payload=payload)
|
|
81
|
+
|
|
82
|
+
async def validate_one_time_password(
|
|
83
|
+
self, otp: str, imei: str, phone_number: str
|
|
84
|
+
) -> dict[str, Any]:
|
|
85
|
+
payload = {
|
|
86
|
+
"pvdid": 1,
|
|
87
|
+
"id": 99,
|
|
88
|
+
"cmd": "CHECK_OTP",
|
|
89
|
+
"data": {
|
|
90
|
+
"imei": imei,
|
|
91
|
+
"phone": phone_number,
|
|
92
|
+
"code": otp,
|
|
93
|
+
"os": "android",
|
|
94
|
+
"osver": "M4B30Z",
|
|
95
|
+
},
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return await self._send_request(payload=payload)
|
|
99
|
+
|
|
100
|
+
def _sid_expired(self) -> bool:
|
|
101
|
+
current_time = int(datetime.now().timestamp())
|
|
102
|
+
refresh_in = self._sid_expiration - current_time
|
|
103
|
+
if refresh_in > 0:
|
|
104
|
+
logger.debug("Should refresh in %s minutes", round(refresh_in / 60))
|
|
105
|
+
|
|
106
|
+
if current_time < self._sid_expiration:
|
|
107
|
+
return False
|
|
108
|
+
else:
|
|
109
|
+
self._sid = None
|
|
110
|
+
return True
|
|
111
|
+
|
|
112
|
+
async def _get_sid(self, force: bool = False) -> None:
|
|
113
|
+
current_ts = int(datetime.now().timestamp())
|
|
114
|
+
if not force and not self._sid_expired():
|
|
115
|
+
logger.debug("Found valid sid in cache, using it")
|
|
116
|
+
return
|
|
117
|
+
|
|
118
|
+
if self._last_sid_request_ts and current_ts < (
|
|
119
|
+
self._last_sid_request_ts + DELAY_BETWEEM_SID_REQUESTS
|
|
120
|
+
):
|
|
121
|
+
logger.debug(
|
|
122
|
+
'Session ID was requested less than 5 minutes ago! waiting in order to prevent "intruder lockdown"...'
|
|
123
|
+
)
|
|
124
|
+
return
|
|
125
|
+
|
|
126
|
+
payload = {
|
|
127
|
+
"pvdid": 1,
|
|
128
|
+
"id": 99,
|
|
129
|
+
"cmd": "VALIDATE_TOKEN",
|
|
130
|
+
"data": {
|
|
131
|
+
"imei": self._imei,
|
|
132
|
+
"token": self._token,
|
|
133
|
+
"os": "android",
|
|
134
|
+
"osver": "M4B30Z",
|
|
135
|
+
},
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
resp = await self._send_request(payload=payload)
|
|
139
|
+
|
|
140
|
+
if resp is None:
|
|
141
|
+
raise ElectraApiError("Failed to retrieve sid")
|
|
142
|
+
else:
|
|
143
|
+
if not resp[Attributes.DATA][Attributes.SID]:
|
|
144
|
+
raise ElectraApiError(
|
|
145
|
+
f"Failed to retrieve SID due to {resp[Attributes.DATA][Attributes.DESC]}"
|
|
146
|
+
)
|
|
147
|
+
|
|
148
|
+
else:
|
|
149
|
+
self._sid = resp[Attributes.DATA][Attributes.SID]
|
|
150
|
+
self._sid_expiration = current_ts + SID_EXPIRATION
|
|
151
|
+
self._last_sid_request_ts = current_ts
|
|
152
|
+
logger.debug("Successfully acquired session id")
|
|
153
|
+
|
|
154
|
+
async def fetch_devices(self) -> None:
|
|
155
|
+
logger.debug("About to Get Electra AC devices")
|
|
156
|
+
await self._get_sid()
|
|
157
|
+
|
|
158
|
+
payload = {"pvdid": 1, "id": 99, "cmd": "GET_DEVICES", "sid": self._sid}
|
|
159
|
+
|
|
160
|
+
ac_list: list[ElectraAirConditioner] = []
|
|
161
|
+
resp = await self._send_request(payload=payload)
|
|
162
|
+
if resp[Attributes.STATUS] == STATUS_SUCCESS:
|
|
163
|
+
for ac in resp[Attributes.DATA][Attributes.DEVICES]:
|
|
164
|
+
if ac["deviceTypeName"] == "A/C":
|
|
165
|
+
electra_ac: ElectraAirConditioner = ElectraAirConditioner(ac)
|
|
166
|
+
logger.debug("Discovered A/C device %s", electra_ac.name)
|
|
167
|
+
ac_list.append(electra_ac)
|
|
168
|
+
else:
|
|
169
|
+
logger.debug(
|
|
170
|
+
"Discovered non-AC device of type %s",
|
|
171
|
+
ac.get("deviceTypeName"),
|
|
172
|
+
)
|
|
173
|
+
|
|
174
|
+
try:
|
|
175
|
+
async with TaskGroup() as tg:
|
|
176
|
+
for ac in ac_list:
|
|
177
|
+
tg.create_task(self.get_last_telemtry(ac))
|
|
178
|
+
except ExceptionGroup as exg:
|
|
179
|
+
# TaskGroup wraps task failures in an ExceptionGroup; surface
|
|
180
|
+
# the underlying API error so callers can catch ElectraApiError.
|
|
181
|
+
for exc in exg.exceptions:
|
|
182
|
+
if isinstance(exc, ElectraApiError):
|
|
183
|
+
raise exc from exg
|
|
184
|
+
raise
|
|
185
|
+
|
|
186
|
+
for ac in ac_list:
|
|
187
|
+
ac.update_features()
|
|
188
|
+
|
|
189
|
+
self._devices = ac_list
|
|
190
|
+
|
|
191
|
+
else:
|
|
192
|
+
raise ElectraApiError(f"Failed to fetch devices {resp}")
|
|
193
|
+
|
|
194
|
+
async def get_last_telemtry(self, ac: ElectraAirConditioner) -> None:
|
|
195
|
+
logger.debug("Getting AC %s state", ac.name)
|
|
196
|
+
|
|
197
|
+
await self._get_sid()
|
|
198
|
+
|
|
199
|
+
payload = {
|
|
200
|
+
"pvdid": 1,
|
|
201
|
+
"id": 99,
|
|
202
|
+
"cmd": "GET_LAST_TELEMETRY",
|
|
203
|
+
"sid": self._sid,
|
|
204
|
+
"data": {"id": ac.id, "commandName": "OPER,DIAG_L2"},
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
resp = await self._send_request(payload=payload)
|
|
208
|
+
if resp[Attributes.STATUS] != STATUS_SUCCESS:
|
|
209
|
+
raise ElectraApiError(f"Failed to get AC operation state: {resp}")
|
|
210
|
+
else:
|
|
211
|
+
ac.update_operation_states(resp[Attributes.DATA])
|
|
212
|
+
|
|
213
|
+
async def set_state(self, device: ElectraAirConditioner) -> dict[str, Any]:
|
|
214
|
+
json_command = device.get_operation_state()
|
|
215
|
+
await self._get_sid()
|
|
216
|
+
|
|
217
|
+
payload = {
|
|
218
|
+
"pvdid": 1,
|
|
219
|
+
"id": 99,
|
|
220
|
+
"cmd": "SEND_COMMAND",
|
|
221
|
+
"sid": self._sid,
|
|
222
|
+
"data": {"id": device.id, "commandJson": json_command},
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
return await self._send_request(payload=payload)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from dataclasses import dataclass
|
|
2
|
+
from datetime import timedelta
|
|
3
|
+
|
|
4
|
+
STATUS_SUCCESS = 0
|
|
5
|
+
DELAY_BETWEEM_SID_REQUESTS = int(timedelta(minutes=5).total_seconds())
|
|
6
|
+
SID_EXPIRATION = int(timedelta(minutes=15).total_seconds())
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
@dataclass
|
|
10
|
+
class Attributes:
|
|
11
|
+
INTRUDER_LOCKOUT = "Intruder lockout"
|
|
12
|
+
DESC = "res_desc"
|
|
13
|
+
DATA = "data"
|
|
14
|
+
TOKEN = "token"
|
|
15
|
+
SID = "sid"
|
|
16
|
+
RES = "res"
|
|
17
|
+
STATUS = "status"
|
|
18
|
+
DEVICES = "devices"
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
from typing import Any
|
|
5
|
+
|
|
6
|
+
from .const import Feature, OperationMode
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class ElectraAirConditioner:
|
|
10
|
+
def __init__(self, data: dict[str, str]) -> None:
|
|
11
|
+
self.id: str = data["id"]
|
|
12
|
+
self.name: str = data["name"]
|
|
13
|
+
self.regdate: str = data["regdate"]
|
|
14
|
+
self.model = data["model"]
|
|
15
|
+
self.mac: str = data["mac"]
|
|
16
|
+
self.serial_number: str = data["sn"]
|
|
17
|
+
self.manufactor: str = data["manufactor"]
|
|
18
|
+
self.type: str = data["deviceTypeName"]
|
|
19
|
+
self.status: str = data["status"]
|
|
20
|
+
# ``deviceToken`` is not always present in the device record (some units
|
|
21
|
+
# omit it), so tolerate a missing field instead of crashing on lookup.
|
|
22
|
+
self.token: str = data.get("deviceToken", "")
|
|
23
|
+
self._time_delta: int = 0
|
|
24
|
+
self.features: list[int] = []
|
|
25
|
+
|
|
26
|
+
self.current_mode: str | None = None
|
|
27
|
+
self.collected_measure: int | None = None
|
|
28
|
+
self._oper_data: dict[str, str] = {}
|
|
29
|
+
|
|
30
|
+
def is_disconnected(self, thresh_sec: int = 60) -> bool:
|
|
31
|
+
return self._time_delta > thresh_sec
|
|
32
|
+
|
|
33
|
+
def update_features(self) -> None:
|
|
34
|
+
if "VSWING" in self._oper_data:
|
|
35
|
+
self.features.append(Feature.V_SWING)
|
|
36
|
+
if "HSWING" in self._oper_data:
|
|
37
|
+
self.features.append(Feature.H_SWING)
|
|
38
|
+
|
|
39
|
+
def get_sensor_temperature(self) -> int | None:
|
|
40
|
+
return self.collected_measure
|
|
41
|
+
|
|
42
|
+
def get_mode(self) -> str:
|
|
43
|
+
return self._oper_data["AC_MODE"]
|
|
44
|
+
|
|
45
|
+
def set_mode(self, mode: str) -> None:
|
|
46
|
+
if (
|
|
47
|
+
mode
|
|
48
|
+
in [
|
|
49
|
+
OperationMode.MODE_AUTO,
|
|
50
|
+
OperationMode.MODE_COOL,
|
|
51
|
+
OperationMode.MODE_DRY,
|
|
52
|
+
OperationMode.MODE_FAN,
|
|
53
|
+
OperationMode.MODE_HEAT,
|
|
54
|
+
]
|
|
55
|
+
and mode != self._oper_data["AC_MODE"]
|
|
56
|
+
):
|
|
57
|
+
self._oper_data["AC_MODE"] = mode
|
|
58
|
+
|
|
59
|
+
def set_horizontal_swing(self, enable: bool) -> None:
|
|
60
|
+
if "HSWING" in self._oper_data:
|
|
61
|
+
self._oper_data["HSWING"] = (
|
|
62
|
+
OperationMode.ON if enable else OperationMode.OFF
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
def set_vertical_swing(self, enable: bool) -> None:
|
|
66
|
+
if "VSWING" in self._oper_data:
|
|
67
|
+
self._oper_data["VSWING"] = (
|
|
68
|
+
OperationMode.ON if enable else OperationMode.OFF
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
def is_vertical_swing(self) -> bool:
|
|
72
|
+
if "VSWING" in self._oper_data:
|
|
73
|
+
return self._oper_data["VSWING"] == OperationMode.ON
|
|
74
|
+
return False
|
|
75
|
+
|
|
76
|
+
def is_horizontal_swing(self) -> bool:
|
|
77
|
+
if "HSWING" in self._oper_data:
|
|
78
|
+
return self._oper_data["HSWING"] == OperationMode.ON
|
|
79
|
+
return False
|
|
80
|
+
|
|
81
|
+
def is_on(self) -> bool:
|
|
82
|
+
if "TURN_ON_OFF" in self._oper_data:
|
|
83
|
+
return self._oper_data["TURN_ON_OFF"] == OperationMode.ON
|
|
84
|
+
else:
|
|
85
|
+
return self._oper_data["AC_MODE"] != OperationMode.STANDBY
|
|
86
|
+
|
|
87
|
+
def turn_on(self) -> None:
|
|
88
|
+
if not self.is_on() and "TURN_ON_OFF" in self._oper_data:
|
|
89
|
+
self._oper_data["TURN_ON_OFF"] = OperationMode.ON
|
|
90
|
+
|
|
91
|
+
def turn_off(self) -> None:
|
|
92
|
+
if self.is_on():
|
|
93
|
+
if "TURN_ON_OFF" in self._oper_data:
|
|
94
|
+
self._oper_data["TURN_ON_OFF"] = OperationMode.OFF
|
|
95
|
+
else:
|
|
96
|
+
self._oper_data["AC_MODE"] = OperationMode.STANDBY
|
|
97
|
+
|
|
98
|
+
def get_temperature(self) -> int:
|
|
99
|
+
return int(self._oper_data["SPT"])
|
|
100
|
+
|
|
101
|
+
def set_temperature(self, val: int) -> None:
|
|
102
|
+
if self.get_temperature() != val:
|
|
103
|
+
self._oper_data["SPT"] = str(val)
|
|
104
|
+
|
|
105
|
+
def get_fan_speed(self) -> str:
|
|
106
|
+
return self._oper_data["FANSPD"]
|
|
107
|
+
|
|
108
|
+
def set_fan_speed(self, speed: str) -> None:
|
|
109
|
+
if (
|
|
110
|
+
speed
|
|
111
|
+
in [
|
|
112
|
+
OperationMode.FAN_SPEED_AUTO,
|
|
113
|
+
OperationMode.FAN_SPEED_HIGH,
|
|
114
|
+
OperationMode.FAN_SPEED_MED,
|
|
115
|
+
OperationMode.FAN_SPEED_LOW,
|
|
116
|
+
]
|
|
117
|
+
and speed != self._oper_data["FANSPD"]
|
|
118
|
+
):
|
|
119
|
+
self._oper_data["FANSPD"] = speed
|
|
120
|
+
|
|
121
|
+
def set_turbo_mode(self, enable: bool) -> None:
|
|
122
|
+
self._oper_data["TURBO"] = OperationMode.ON if enable else OperationMode.OFF
|
|
123
|
+
|
|
124
|
+
def get_turbo_mode(self) -> bool:
|
|
125
|
+
return self._oper_data["TURBO"] == OperationMode.ON
|
|
126
|
+
|
|
127
|
+
def set_shabat_mode(self, enable: bool) -> None:
|
|
128
|
+
self._oper_data["SHABAT"] = OperationMode.ON if enable else OperationMode.OFF
|
|
129
|
+
|
|
130
|
+
def get_shabat_mode(self) -> bool:
|
|
131
|
+
return self._oper_data["SHABAT"] == OperationMode.ON
|
|
132
|
+
|
|
133
|
+
def update_operation_states(self, data: dict[str, Any]) -> None:
|
|
134
|
+
self._oper_data = json.loads(data["commandJson"]["OPER"])["OPER"]
|
|
135
|
+
self._time_delta = data["timeDelta"]
|
|
136
|
+
measurments = json.loads(data["commandJson"]["DIAG_L2"])["DIAG_L2"]
|
|
137
|
+
# ``I_RAT``/``I_CALC_AT`` are reported as a ×256 left-shifted integer
|
|
138
|
+
# (e.g. raw 5632 == 22 °C). Normalize back to Celsius when the raw value
|
|
139
|
+
# is implausible for a room temperature; some units already return the
|
|
140
|
+
# normalized value, so only shift above the 100 °C threshold.
|
|
141
|
+
if "I_RAT" in measurments:
|
|
142
|
+
raw_temp = int(measurments["I_RAT"])
|
|
143
|
+
self.collected_measure = raw_temp >> 8 if raw_temp > 100 else raw_temp
|
|
144
|
+
if "I_CALC_AT" in measurments:
|
|
145
|
+
raw_temp = int(measurments["I_CALC_AT"])
|
|
146
|
+
self.collected_measure = raw_temp >> 8 if raw_temp > 100 else raw_temp
|
|
147
|
+
|
|
148
|
+
self.current_mode = measurments["O_ODU_MODE"]
|
|
149
|
+
|
|
150
|
+
def get_operation_state(self) -> str:
|
|
151
|
+
if "AC_STSRC" in self._oper_data:
|
|
152
|
+
self._oper_data["AC_STSRC"] = "WI-FI"
|
|
153
|
+
|
|
154
|
+
return json.dumps({"OPER": self._oper_data})
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
from dataclasses import dataclass
|
|
2
|
+
|
|
3
|
+
MAX_TEMP = 30
|
|
4
|
+
MIN_TEMP = 17
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
@dataclass
|
|
8
|
+
class OperationMode:
|
|
9
|
+
MODE_COOL = "COOL"
|
|
10
|
+
MODE_HEAT = "HEAT"
|
|
11
|
+
MODE_AUTO = "AUTO"
|
|
12
|
+
MODE_DRY = "DRY"
|
|
13
|
+
MODE_FAN = "FAN"
|
|
14
|
+
FAN_SPEED_LOW = "LOW"
|
|
15
|
+
FAN_SPEED_MED = "MED"
|
|
16
|
+
FAN_SPEED_HIGH = "HIGH"
|
|
17
|
+
FAN_SPEED_AUTO = "AUTO"
|
|
18
|
+
ON = "ON"
|
|
19
|
+
OFF = "OFF"
|
|
20
|
+
STANDBY = "STBY"
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
@dataclass
|
|
24
|
+
class Feature:
|
|
25
|
+
V_SWING = 0
|
|
26
|
+
H_SWING = 1
|
|
File without changes
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pyelectrasmart
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Python API library for Electra Smart air conditioners (maintained fork of pyElectra).
|
|
5
|
+
Author: Noam Okman
|
|
6
|
+
Author-email: Jafar Atili <at.jafar@outlook.com>
|
|
7
|
+
Maintainer: Noam Okman
|
|
8
|
+
License: Apache-2.0
|
|
9
|
+
Project-URL: homepage, https://github.com/noamokman/pyelectrasmart
|
|
10
|
+
Project-URL: repository, https://github.com/noamokman/pyelectrasmart
|
|
11
|
+
Project-URL: changelog, https://github.com/noamokman/pyelectrasmart/blob/main/CHANGELOG.md
|
|
12
|
+
Keywords: home,automation,Electra,smart,Electra Smart,Air Condition,aiohttp
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Topic :: Home Automation
|
|
16
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
17
|
+
Classifier: Typing :: Typed
|
|
18
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
19
|
+
Requires-Python: >=3.11
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
License-File: LICENSE
|
|
22
|
+
Requires-Dist: aiohttp
|
|
23
|
+
Dynamic: license-file
|
|
24
|
+
|
|
25
|
+
# pyElectraSmart
|
|
26
|
+
|
|
27
|
+
[](https://pypi.org/project/pyelectrasmart)
|
|
28
|
+
[](https://pypi.org/project/pyelectrasmart)
|
|
29
|
+
|
|
30
|
+
A **maintained fork** of [`pyElectra`](https://pypi.org/project/pyelectra/) — a Python
|
|
31
|
+
library to control **Electra Smart** air conditioners.
|
|
32
|
+
|
|
33
|
+
The original `pyElectra` (last release **1.2.4**, July 2024) is unmaintained and its
|
|
34
|
+
pinned release ships a `KeyError: 'deviceToken'` setup crash and a wrong
|
|
35
|
+
current-temperature reading. This fork keeps the same public API and import name
|
|
36
|
+
(`electrasmart`), fixes those bugs, and applies several code-quality corrections so
|
|
37
|
+
projects can pick up the fixes with a one-line dependency bump.
|
|
38
|
+
|
|
39
|
+
## Install
|
|
40
|
+
|
|
41
|
+
```sh
|
|
42
|
+
pip install pyelectrasmart
|
|
43
|
+
# or, if you use uv:
|
|
44
|
+
uv add pyelectrasmart
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
> Drop-in replacement: swap `pyElectra==1.2.4` → `pyelectrasmart==1.0.0`. The import
|
|
48
|
+
> name stays `electrasmart`, so no source changes are needed.
|
|
49
|
+
|
|
50
|
+
## Usage
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
import asyncio
|
|
54
|
+
|
|
55
|
+
import aiohttp
|
|
56
|
+
|
|
57
|
+
from electrasmart import ElectraAPI, ElectraApiError
|
|
58
|
+
from electrasmart.api.utils import generate_imei
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
async def main():
|
|
62
|
+
session = aiohttp.ClientSession(
|
|
63
|
+
connector=aiohttp.TCPConnector(ssl=False),
|
|
64
|
+
timeout=aiohttp.ClientTimeout(total=10),
|
|
65
|
+
)
|
|
66
|
+
api = ElectraAPI(session)
|
|
67
|
+
|
|
68
|
+
# 1. Register your phone number
|
|
69
|
+
imei = generate_imei()
|
|
70
|
+
resp = await api.generate_new_token(phone_number="0521234567", imei=imei)
|
|
71
|
+
print(resp)
|
|
72
|
+
|
|
73
|
+
# 2. Confirm the OTP you received by SMS
|
|
74
|
+
resp = await api.validate_one_time_password(
|
|
75
|
+
otp="123456", imei=imei, phone_number="0521234567"
|
|
76
|
+
)
|
|
77
|
+
token = resp["data"]["token"]
|
|
78
|
+
|
|
79
|
+
# 3. Connect with the token and enumerate devices
|
|
80
|
+
api = ElectraAPI(session, imei=imei, token=token)
|
|
81
|
+
await api.fetch_devices()
|
|
82
|
+
for ac in api.devices:
|
|
83
|
+
print(ac.name, ac.get_temperature(), ac.get_sensor_temperature())
|
|
84
|
+
|
|
85
|
+
await session.close()
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
asyncio.run(main())
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Changes vs. upstream `pyElectra` 1.2.4
|
|
92
|
+
|
|
93
|
+
- **Fix: `KeyError: 'deviceToken'` crash** — the token field is not present in every
|
|
94
|
+
device record; it is now read tolerantly (`data.get("deviceToken", "")`).
|
|
95
|
+
- **Fix: current-temperature miscalculation** — `I_RAT` / `I_CALC_AT` telemetry is a
|
|
96
|
+
×256 left-shifted integer (raw `5632` == `22` °C); it is now normalized back to
|
|
97
|
+
Celsius inside the library.
|
|
98
|
+
- **Fix: correct API error messages** — exception messages are now formatted as `f`
|
|
99
|
+
strings instead of leaving `%s` unsubstituted, and `Recieved` → `Received`.
|
|
100
|
+
- **Fix: don't leak the session ID into logs** — the `SID`, which authorizes cloud
|
|
101
|
+
requests, is no longer logged.
|
|
102
|
+
- **Fix: don't log full device records** — `GET_DEVICES` payloads may contain
|
|
103
|
+
`deviceToken` and device identifiers; only the device type is logged.
|
|
104
|
+
- **Fix: structured concurrency in `fetch_devices()`** — telemetry requests run in an
|
|
105
|
+
`asyncio.TaskGroup` so a failing task can't leave siblings orphaned, and the
|
|
106
|
+
underlying `ElectraApiError` is preserved for callers.
|
|
107
|
+
- Requires Python **>= 3.11** (for `asyncio.TaskGroup` / `ExceptionGroup`).
|
|
108
|
+
|
|
109
|
+
## Development
|
|
110
|
+
|
|
111
|
+
```sh
|
|
112
|
+
uv sync
|
|
113
|
+
uv run pytest
|
|
114
|
+
uv build
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## License
|
|
118
|
+
|
|
119
|
+
Apache-2.0 — the same as the upstream `pyElectra` project. Original author: Jafar Atili.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
src/electrasmart/__init__.py
|
|
5
|
+
src/electrasmart/py.typed
|
|
6
|
+
src/electrasmart/api/__init__.py
|
|
7
|
+
src/electrasmart/api/const.py
|
|
8
|
+
src/electrasmart/api/utils.py
|
|
9
|
+
src/electrasmart/device/__init__.py
|
|
10
|
+
src/electrasmart/device/const.py
|
|
11
|
+
src/pyelectrasmart.egg-info/PKG-INFO
|
|
12
|
+
src/pyelectrasmart.egg-info/SOURCES.txt
|
|
13
|
+
src/pyelectrasmart.egg-info/dependency_links.txt
|
|
14
|
+
src/pyelectrasmart.egg-info/requires.txt
|
|
15
|
+
src/pyelectrasmart.egg-info/top_level.txt
|
|
16
|
+
tests/test_electrasmart.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
aiohttp
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
electrasmart
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"""Regression tests for the fixes on top of pyElectra 1.2.4."""
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
|
|
5
|
+
from electrasmart.device import ElectraAirConditioner
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def _device_record() -> dict:
|
|
9
|
+
return {
|
|
10
|
+
"id": "1234123456",
|
|
11
|
+
"name": "Living Room AC",
|
|
12
|
+
"regdate": "2023-01-01 00:00:00",
|
|
13
|
+
"model": "HTPC-12",
|
|
14
|
+
"mac": "aa:bb:cc:dd:ee:ff",
|
|
15
|
+
"sn": "SN123",
|
|
16
|
+
"manufactor": "Electra",
|
|
17
|
+
"deviceTypeName": "A/C",
|
|
18
|
+
"status": "1",
|
|
19
|
+
"deviceToken": "some-token",
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def _telemetry(raw_temp: int) -> dict:
|
|
24
|
+
return {
|
|
25
|
+
"commandJson": {
|
|
26
|
+
"OPER": json.dumps({"OPER": {"TURN_ON_OFF": "ON", "SPT": "22"}}),
|
|
27
|
+
"DIAG_L2": json.dumps(
|
|
28
|
+
{"DIAG_L2": {"I_RAT": str(raw_temp), "O_ODU_MODE": "COOL"}}
|
|
29
|
+
),
|
|
30
|
+
},
|
|
31
|
+
"timeDelta": 5,
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def test_device_without_device_token_does_not_crash() -> None:
|
|
36
|
+
"""The deviceToken field is optional on some units."""
|
|
37
|
+
record = _device_record()
|
|
38
|
+
del record["deviceToken"]
|
|
39
|
+
|
|
40
|
+
ac = ElectraAirConditioner(record)
|
|
41
|
+
|
|
42
|
+
assert ac.token == ""
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def test_device_with_device_token() -> None:
|
|
46
|
+
ac = ElectraAirConditioner(_device_record())
|
|
47
|
+
assert ac.token == "some-token"
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def test_raw_x256_temperature_is_normalized() -> None:
|
|
51
|
+
"""Raw 5632 == 22 °C; the ×256 left-shift must be undone."""
|
|
52
|
+
ac = ElectraAirConditioner(_device_record())
|
|
53
|
+
ac.update_operation_states(_telemetry(5632))
|
|
54
|
+
assert ac.get_sensor_temperature() == 22
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def test_already_normalized_temperature_is_left_alone() -> None:
|
|
58
|
+
"""Some units report the value already normalized; don't shift it again."""
|
|
59
|
+
ac = ElectraAirConditioner(_device_record())
|
|
60
|
+
ac.update_operation_states(_telemetry(22))
|
|
61
|
+
assert ac.get_sensor_temperature() == 22
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def test_missing_telemetry_leaves_no_temperature() -> None:
|
|
65
|
+
ac = ElectraAirConditioner(_device_record())
|
|
66
|
+
assert ac.get_sensor_temperature() is None
|