pycloudedge 0.1.12__tar.gz → 0.1.13__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.
- pycloudedge-0.1.13/CHANGELOG.md +28 -0
- {pycloudedge-0.1.12 → pycloudedge-0.1.13}/MANIFEST.in +4 -1
- {pycloudedge-0.1.12 → pycloudedge-0.1.13}/PKG-INFO +24 -11
- {pycloudedge-0.1.12 → pycloudedge-0.1.13}/README.md +23 -10
- pycloudedge-0.1.13/RELEASE.md +51 -0
- {pycloudedge-0.1.12 → pycloudedge-0.1.13}/cloudedge/_version.py +3 -3
- {pycloudedge-0.1.12 → pycloudedge-0.1.13}/cloudedge/client.py +95 -63
- {pycloudedge-0.1.12 → pycloudedge-0.1.13}/cloudedge/constants.py +1 -0
- {pycloudedge-0.1.12 → pycloudedge-0.1.13}/cloudedge/mqtt.py +54 -22
- {pycloudedge-0.1.12 → pycloudedge-0.1.13}/cloudedge/p2p/kcp_tunnel.py +14 -0
- {pycloudedge-0.1.12 → pycloudedge-0.1.13}/cloudedge/p2p/meari_signaling.py +17 -12
- {pycloudedge-0.1.12 → pycloudedge-0.1.13}/cloudedge/p2p/p2p_streamer.py +39 -1
- {pycloudedge-0.1.12 → pycloudedge-0.1.13}/cloudedge/stream_profiles.py +5 -1
- {pycloudedge-0.1.12 → pycloudedge-0.1.13}/pycloudedge.egg-info/PKG-INFO +24 -11
- {pycloudedge-0.1.12 → pycloudedge-0.1.13}/pycloudedge.egg-info/SOURCES.txt +1 -0
- {pycloudedge-0.1.12 → pycloudedge-0.1.13}/pycloudedge.egg-info/scm_file_list.json +1 -0
- pycloudedge-0.1.13/pycloudedge.egg-info/scm_version.json +8 -0
- pycloudedge-0.1.13/requirements-dev.txt +9 -0
- {pycloudedge-0.1.12 → pycloudedge-0.1.13}/tests/test_improvements.py +19 -0
- {pycloudedge-0.1.12 → pycloudedge-0.1.13}/tests/test_kcp_tunnel.py +21 -0
- {pycloudedge-0.1.12 → pycloudedge-0.1.13}/tests/test_media_sources.py +55 -1
- {pycloudedge-0.1.12 → pycloudedge-0.1.13}/tests/test_mqtt.py +127 -5
- {pycloudedge-0.1.12 → pycloudedge-0.1.13}/tests/test_openapi_credentials.py +46 -1
- {pycloudedge-0.1.12 → pycloudedge-0.1.13}/tests/test_reliability.py +13 -0
- {pycloudedge-0.1.12 → pycloudedge-0.1.13}/tests/test_review_fixes.py +5 -4
- {pycloudedge-0.1.12 → pycloudedge-0.1.13}/tests/test_signaling.py +28 -1
- {pycloudedge-0.1.12 → pycloudedge-0.1.13}/tests/test_stream_loop_timers.py +61 -6
- {pycloudedge-0.1.12 → pycloudedge-0.1.13}/tests/test_stream_profiles.py +12 -0
- pycloudedge-0.1.12/CHANGELOG.md +0 -14
- pycloudedge-0.1.12/pycloudedge.egg-info/scm_version.json +0 -8
- pycloudedge-0.1.12/requirements-dev.txt +0 -11
- {pycloudedge-0.1.12 → pycloudedge-0.1.13}/.env.example +0 -0
- {pycloudedge-0.1.12 → pycloudedge-0.1.13}/.github/workflows/ci.yml +0 -0
- {pycloudedge-0.1.12 → pycloudedge-0.1.13}/.gitignore +0 -0
- {pycloudedge-0.1.12 → pycloudedge-0.1.13}/LICENSE +0 -0
- {pycloudedge-0.1.12 → pycloudedge-0.1.13}/cloudedge/__init__.py +0 -0
- {pycloudedge-0.1.12 → pycloudedge-0.1.13}/cloudedge/cli.py +0 -0
- {pycloudedge-0.1.12 → pycloudedge-0.1.13}/cloudedge/exceptions.py +0 -0
- {pycloudedge-0.1.12 → pycloudedge-0.1.13}/cloudedge/image_decrypt.py +0 -0
- {pycloudedge-0.1.12 → pycloudedge-0.1.13}/cloudedge/iot_parameters.py +0 -0
- {pycloudedge-0.1.12 → pycloudedge-0.1.13}/cloudedge/logging_config.py +0 -0
- {pycloudedge-0.1.12 → pycloudedge-0.1.13}/cloudedge/p2p/__init__.py +0 -0
- {pycloudedge-0.1.12 → pycloudedge-0.1.13}/cloudedge/p2p/root_discovery.py +0 -0
- {pycloudedge-0.1.12 → pycloudedge-0.1.13}/cloudedge/p2p/turn_client.py +0 -0
- {pycloudedge-0.1.12 → pycloudedge-0.1.13}/cloudedge/utils.py +0 -0
- {pycloudedge-0.1.12 → pycloudedge-0.1.13}/cloudedge/validators.py +0 -0
- {pycloudedge-0.1.12 → pycloudedge-0.1.13}/docs/plans/2026-03-30-streaming-video.md +0 -0
- {pycloudedge-0.1.12 → pycloudedge-0.1.13}/examples/README.md +0 -0
- {pycloudedge-0.1.12 → pycloudedge-0.1.13}/examples/basic_example.py +0 -0
- {pycloudedge-0.1.12 → pycloudedge-0.1.13}/examples/device_control.py +0 -0
- {pycloudedge-0.1.12 → pycloudedge-0.1.13}/examples/network_ping_status.py +0 -0
- {pycloudedge-0.1.12 → pycloudedge-0.1.13}/examples/stream_test.py +0 -0
- {pycloudedge-0.1.12 → pycloudedge-0.1.13}/pycloudedge.egg-info/dependency_links.txt +0 -0
- {pycloudedge-0.1.12 → pycloudedge-0.1.13}/pycloudedge.egg-info/entry_points.txt +0 -0
- {pycloudedge-0.1.12 → pycloudedge-0.1.13}/pycloudedge.egg-info/requires.txt +0 -0
- {pycloudedge-0.1.12 → pycloudedge-0.1.13}/pycloudedge.egg-info/top_level.txt +0 -0
- {pycloudedge-0.1.12 → pycloudedge-0.1.13}/pyproject.toml +0 -0
- {pycloudedge-0.1.12 → pycloudedge-0.1.13}/requirements.txt +0 -0
- {pycloudedge-0.1.12 → pycloudedge-0.1.13}/setup.cfg +0 -0
- {pycloudedge-0.1.12 → pycloudedge-0.1.13}/setup.py +0 -0
- {pycloudedge-0.1.12 → pycloudedge-0.1.13}/test_3region_login.py +0 -0
- {pycloudedge-0.1.12 → pycloudedge-0.1.13}/tests/test_basic.py +0 -0
- {pycloudedge-0.1.12 → pycloudedge-0.1.13}/tests/test_device_status_and_info.py +0 -0
- {pycloudedge-0.1.12 → pycloudedge-0.1.13}/tests/test_log_redaction.py +0 -0
- {pycloudedge-0.1.12 → pycloudedge-0.1.13}/tests/test_review_followup.py +0 -0
- {pycloudedge-0.1.12 → pycloudedge-0.1.13}/tests/test_session_keepalive.py +0 -0
- {pycloudedge-0.1.12 → pycloudedge-0.1.13}/tests/test_stream_metadata_refresh.py +0 -0
- {pycloudedge-0.1.12 → pycloudedge-0.1.13}/tests/test_stream_transport.py +0 -0
- {pycloudedge-0.1.12 → pycloudedge-0.1.13}/tests/test_streaming_helpers.py +0 -0
- {pycloudedge-0.1.12 → pycloudedge-0.1.13}/tests/test_turn_renewal.py +0 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.1.13
|
|
4
|
+
|
|
5
|
+
Fixes fragmented video, MQTT listener lifecycle and authentication recovery after temporary credential-renewal failures. This is the library required by CloudEdge Home Assistant 1.5.0.
|
|
6
|
+
|
|
7
|
+
Changes:
|
|
8
|
+
- Fix corrupt video frames when a camera abandons a fragmented message: its fragments are no longer joined to the next message.
|
|
9
|
+
- Harden the MQTT listener: a second `start()` no longer leaves two connections open, an error in an `on_connect`/`on_disconnect` callback no longer stops push events, and an event callback that raises `TypeError` is no longer called twice.
|
|
10
|
+
- Tolerate devices without a name in `find_device_by_name()`, a malformed fps in a stream profile and relayed ICE checks without an IPv4 peer address; restore the signaling timeout after waiting for a camera to wake; deliver frames that arrive together with a camera keepalive without delay.
|
|
11
|
+
- A renewal of the OpenAPI credentials that fails (for example on a network error) no longer drops every device's signature, and no longer holds the next renewal back for a minute: one transient error used to fail the other devices' requests as rejected credentials.
|
|
12
|
+
- `get_device_status()` and `refresh_mqtt_config()` raise `AuthenticationError` when the server rejects the session (code 1023), as the home and device lists already did.
|
|
13
|
+
- Fix the README examples: import `cloudedge`, the package that `pip install pycloudedge` installs.
|
|
14
|
+
|
|
15
|
+
Requires Python 3.10 or newer. No public API changes are required for existing callers.
|
|
16
|
+
|
|
17
|
+
## 0.1.12
|
|
18
|
+
|
|
19
|
+
Relayed live streams that negotiated successfully but never delivered video now work: the P2P transport handles the extra XTS relay byte in both directions while retaining strict validation of direct KCP packets.
|
|
20
|
+
|
|
21
|
+
Changes:
|
|
22
|
+
- Fix device discovery for accounts with owned/default homes and shared homes; malformed or failed inventories no longer silently remove devices.
|
|
23
|
+
- Improve P2P recovery, signaling frame buffering, camera wake status handling, KCP acknowledgements, and TURN renewal/media handling.
|
|
24
|
+
- Refresh MQTT credentials on reconnect and preserve dormant battery-camera status.
|
|
25
|
+
- Redact credentials and signed URLs from diagnostics and debug logging.
|
|
26
|
+
- Opening a live stream no longer toggles the camera floodlight setting.
|
|
27
|
+
|
|
28
|
+
Requires Python 3.10 or newer. Live verification covered three cameras, including a relayed H.264 stream at 2304×1296 through Home Assistant. The library regression suite contains 331 passing tests.
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
include README.md
|
|
2
|
+
include CHANGELOG.md
|
|
3
|
+
include RELEASE.md
|
|
2
4
|
include LICENSE
|
|
3
5
|
include requirements.txt
|
|
6
|
+
include requirements-dev.txt
|
|
4
7
|
include .env.example
|
|
5
8
|
recursive-include cloudedge *.py
|
|
6
9
|
recursive-include examples *.py *.md
|
|
@@ -9,4 +12,4 @@ exclude cloudedge_api_flow.py
|
|
|
9
12
|
exclude iot_parameters.py
|
|
10
13
|
exclude results.txt
|
|
11
14
|
exclude .cloudedge_session_cache
|
|
12
|
-
exclude .home_id
|
|
15
|
+
exclude .home_id
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pycloudedge
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.13
|
|
4
4
|
Summary: Python library for CloudEdge cameras
|
|
5
5
|
Home-page: https://github.com/fradaloisio/pycloudedge
|
|
6
6
|
Author: Francesco D'Aloisio
|
|
@@ -171,7 +171,7 @@ Optional dependencies:
|
|
|
171
171
|
```python
|
|
172
172
|
import os
|
|
173
173
|
from dotenv import load_dotenv
|
|
174
|
-
from
|
|
174
|
+
from cloudedge import CloudEdgeClient
|
|
175
175
|
|
|
176
176
|
def main():
|
|
177
177
|
# Initialize the client
|
|
@@ -217,7 +217,7 @@ if __name__ == "__main__":
|
|
|
217
217
|
### Multi-Home Device Management
|
|
218
218
|
|
|
219
219
|
```python
|
|
220
|
-
from
|
|
220
|
+
from cloudedge import CloudEdgeClient
|
|
221
221
|
|
|
222
222
|
def manage_multi_home():
|
|
223
223
|
client = CloudEdgeClient("user@example.com", "password", "US", "+1")
|
|
@@ -246,7 +246,7 @@ manage_multi_home()
|
|
|
246
246
|
### Device Control
|
|
247
247
|
|
|
248
248
|
```python
|
|
249
|
-
from
|
|
249
|
+
from cloudedge import CloudEdgeClient
|
|
250
250
|
|
|
251
251
|
def control_devices():
|
|
252
252
|
client = CloudEdgeClient("user@example.com", "password", "US", "+1")
|
|
@@ -289,7 +289,7 @@ Then use environment variables in your code:
|
|
|
289
289
|
```python
|
|
290
290
|
import os
|
|
291
291
|
from dotenv import load_dotenv
|
|
292
|
-
from
|
|
292
|
+
from cloudedge import CloudEdgeClient
|
|
293
293
|
|
|
294
294
|
load_dotenv()
|
|
295
295
|
|
|
@@ -559,7 +559,7 @@ The library includes comprehensive IoT parameter definitions for CloudEdge devic
|
|
|
559
559
|
### Parameter Helper Functions
|
|
560
560
|
|
|
561
561
|
```python
|
|
562
|
-
from
|
|
562
|
+
from cloudedge import get_parameter_name, format_parameter_value
|
|
563
563
|
|
|
564
564
|
# Get human-readable name from code
|
|
565
565
|
name = get_parameter_name("167") # Returns "FRONT_LIGHT_SWITCH"
|
|
@@ -573,7 +573,7 @@ formatted = format_parameter_value("BATTERY_PERCENT", 85) # Returns "85%"
|
|
|
573
573
|
The library provides specific exception types for different error conditions:
|
|
574
574
|
|
|
575
575
|
```python
|
|
576
|
-
from
|
|
576
|
+
from cloudedge import (
|
|
577
577
|
CloudEdgeClient,
|
|
578
578
|
AuthenticationError,
|
|
579
579
|
DeviceNotFoundError,
|
|
@@ -633,12 +633,25 @@ mypy cloudedge/
|
|
|
633
633
|
|
|
634
634
|
### Building and Publishing
|
|
635
635
|
|
|
636
|
+
See [Release preparation](RELEASE.md) for the 0.1.13 candidate build, installed
|
|
637
|
+
artifact checks and the coordinated release with CloudEdge Home Assistant 1.5.0.
|
|
638
|
+
The version comes from Git tags through `setuptools_scm`; do not edit the
|
|
639
|
+
generated `cloudedge/_version.py` file.
|
|
640
|
+
|
|
636
641
|
```bash
|
|
637
|
-
#
|
|
638
|
-
python -m build
|
|
642
|
+
# Prepare a local candidate before creating the release tag; this does not publish.
|
|
643
|
+
SETUPTOOLS_SCM_PRETEND_VERSION_FOR_PYCLOUDEDGE=0.1.13 python -m build --outdir dist-staging/0.1.13
|
|
644
|
+
python -m twine check --strict dist-staging/0.1.13/*
|
|
645
|
+
```
|
|
639
646
|
|
|
640
|
-
|
|
641
|
-
|
|
647
|
+
After release approval, create the `v0.1.13` tag on the approved commit, build
|
|
648
|
+
again from a clean checkout of that tag without the version override, and
|
|
649
|
+
validate those artifacts before uploading:
|
|
650
|
+
|
|
651
|
+
```bash
|
|
652
|
+
python -m build
|
|
653
|
+
python -m twine check --strict dist/*
|
|
654
|
+
# Publication is a separate, approved step; see RELEASE.md.
|
|
642
655
|
```
|
|
643
656
|
|
|
644
657
|
## Troubleshooting
|
|
@@ -123,7 +123,7 @@ Optional dependencies:
|
|
|
123
123
|
```python
|
|
124
124
|
import os
|
|
125
125
|
from dotenv import load_dotenv
|
|
126
|
-
from
|
|
126
|
+
from cloudedge import CloudEdgeClient
|
|
127
127
|
|
|
128
128
|
def main():
|
|
129
129
|
# Initialize the client
|
|
@@ -169,7 +169,7 @@ if __name__ == "__main__":
|
|
|
169
169
|
### Multi-Home Device Management
|
|
170
170
|
|
|
171
171
|
```python
|
|
172
|
-
from
|
|
172
|
+
from cloudedge import CloudEdgeClient
|
|
173
173
|
|
|
174
174
|
def manage_multi_home():
|
|
175
175
|
client = CloudEdgeClient("user@example.com", "password", "US", "+1")
|
|
@@ -198,7 +198,7 @@ manage_multi_home()
|
|
|
198
198
|
### Device Control
|
|
199
199
|
|
|
200
200
|
```python
|
|
201
|
-
from
|
|
201
|
+
from cloudedge import CloudEdgeClient
|
|
202
202
|
|
|
203
203
|
def control_devices():
|
|
204
204
|
client = CloudEdgeClient("user@example.com", "password", "US", "+1")
|
|
@@ -241,7 +241,7 @@ Then use environment variables in your code:
|
|
|
241
241
|
```python
|
|
242
242
|
import os
|
|
243
243
|
from dotenv import load_dotenv
|
|
244
|
-
from
|
|
244
|
+
from cloudedge import CloudEdgeClient
|
|
245
245
|
|
|
246
246
|
load_dotenv()
|
|
247
247
|
|
|
@@ -511,7 +511,7 @@ The library includes comprehensive IoT parameter definitions for CloudEdge devic
|
|
|
511
511
|
### Parameter Helper Functions
|
|
512
512
|
|
|
513
513
|
```python
|
|
514
|
-
from
|
|
514
|
+
from cloudedge import get_parameter_name, format_parameter_value
|
|
515
515
|
|
|
516
516
|
# Get human-readable name from code
|
|
517
517
|
name = get_parameter_name("167") # Returns "FRONT_LIGHT_SWITCH"
|
|
@@ -525,7 +525,7 @@ formatted = format_parameter_value("BATTERY_PERCENT", 85) # Returns "85%"
|
|
|
525
525
|
The library provides specific exception types for different error conditions:
|
|
526
526
|
|
|
527
527
|
```python
|
|
528
|
-
from
|
|
528
|
+
from cloudedge import (
|
|
529
529
|
CloudEdgeClient,
|
|
530
530
|
AuthenticationError,
|
|
531
531
|
DeviceNotFoundError,
|
|
@@ -585,12 +585,25 @@ mypy cloudedge/
|
|
|
585
585
|
|
|
586
586
|
### Building and Publishing
|
|
587
587
|
|
|
588
|
+
See [Release preparation](RELEASE.md) for the 0.1.13 candidate build, installed
|
|
589
|
+
artifact checks and the coordinated release with CloudEdge Home Assistant 1.5.0.
|
|
590
|
+
The version comes from Git tags through `setuptools_scm`; do not edit the
|
|
591
|
+
generated `cloudedge/_version.py` file.
|
|
592
|
+
|
|
588
593
|
```bash
|
|
589
|
-
#
|
|
590
|
-
python -m build
|
|
594
|
+
# Prepare a local candidate before creating the release tag; this does not publish.
|
|
595
|
+
SETUPTOOLS_SCM_PRETEND_VERSION_FOR_PYCLOUDEDGE=0.1.13 python -m build --outdir dist-staging/0.1.13
|
|
596
|
+
python -m twine check --strict dist-staging/0.1.13/*
|
|
597
|
+
```
|
|
591
598
|
|
|
592
|
-
|
|
593
|
-
|
|
599
|
+
After release approval, create the `v0.1.13` tag on the approved commit, build
|
|
600
|
+
again from a clean checkout of that tag without the version override, and
|
|
601
|
+
validate those artifacts before uploading:
|
|
602
|
+
|
|
603
|
+
```bash
|
|
604
|
+
python -m build
|
|
605
|
+
python -m twine check --strict dist/*
|
|
606
|
+
# Publication is a separate, approved step; see RELEASE.md.
|
|
594
607
|
```
|
|
595
608
|
|
|
596
609
|
## Troubleshooting
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# pycloudedge 0.1.13 release preparation
|
|
2
|
+
|
|
3
|
+
This candidate is on `fix/corrective-0.1.13` and is required by CloudEdge Home
|
|
4
|
+
Assistant **1.5.0**. Its release notes are the `0.1.13` section of `CHANGELOG.md`.
|
|
5
|
+
Supported Python versions start at **3.10**; CI tests **3.10** and **3.14**.
|
|
6
|
+
|
|
7
|
+
## Build a candidate without releasing
|
|
8
|
+
|
|
9
|
+
Use an isolated environment with `requirements-dev.txt` installed. From this
|
|
10
|
+
repository root:
|
|
11
|
+
|
|
12
|
+
```sh
|
|
13
|
+
python -m pip install -r requirements-dev.txt
|
|
14
|
+
python -m pytest tests/ -p no:cacheprovider -o addopts='' -q
|
|
15
|
+
SETUPTOOLS_SCM_PRETEND_VERSION_FOR_PYCLOUDEDGE=0.1.13 python -m build --outdir dist-staging/0.1.13
|
|
16
|
+
python -m twine check --strict dist-staging/0.1.13/*
|
|
17
|
+
git diff --check
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
The version override produces a local **0.1.13** candidate without a Git tag;
|
|
21
|
+
it does not publish anything. `cloudedge/_version.py` is generated and ignored,
|
|
22
|
+
so there is no tracked version constant to bump.
|
|
23
|
+
|
|
24
|
+
Install the wheel in fresh Python **3.10** and **3.14** environments with
|
|
25
|
+
`pytest` and the runtime dependencies, including the optional `paho-mqtt`.
|
|
26
|
+
Copy `tests/` outside this checkout and run the suite from there so imports
|
|
27
|
+
exercise the installed wheel. Check both `cloudedge.__version__` and
|
|
28
|
+
`importlib.metadata.version('pycloudedge')` report **0.1.13**. Also build a wheel
|
|
29
|
+
from the source archive and run the same checks. This catches missing source
|
|
30
|
+
files and package metadata differences.
|
|
31
|
+
|
|
32
|
+
Install the candidate wheel into the integration's Python 3.14 test environment
|
|
33
|
+
before installing its requirements, then run the integration suite. For the
|
|
34
|
+
coordinated publication sequence, see `../cloudedge-ha/RELEASE.md`.
|
|
35
|
+
|
|
36
|
+
## Publication after approval
|
|
37
|
+
|
|
38
|
+
1. Review and commit the candidate with the owner's configured author identity,
|
|
39
|
+
without `Co-authored-by` trailers; merge it and require CI to pass.
|
|
40
|
+
2. Create and push **v0.1.13** on the approved commit.
|
|
41
|
+
3. In a fresh checkout of that tag, with no version override, run `python -m build`
|
|
42
|
+
into an empty output directory and `python -m twine check --strict dist/*`.
|
|
43
|
+
Confirm the wheel and source archive metadata both say **0.1.13**, and rerun
|
|
44
|
+
installed-artifact tests.
|
|
45
|
+
4. Upload only those checked **0.1.13** files to PyPI and publish the GitHub
|
|
46
|
+
release using the changelog section as its notes.
|
|
47
|
+
5. Verify a new environment can install **pycloudedge==0.1.13** from PyPI before
|
|
48
|
+
releasing CloudEdge Home Assistant **1.5.0**.
|
|
49
|
+
|
|
50
|
+
Prepared local archives are candidates, not published releases. Keep account
|
|
51
|
+
files, logs, caches and credentials out of every archive.
|
|
@@ -18,7 +18,7 @@ version_tuple: tuple[int | str, ...]
|
|
|
18
18
|
commit_id: str | None
|
|
19
19
|
__commit_id__: str | None
|
|
20
20
|
|
|
21
|
-
__version__ = version = '0.1.
|
|
22
|
-
__version_tuple__ = version_tuple = (0, 1,
|
|
21
|
+
__version__ = version = '0.1.13'
|
|
22
|
+
__version_tuple__ = version_tuple = (0, 1, 13)
|
|
23
23
|
|
|
24
|
-
__commit_id__ = commit_id =
|
|
24
|
+
__commit_id__ = commit_id = 'g30dd22605'
|
|
@@ -43,8 +43,10 @@ from .iot_parameters import (
|
|
|
43
43
|
format_parameter_value
|
|
44
44
|
)
|
|
45
45
|
from .constants import (
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
APP_VERSION, APP_VERSION_CODE,
|
|
47
|
+
CA_KEY, CA_SECRET, DEFAULT_HEADERS, DEFAULT_LANGUAGE, DEFAULT_TIMEOUT,
|
|
48
|
+
IOT_TYPE, PHONE_TYPE, REDIRECT_URL, SDK_VERSION, SESSION_INVALID_RESULT_CODES,
|
|
49
|
+
SOURCE_APP,
|
|
48
50
|
)
|
|
49
51
|
from .validators import validate_email, validate_country_code, validate_phone_code
|
|
50
52
|
from .logging_config import get_logger
|
|
@@ -115,6 +117,21 @@ _APP_STREAMING_METADATA_FIELDS = {
|
|
|
115
117
|
}
|
|
116
118
|
|
|
117
119
|
|
|
120
|
+
def _raise_if_session_rejected(response_data: Dict[str, Any]) -> None:
|
|
121
|
+
"""Raise AuthenticationError when the API rejected the session token.
|
|
122
|
+
|
|
123
|
+
The server rejects it when the account logged in elsewhere (one active
|
|
124
|
+
session per account): callers must re-authenticate instead of retrying
|
|
125
|
+
forever with a dead session.
|
|
126
|
+
"""
|
|
127
|
+
error_code = response_data.get("resultCode", "unknown")
|
|
128
|
+
if str(error_code) in SESSION_INVALID_RESULT_CODES:
|
|
129
|
+
error_msg = response_data.get("resultMsg", "Unknown error")
|
|
130
|
+
raise AuthenticationError(
|
|
131
|
+
f"Session rejected by API (Code: {error_code}): {error_msg}"
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
|
|
118
135
|
def _read_device_list(payload: Dict[str, Any], key: str) -> List[Dict[str, Any]]:
|
|
119
136
|
"""Read an optional list without treating malformed inventory as empty."""
|
|
120
137
|
devices = payload.get(key, [])
|
|
@@ -786,12 +803,7 @@ class CloudEdgeClient:
|
|
|
786
803
|
last_refresh = getattr(self, "_last_openapi_auth_refresh", float("-inf"))
|
|
787
804
|
if attempt == 0 and now - last_refresh >= 60:
|
|
788
805
|
self._last_openapi_auth_refresh = now
|
|
789
|
-
self.
|
|
790
|
-
self._save_session_cache(self.session_data)
|
|
791
|
-
# Device signatures expire too; a stale one is rejected
|
|
792
|
-
# with the same 401 as stale platform credentials.
|
|
793
|
-
self._device_tokens.clear()
|
|
794
|
-
self._refresh_device_tokens(force_refresh=True)
|
|
806
|
+
self._renew_openapi_credentials(device_id, last_refresh)
|
|
795
807
|
continue
|
|
796
808
|
raise AuthenticationError("OpenAPI authorization rejected (401)")
|
|
797
809
|
if str(data.get("errid", 0)) != "0":
|
|
@@ -803,6 +815,36 @@ class CloudEdgeClient:
|
|
|
803
815
|
return response
|
|
804
816
|
raise AuthenticationError("OpenAPI authorization rejected (401)")
|
|
805
817
|
|
|
818
|
+
def _renew_openapi_credentials(
|
|
819
|
+
self, rejected_device: Optional[str], last_refresh: float
|
|
820
|
+
) -> None:
|
|
821
|
+
"""Renew the platform keys and the device signatures after a 401.
|
|
822
|
+
|
|
823
|
+
Device signatures expire too; a stale one is rejected with the same
|
|
824
|
+
401 as stale platform credentials, so the rejected device's is
|
|
825
|
+
dropped and all are minted again. The other devices keep theirs
|
|
826
|
+
when the renewal cannot replace them, and a failed renewal does not
|
|
827
|
+
hold back the next one: otherwise one transient error would fail
|
|
828
|
+
every device's next requests as rejected credentials.
|
|
829
|
+
"""
|
|
830
|
+
with self._state_lock:
|
|
831
|
+
kept = {
|
|
832
|
+
device: entry
|
|
833
|
+
for device, entry in self._device_tokens.items()
|
|
834
|
+
if device != rejected_device
|
|
835
|
+
}
|
|
836
|
+
try:
|
|
837
|
+
self._fetch_iot_config(force_refresh=True)
|
|
838
|
+
self._save_session_cache(self.session_data)
|
|
839
|
+
self._device_tokens.clear()
|
|
840
|
+
self._refresh_device_tokens(force_refresh=True)
|
|
841
|
+
except Exception:
|
|
842
|
+
self._last_openapi_auth_refresh = last_refresh
|
|
843
|
+
raise
|
|
844
|
+
finally:
|
|
845
|
+
for device, entry in kept.items():
|
|
846
|
+
self._device_tokens.setdefault(device, entry)
|
|
847
|
+
|
|
806
848
|
def _generate_timestamp(self) -> str:
|
|
807
849
|
"""Generate timestamp in CloudEdge format."""
|
|
808
850
|
return datetime.datetime.now().astimezone().isoformat(timespec='seconds')
|
|
@@ -1031,13 +1073,13 @@ class CloudEdgeClient:
|
|
|
1031
1073
|
|
|
1032
1074
|
phone_code_bare = self.phone_code.lstrip("+")
|
|
1033
1075
|
params = {
|
|
1034
|
-
"phoneType":
|
|
1035
|
-
"sourceApp":
|
|
1036
|
-
"appVer":
|
|
1037
|
-
"appVerCode":
|
|
1076
|
+
"phoneType": PHONE_TYPE,
|
|
1077
|
+
"sourceApp": SOURCE_APP,
|
|
1078
|
+
"appVer": APP_VERSION,
|
|
1079
|
+
"appVerCode": APP_VERSION_CODE,
|
|
1038
1080
|
"localTime": str(timestamp),
|
|
1039
1081
|
"t": str(timestamp),
|
|
1040
|
-
"lngType":
|
|
1082
|
+
"lngType": DEFAULT_LANGUAGE,
|
|
1041
1083
|
"countryCode": self.country_code,
|
|
1042
1084
|
"userAccount": encrypted_account,
|
|
1043
1085
|
"phoneCode": phone_code_bare,
|
|
@@ -1186,35 +1228,30 @@ class CloudEdgeClient:
|
|
|
1186
1228
|
# The app sends the dialling prefix without the leading "+"
|
|
1187
1229
|
phone_code_bare = self.phone_code.lstrip("+")
|
|
1188
1230
|
|
|
1189
|
-
# Create signature
|
|
1190
|
-
ca_sign_data = (
|
|
1191
|
-
f"phoneType=a&sourceApp=8&appVer=6.2.8&iotType=4&equipmentNo= &"
|
|
1192
|
-
f"appVerCode=643&localTime={timestamp}&password={encrypted_password}&"
|
|
1193
|
-
f"t={timestamp}&lngType=en&countryCode={self.country_code}&"
|
|
1194
|
-
f"userAccount={encrypted_username}&encryStatus=1&"
|
|
1195
|
-
f"phoneCode={phone_code_bare}"
|
|
1196
|
-
)
|
|
1197
|
-
ca_signature = base64.b64encode(
|
|
1198
|
-
hmac.new(ca_key.encode(), ca_sign_data.encode(), hashlib.sha1).digest()
|
|
1199
|
-
).decode()
|
|
1200
|
-
|
|
1201
1231
|
login_data = {
|
|
1202
|
-
"phoneType":
|
|
1203
|
-
"sourceApp":
|
|
1204
|
-
"appVer":
|
|
1205
|
-
"iotType":
|
|
1232
|
+
"phoneType": PHONE_TYPE,
|
|
1233
|
+
"sourceApp": SOURCE_APP,
|
|
1234
|
+
"appVer": APP_VERSION,
|
|
1235
|
+
"iotType": IOT_TYPE,
|
|
1206
1236
|
"equipmentNo": " ",
|
|
1207
|
-
"appVerCode":
|
|
1237
|
+
"appVerCode": APP_VERSION_CODE,
|
|
1208
1238
|
"localTime": timestamp,
|
|
1209
1239
|
"password": encrypted_password,
|
|
1210
1240
|
"t": timestamp,
|
|
1211
|
-
"lngType":
|
|
1241
|
+
"lngType": DEFAULT_LANGUAGE,
|
|
1212
1242
|
"countryCode": self.country_code,
|
|
1213
1243
|
"userAccount": encrypted_username,
|
|
1214
1244
|
"encryStatus": "1",
|
|
1215
1245
|
"phoneCode": phone_code_bare
|
|
1216
1246
|
}
|
|
1217
|
-
|
|
1247
|
+
|
|
1248
|
+
# The signature covers the form fields in the order they are sent,
|
|
1249
|
+
# unencoded.
|
|
1250
|
+
ca_sign_data = "&".join(f"{key}={value}" for key, value in login_data.items())
|
|
1251
|
+
ca_signature = base64.b64encode(
|
|
1252
|
+
hmac.new(ca_key.encode(), ca_sign_data.encode(), hashlib.sha1).digest()
|
|
1253
|
+
).decode()
|
|
1254
|
+
|
|
1218
1255
|
headers = {
|
|
1219
1256
|
"Accept-Language": "en-US,en;q=0.8",
|
|
1220
1257
|
"User-Agent": "Mozilla/5.0 (Linux; U; Android 10; en-us; Android SDK built for arm64 Build/QSR1.211112.002) AppleWebKit/533.1 (KHTML, like Gecko) Version/5.0 Mobile Safari/533.1",
|
|
@@ -1344,11 +1381,12 @@ class CloudEdgeClient:
|
|
|
1344
1381
|
ts = int(time.time() * 1000)
|
|
1345
1382
|
|
|
1346
1383
|
params = {
|
|
1347
|
-
'appVer':
|
|
1348
|
-
'
|
|
1384
|
+
'appVer': APP_VERSION, 'appVerCode': APP_VERSION_CODE,
|
|
1385
|
+
'lngType': DEFAULT_LANGUAGE, 'phoneType': PHONE_TYPE,
|
|
1386
|
+
'sdkVer': SDK_VERSION, 'sourceApp': SOURCE_APP,
|
|
1349
1387
|
'countryCode': self.country_code,
|
|
1350
1388
|
'phoneCode': self.phone_code,
|
|
1351
|
-
'iotType':
|
|
1389
|
+
'iotType': IOT_TYPE,
|
|
1352
1390
|
'signatureMethod': 'HMAC-SHA1', 'signatureVersion': '1.0',
|
|
1353
1391
|
'signatureNonce': str(ts),
|
|
1354
1392
|
't': str(ts), 'timestamp': str(ts),
|
|
@@ -1380,6 +1418,7 @@ class CloudEdgeClient:
|
|
|
1380
1418
|
data = resp.json()
|
|
1381
1419
|
if data.get("resultCode") != "1001":
|
|
1382
1420
|
self._log(f"IoT config response: {data.get('resultCode')}")
|
|
1421
|
+
_raise_if_session_rejected(data)
|
|
1383
1422
|
return
|
|
1384
1423
|
|
|
1385
1424
|
pf = data.get("result", {}).get("pfApi", {})
|
|
@@ -1448,6 +1487,8 @@ class CloudEdgeClient:
|
|
|
1448
1487
|
f"MQTT config: {self.session_data['mqtt']['mqtt_host']}"
|
|
1449
1488
|
f":{self.session_data['mqtt']['mqtt_port']}"
|
|
1450
1489
|
)
|
|
1490
|
+
except AuthenticationError:
|
|
1491
|
+
raise
|
|
1451
1492
|
except Exception as exc:
|
|
1452
1493
|
self._log(f"Failed to fetch IoT config: {_safe_exception_text(exc)}")
|
|
1453
1494
|
|
|
@@ -1507,12 +1548,12 @@ class CloudEdgeClient:
|
|
|
1507
1548
|
raise AuthenticationError("Not authenticated")
|
|
1508
1549
|
|
|
1509
1550
|
body = {
|
|
1510
|
-
'appVer':
|
|
1511
|
-
'appVerCode':
|
|
1512
|
-
'lngType':
|
|
1513
|
-
'phoneType':
|
|
1514
|
-
'sdkVer':
|
|
1515
|
-
'sourceApp':
|
|
1551
|
+
'appVer': APP_VERSION,
|
|
1552
|
+
'appVerCode': APP_VERSION_CODE,
|
|
1553
|
+
'lngType': DEFAULT_LANGUAGE,
|
|
1554
|
+
'phoneType': PHONE_TYPE,
|
|
1555
|
+
'sdkVer': SDK_VERSION,
|
|
1556
|
+
'sourceApp': SOURCE_APP,
|
|
1516
1557
|
'userID': self.session_data['userID'],
|
|
1517
1558
|
'userToken': self.session_data['userToken']
|
|
1518
1559
|
}
|
|
@@ -1543,9 +1584,10 @@ class CloudEdgeClient:
|
|
|
1543
1584
|
nonce = int(time.time())
|
|
1544
1585
|
|
|
1545
1586
|
params_str = (
|
|
1546
|
-
f"appVer=
|
|
1587
|
+
f"appVer={APP_VERSION}&appVerCode={APP_VERSION_CODE}&"
|
|
1588
|
+
f"lngType={DEFAULT_LANGUAGE}&phoneType={PHONE_TYPE}&"
|
|
1547
1589
|
f"signatureMethod=HMAC-SHA1&signatureNonce={nonce}&"
|
|
1548
|
-
f"signatureVersion=1.0&sourceApp=
|
|
1590
|
+
f"signatureVersion=1.0&sourceApp={SOURCE_APP}×tamp={timestamp}&"
|
|
1549
1591
|
f"userID={self.session_data['userID']}"
|
|
1550
1592
|
)
|
|
1551
1593
|
|
|
@@ -1597,14 +1639,7 @@ class CloudEdgeClient:
|
|
|
1597
1639
|
error_msg = response_data.get('resultMsg', 'Unknown error')
|
|
1598
1640
|
error_code = response_data.get('resultCode', 'unknown')
|
|
1599
1641
|
self._log(f"API error - Code: {error_code}, Message: {error_msg}")
|
|
1600
|
-
|
|
1601
|
-
# The server rejected our token (e.g. the account was
|
|
1602
|
-
# logged in elsewhere — one active session per account).
|
|
1603
|
-
# Raise the typed auth error so callers re-authenticate
|
|
1604
|
-
# instead of retrying forever with a dead session.
|
|
1605
|
-
raise AuthenticationError(
|
|
1606
|
-
f"Session rejected by API (Code: {error_code}): {error_msg}"
|
|
1607
|
-
)
|
|
1642
|
+
_raise_if_session_rejected(response_data)
|
|
1608
1643
|
raise CloudEdgeError(
|
|
1609
1644
|
f"Failed to retrieve homes: {error_msg} (Code: {error_code})",
|
|
1610
1645
|
details={"error_code": error_code, "message": error_msg}
|
|
@@ -1645,9 +1680,10 @@ class CloudEdgeClient:
|
|
|
1645
1680
|
nonce = int(time.time())
|
|
1646
1681
|
|
|
1647
1682
|
params_str = (
|
|
1648
|
-
f"appVer=
|
|
1683
|
+
f"appVer={APP_VERSION}&appVerCode={APP_VERSION_CODE}&homeID={home_id}&"
|
|
1684
|
+
f"lngType={DEFAULT_LANGUAGE}&phoneType={PHONE_TYPE}&"
|
|
1649
1685
|
f"signatureMethod=HMAC-SHA1&signatureNonce={nonce}&"
|
|
1650
|
-
f"signatureVersion=1.0&sourceApp=
|
|
1686
|
+
f"signatureVersion=1.0&sourceApp={SOURCE_APP}×tamp={timestamp}&"
|
|
1651
1687
|
f"userID={self.session_data['userID']}"
|
|
1652
1688
|
)
|
|
1653
1689
|
|
|
@@ -1711,10 +1747,7 @@ class CloudEdgeClient:
|
|
|
1711
1747
|
else:
|
|
1712
1748
|
error_msg = response_data.get('resultMsg', 'Unknown error')
|
|
1713
1749
|
error_code = response_data.get('resultCode', 'unknown')
|
|
1714
|
-
|
|
1715
|
-
raise AuthenticationError(
|
|
1716
|
-
f"Session rejected by API (Code: {error_code}): {error_msg}"
|
|
1717
|
-
)
|
|
1750
|
+
_raise_if_session_rejected(response_data)
|
|
1718
1751
|
raise CloudEdgeError(
|
|
1719
1752
|
f"Failed to retrieve home devices: {error_msg} (Code: {error_code})",
|
|
1720
1753
|
details={"error_code": error_code, "message": error_msg, "home_id": home_id}
|
|
@@ -1944,10 +1977,7 @@ class CloudEdgeClient:
|
|
|
1944
1977
|
else:
|
|
1945
1978
|
error_msg = response_data.get('resultMsg', 'Unknown error')
|
|
1946
1979
|
error_code = response_data.get('resultCode', 'unknown')
|
|
1947
|
-
|
|
1948
|
-
raise AuthenticationError(
|
|
1949
|
-
f"Session rejected by API (Code: {error_code}): {error_msg}"
|
|
1950
|
-
)
|
|
1980
|
+
_raise_if_session_rejected(response_data)
|
|
1951
1981
|
raise CloudEdgeError(
|
|
1952
1982
|
f"Failed to retrieve devices: {error_msg}",
|
|
1953
1983
|
details={"error_code": error_code, "message": error_msg}
|
|
@@ -2024,6 +2054,7 @@ class CloudEdgeClient:
|
|
|
2024
2054
|
error_msg = response_data.get('resultMsg', 'Unknown error')
|
|
2025
2055
|
error_code = response_data.get('resultCode', 'unknown')
|
|
2026
2056
|
self._log(f"Failed to get device status: {error_msg}")
|
|
2057
|
+
_raise_if_session_rejected(response_data)
|
|
2027
2058
|
raise CloudEdgeError(
|
|
2028
2059
|
f"Failed to get device status: {error_msg}",
|
|
2029
2060
|
details={"error_code": error_code, "device_id": device_id}
|
|
@@ -2520,9 +2551,10 @@ class CloudEdgeClient:
|
|
|
2520
2551
|
devices = self.get_all_devices()
|
|
2521
2552
|
|
|
2522
2553
|
name = device_name.lower()
|
|
2523
|
-
|
|
2554
|
+
# A device listed with a null deviceName has name None.
|
|
2555
|
+
matches = [device for device in devices if (device.get("name") or "").lower() == name]
|
|
2524
2556
|
if not matches:
|
|
2525
|
-
matches = [device for device in devices if name in device.get("name"
|
|
2557
|
+
matches = [device for device in devices if name in (device.get("name") or "").lower()]
|
|
2526
2558
|
if len(matches) > 1:
|
|
2527
2559
|
raise DeviceNotFoundError(
|
|
2528
2560
|
f"Device name '{device_name}' is ambiguous; use a unique device name",
|