ipguard-api 0.1.0b6__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.
- ipguard_api-0.1.0b6/.gitignore +32 -0
- ipguard_api-0.1.0b6/.python-version +1 -0
- ipguard_api-0.1.0b6/DEVELOPMENT.md +56 -0
- ipguard_api-0.1.0b6/LICENSE +201 -0
- ipguard_api-0.1.0b6/PKG-INFO +47 -0
- ipguard_api-0.1.0b6/README.md +31 -0
- ipguard_api-0.1.0b6/build-constraints.txt +7 -0
- ipguard_api-0.1.0b6/conftest.py +93 -0
- ipguard_api-0.1.0b6/docs/USAGE.md +106 -0
- ipguard_api-0.1.0b6/pyproject.toml +96 -0
- ipguard_api-0.1.0b6/scripts/packaging_policy.py +274 -0
- ipguard_api-0.1.0b6/scripts/release_metadata.py +342 -0
- ipguard_api-0.1.0b6/src/ipguard_api/__init__.py +63 -0
- ipguard_api-0.1.0b6/src/ipguard_api/client.py +833 -0
- ipguard_api-0.1.0b6/src/ipguard_api/errors.py +53 -0
- ipguard_api-0.1.0b6/src/ipguard_api/models.py +205 -0
- ipguard_api-0.1.0b6/src/ipguard_api/protocol.py +464 -0
- ipguard_api-0.1.0b6/src/ipguard_api/py.typed +0 -0
- ipguard_api-0.1.0b6/src/ipguard_api/transport.py +265 -0
- ipguard_api-0.1.0b6/src/ipguard_api/validation.py +93 -0
- ipguard_api-0.1.0b6/tests/test_cloud.py +1644 -0
- ipguard_api-0.1.0b6/tests/test_contract.py +286 -0
- ipguard_api-0.1.0b6/tests/test_network_guard.py +50 -0
- ipguard_api-0.1.0b6/tests/test_packaging.py +320 -0
- ipguard_api-0.1.0b6/tests/test_protocol.py +601 -0
- ipguard_api-0.1.0b6/uv.lock +400 -0
- ipguard_api-0.1.0b6/uv.toml +2 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
.venv/
|
|
2
|
+
.cache/
|
|
3
|
+
.pytest_cache/
|
|
4
|
+
.mypy_cache/
|
|
5
|
+
.ruff_cache/
|
|
6
|
+
__pycache__/
|
|
7
|
+
*.py[cod]
|
|
8
|
+
*.egg-info/
|
|
9
|
+
.coverage
|
|
10
|
+
coverage.xml
|
|
11
|
+
htmlcov/
|
|
12
|
+
dist/
|
|
13
|
+
upload/
|
|
14
|
+
build/
|
|
15
|
+
.ha-dev/
|
|
16
|
+
.env
|
|
17
|
+
.env.*
|
|
18
|
+
.ipguard/
|
|
19
|
+
*.session.json
|
|
20
|
+
.storage/
|
|
21
|
+
session.json
|
|
22
|
+
credentials.json
|
|
23
|
+
credentials.yaml
|
|
24
|
+
credentials.yml
|
|
25
|
+
*.credentials.json
|
|
26
|
+
*.credentials.yaml
|
|
27
|
+
*.credentials.yml
|
|
28
|
+
*.session.yaml
|
|
29
|
+
*.session.yml
|
|
30
|
+
*.pem
|
|
31
|
+
*.key
|
|
32
|
+
.DS_Store
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
3.14.8
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# Development
|
|
2
|
+
|
|
3
|
+
This repository builds and tests `ipguard-api` independently. It does not require Home Assistant, a workspace member, or a sibling checkout. [pyproject.toml](pyproject.toml) declares the runtime requirements and development tools. [uv.lock](uv.lock) records the resolved versions and hashes. Use the interpreter selected by [.python-version](.python-version). Use the `uv` version pinned in the [checks workflow](.github/workflows/checks.yml).
|
|
4
|
+
|
|
5
|
+
## Local checks
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
uv sync --locked
|
|
9
|
+
uv run --no-sync ruff check .
|
|
10
|
+
uv run --no-sync ruff format --check .
|
|
11
|
+
uv run --no-sync mypy
|
|
12
|
+
uv run --no-sync pytest
|
|
13
|
+
uv run --no-sync python -m scripts.release_metadata
|
|
14
|
+
uv build --build-constraints build-constraints.txt --require-hashes
|
|
15
|
+
uv run --no-sync python -m scripts.release_metadata --dist dist --write-checksums
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Use a clean `dist` directory when you build a different version. Validation rejects stale or unexpected archives. The development environment and caches are local and ignored.
|
|
19
|
+
|
|
20
|
+
`conftest.py` guards ordinary Python sockets, DNS resolution, and native ZeroMQ connections. It permits only loopback or in-process fixtures. Tests use synthetic accounts. Tests must not contact the provider, send verification messages, replace a mobile installation, answer a call, or actuate a physical door. Secure transport tests require native ZeroMQ CURVE support.
|
|
21
|
+
|
|
22
|
+
The package tests build the wheel and source distribution in temporary directories. They verify exact contents and metadata. They also test rejection of altered or extra files, unsafe paths, links, changed checksums, and invalid release identity. Network-guard tests verify the Python and native ZeroMQ restrictions. CI also runs the pinned `actionlint` workflow validator.
|
|
23
|
+
|
|
24
|
+
## Package boundaries
|
|
25
|
+
|
|
26
|
+
The explicit Hatch `only-include` lists in [pyproject.toml](pyproject.toml) are the authoritative package allowlists. The wheel contains only `ipguard_api`, its type marker, the license, and generated metadata. The source distribution also contains the development-only test harness (`conftest.py`), package validators, usage and development documentation, and reproducible environment inputs. It does not contain local credentials, caches, application artifacts, or integration files.
|
|
27
|
+
|
|
28
|
+
[scripts/packaging_policy.py](scripts/packaging_policy.py) checks all allowed source bytes. It rejects stray or missing source files, symbolic links, unsafe archive paths, and duplicate members. Wheel RECORD hashes and sizes must describe exactly the approved payload. [scripts/release_metadata.py](scripts/release_metadata.py) also checks the distribution identity, runtime requirements, README, license, URLs, Python requirements, and pure-Python wheel tags against the checked source. Both archives must match their SHA-256 manifest.
|
|
29
|
+
|
|
30
|
+
[build-constraints.txt](build-constraints.txt) pins and hashes the complete isolated Hatch build dependency set. It must agree exactly with the lockfile and the build backend declaration. When you change the backend, review and update all three together. Do not relax an allowlist or hash check to make an unexpected build pass.
|
|
31
|
+
|
|
32
|
+
## Publishing to PyPI
|
|
33
|
+
|
|
34
|
+
The SDK repository is [KennyTangHK/ipguard-api](https://github.com/KennyTangHK/ipguard-api). Its default branch is `master`. Ordinary CI checks run on pushes to `master` and on pull requests.
|
|
35
|
+
|
|
36
|
+
Before the first release, configure PyPI Trusted Publishing for the `ipguard-api` project. Use repository owner `KennyTangHK`, repository name `ipguard-api`, workflow filename `publish.yml`, and GitHub environment `pypi`. Configure the matching GitHub environment and its release approval and tag rules as appropriate. See [PyPI publisher setup](https://docs.pypi.org/trusted-publishers/adding-a-publisher/) or [creating a new PyPI project](https://docs.pypi.org/trusted-publishers/creating-a-project-through-oidc/). Confirm package-name availability and publisher ownership in the target account.
|
|
37
|
+
|
|
38
|
+
When you have explicit authorization to release SDK changes:
|
|
39
|
+
|
|
40
|
+
1. Set the intended version in [pyproject.toml](pyproject.toml). Run `uv lock` and the local checks. Use `X.Y.ZbN` for beta releases or `X.Y.Z` for stable releases. Review the lockfile change. A package version change must not silently upgrade external dependencies.
|
|
41
|
+
2. Commit and push the reviewed changes to `master` in the independent SDK repository.
|
|
42
|
+
3. Push the matching `vX.Y.ZbN` or `vX.Y.Z` tag. The tag must match the committed package version exactly. Do not move or reuse a published tag or version.
|
|
43
|
+
|
|
44
|
+
The [publication workflow](.github/workflows/publish.yml) calls the checks workflow for the tagged commit. It downloads the three checked assets from that run. It then validates the event, tag, clean checkout, tested commit, remote tag, archive payloads, and hashes again. It stages only the two validated distribution archives for upload.
|
|
45
|
+
|
|
46
|
+
The separate publishing job uses the `pypi` environment. Only this job receives `id-token: write`. Ordinary checks have read-only repository access. [PyPA's publishing action](https://github.com/pypa/gh-action-pypi-publish) uses [Trusted Publishing](https://docs.pypi.org/trusted-publishers/using-a-publisher/) and produces attestations. It does not need a stored PyPI password or API token.
|
|
47
|
+
|
|
48
|
+
If no source changes are necessary, you can rerun a failed run from GitHub Actions or manually dispatch it against the same tag. The workflow rejects branch dispatches. Publication does not skip existing distributions. After an uncertain or partial upload, inspect PyPI before you decide what to release next. A source or workflow fix requires a new version and tag. Published artifacts are never overwritten. Publishing the SDK does not release the separate Home Assistant integration.
|
|
49
|
+
|
|
50
|
+
## Runtime invariants
|
|
51
|
+
|
|
52
|
+
Keep the Android handset profile independent of package releases. Human-readable provider metadata uses the configured Android strings. Preserve opaque identifiers, credentials, and call tokens exactly. Enrollment, resends, and installation replacement must remain explicit. Release operations must check current permission, reject busy or unavailable operations, and never queue or replay a command with an uncertain outcome.
|
|
53
|
+
|
|
54
|
+
Incoming-call callbacks expose only sanitized board information. The SDK is passive by default. An explicit `auto_hangup=True` enables one immediate hangup attempt with cause zero after notification. The SDK does not retain media offers, answer calls, or implement media transport. Disconnect and shutdown cancel owned work. The SDK never replays uncertain attempts.
|
|
55
|
+
|
|
56
|
+
Store credentials in the consumer's private session storage. Keep raw packets, session contents, arbitrary provider errors, call tokens, and media data out of logs, tracebacks, and callback data. [README.md](README.md) and [API usage](docs/USAGE.md) document the plaintext enrollment stage and other protocol limits. Synthetic tests show local client behavior. They do not show current provider acceptance, account-wide routing guarantees, or physical door outcomes.
|
|
@@ -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,47 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: ipguard-api
|
|
3
|
+
Version: 0.1.0b6
|
|
4
|
+
Summary: Typed asynchronous client for the IPGUARD cloud service
|
|
5
|
+
Project-URL: Repository, https://github.com/KennyTangHK/ipguard-api
|
|
6
|
+
Project-URL: Issues, https://github.com/KennyTangHK/ipguard-api/issues
|
|
7
|
+
Project-URL: Documentation, https://github.com/KennyTangHK/ipguard-api/blob/master/docs/USAGE.md
|
|
8
|
+
License-Expression: Apache-2.0
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
12
|
+
Classifier: Typing :: Typed
|
|
13
|
+
Requires-Python: <3.15,>=3.14.2
|
|
14
|
+
Requires-Dist: pyzmq<28,>=27.2.0
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
|
|
17
|
+
# ipguard-api
|
|
18
|
+
|
|
19
|
+
Source repository: [KennyTangHK/ipguard-api](https://github.com/KennyTangHK/ipguard-api). The default branch is `master`.
|
|
20
|
+
|
|
21
|
+
**Beta software.** This software is not a stable release.
|
|
22
|
+
|
|
23
|
+
This is an independent community project. It is not affiliated with, sponsored by, or endorsed by IPGUARD, NACD, or Noralsy.
|
|
24
|
+
|
|
25
|
+
Use this software lawfully. Use it only with your own authorized account and with buildings or doors that you have permission to access and control. Do not use it for unauthorized access or abuse.
|
|
26
|
+
|
|
27
|
+
**Use at your own risk.** To the extent permitted by applicable law, the software is provided without warranty. Its authors and contributors accept no responsibility or liability for its use. The warranty and liability limits in the [Apache-2.0 license](LICENSE) apply.
|
|
28
|
+
|
|
29
|
+
`ipguard-api` is a typed asynchronous Python library for an authorized IPGUARD cloud account. It supports phone and email enrollment, ZeroMQ CURVE connections, relay discovery, incoming-call callbacks, and explicit remote release commands. It does not depend on Home Assistant.
|
|
30
|
+
|
|
31
|
+
**Video calling and camera streaming are not supported.** By default, incoming calls give passive notifications. The library does not retain media offers or answer calls. To attempt one immediate hangup after the notification, set `auto_hangup=True` for the client. This attempt is intended to trigger carrier-call fallback sooner. The provider and account configuration determine the actual routing and timing.
|
|
32
|
+
|
|
33
|
+
For enrollment, saved sessions, event subscriptions, and command errors, see [API usage](docs/USAGE.md). For tests and release builds, see [Development](DEVELOPMENT.md).
|
|
34
|
+
|
|
35
|
+
The [package metadata](pyproject.toml) defines the Python and dependency requirements. The [lockfile](uv.lock) records the resolved dependencies. The PyPI package is `ipguard-api`; the import package is `ipguard_api`. The separate Home Assistant integration is at [hass-ipguard](https://github.com/KennyTangHK/hass-ipguard).
|
|
36
|
+
|
|
37
|
+
The [protocol implementation](src/ipguard_api/protocol.py) defines the protocol behavior. The [handset profile](src/ipguard_api/models.py) defines the client metadata values. Direct enrollment uses unencrypted TCP to retrieve the server public key. The authenticated channel then uses CURVE. A board acknowledgement does not show the physical state of a door. Bluetooth, SIP, pickup, and media transport and decoding are outside the scope of this library. Local fixtures test client behavior with synthetic accounts. They do not show current provider acceptance or physical door outcomes.
|
|
38
|
+
|
|
39
|
+
## Installation
|
|
40
|
+
|
|
41
|
+
After a release is published to PyPI, install the package:
|
|
42
|
+
|
|
43
|
+
```sh
|
|
44
|
+
python -m pip install --pre ipguard-api
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
The `--pre` option permits beta releases. To install this checkout, use `python -m pip install .`. For a locked test environment, see the [development guide](DEVELOPMENT.md). Installation and import do not enroll an account or open a connection.
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# ipguard-api
|
|
2
|
+
|
|
3
|
+
Source repository: [KennyTangHK/ipguard-api](https://github.com/KennyTangHK/ipguard-api). The default branch is `master`.
|
|
4
|
+
|
|
5
|
+
**Beta software.** This software is not a stable release.
|
|
6
|
+
|
|
7
|
+
This is an independent community project. It is not affiliated with, sponsored by, or endorsed by IPGUARD, NACD, or Noralsy.
|
|
8
|
+
|
|
9
|
+
Use this software lawfully. Use it only with your own authorized account and with buildings or doors that you have permission to access and control. Do not use it for unauthorized access or abuse.
|
|
10
|
+
|
|
11
|
+
**Use at your own risk.** To the extent permitted by applicable law, the software is provided without warranty. Its authors and contributors accept no responsibility or liability for its use. The warranty and liability limits in the [Apache-2.0 license](LICENSE) apply.
|
|
12
|
+
|
|
13
|
+
`ipguard-api` is a typed asynchronous Python library for an authorized IPGUARD cloud account. It supports phone and email enrollment, ZeroMQ CURVE connections, relay discovery, incoming-call callbacks, and explicit remote release commands. It does not depend on Home Assistant.
|
|
14
|
+
|
|
15
|
+
**Video calling and camera streaming are not supported.** By default, incoming calls give passive notifications. The library does not retain media offers or answer calls. To attempt one immediate hangup after the notification, set `auto_hangup=True` for the client. This attempt is intended to trigger carrier-call fallback sooner. The provider and account configuration determine the actual routing and timing.
|
|
16
|
+
|
|
17
|
+
For enrollment, saved sessions, event subscriptions, and command errors, see [API usage](docs/USAGE.md). For tests and release builds, see [Development](DEVELOPMENT.md).
|
|
18
|
+
|
|
19
|
+
The [package metadata](pyproject.toml) defines the Python and dependency requirements. The [lockfile](uv.lock) records the resolved dependencies. The PyPI package is `ipguard-api`; the import package is `ipguard_api`. The separate Home Assistant integration is at [hass-ipguard](https://github.com/KennyTangHK/hass-ipguard).
|
|
20
|
+
|
|
21
|
+
The [protocol implementation](src/ipguard_api/protocol.py) defines the protocol behavior. The [handset profile](src/ipguard_api/models.py) defines the client metadata values. Direct enrollment uses unencrypted TCP to retrieve the server public key. The authenticated channel then uses CURVE. A board acknowledgement does not show the physical state of a door. Bluetooth, SIP, pickup, and media transport and decoding are outside the scope of this library. Local fixtures test client behavior with synthetic accounts. They do not show current provider acceptance or physical door outcomes.
|
|
22
|
+
|
|
23
|
+
## Installation
|
|
24
|
+
|
|
25
|
+
After a release is published to PyPI, install the package:
|
|
26
|
+
|
|
27
|
+
```sh
|
|
28
|
+
python -m pip install --pre ipguard-api
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
The `--pre` option permits beta releases. To install this checkout, use `python -m pip install .`. For a locked test environment, see the [development guide](DEVELOPMENT.md). Installation and import do not enroll an account or open a connection.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# Exact isolated build dependencies from uv.lock. Update and verify together.
|
|
2
|
+
hatchling==1.32.4 --hash=sha256:08ecf7548fb48205e7f213d70c71e67b8271b7242093dc3f1da578b42c734a2c --hash=sha256:c4468f73144c054d2aab4ef0f0378c43b9878bf07f8ffd6b79690e970d375f07
|
|
3
|
+
packaging==26.3 --hash=sha256:94edc256424af38762eb31306eed28beb9f0efc50a8837492c9d6fd6004aed79 --hash=sha256:d7193f7c8e4e93f444fde0262bf90af30e16fa0ad0ad44cb553c87339b23cd1c
|
|
4
|
+
pathspec==1.1.1 --hash=sha256:17db5ecd524104a120e173814c90367a96a98d07c45b2e10c2f3919fff91bf5a --hash=sha256:a00ce642f577bf7f473932318056212bc4f8bfdf53128c78bbd5af0b9b20b189
|
|
5
|
+
pluggy==1.6.0 --hash=sha256:7dcc130b76258d33b90f61b658791dede3486c3e6bfb003ee5c9bfb396dd22f3 --hash=sha256:e920276dd6813095e9377c0bc5566d94c932c33b27a3e3945d8389c374dd4746
|
|
6
|
+
tomlkit==0.15.1 --hash=sha256:177a05aece5a8ca5266fd3c448abb47b8d352f09d477d3ca8332db4d89b24304 --hash=sha256:e25bbf38843005246210a12982776f27f99cb9be67160e14434d0c0d21ee1e97
|
|
7
|
+
trove-classifiers==2026.9.21.13 --hash=sha256:0a9ebc8d4e2f3e8a22848c5258033035bec17a3012ac3fea16dbaa764489eb71 --hash=sha256:8b1ff4f9c191b1040b71c37f1e445ab99732911e3cd91de52838453a854d7a17
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"""Confine Python and native ZeroMQ test traffic to synthetic local fixtures."""
|
|
2
|
+
|
|
3
|
+
import ipaddress
|
|
4
|
+
import re
|
|
5
|
+
import socket
|
|
6
|
+
from collections.abc import Iterator
|
|
7
|
+
from typing import Any
|
|
8
|
+
|
|
9
|
+
import pytest
|
|
10
|
+
import zmq
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def _check_host(host: object) -> None:
|
|
14
|
+
if host == "localhost":
|
|
15
|
+
return
|
|
16
|
+
try:
|
|
17
|
+
if isinstance(host, str) and ipaddress.ip_address(host).is_loopback:
|
|
18
|
+
return
|
|
19
|
+
except ValueError:
|
|
20
|
+
pass
|
|
21
|
+
raise AssertionError("Tests may only use loopback hosts.")
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def _check_address(sock: socket.socket, address: Any) -> None:
|
|
25
|
+
if sock.family == socket.AF_UNIX:
|
|
26
|
+
return
|
|
27
|
+
if not isinstance(address, tuple) or not address:
|
|
28
|
+
raise AssertionError("Tests may only use loopback addresses.")
|
|
29
|
+
_check_host(address[0])
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
@pytest.fixture(autouse=True)
|
|
33
|
+
def prevent_provider_traffic(monkeypatch: pytest.MonkeyPatch) -> Iterator[None]:
|
|
34
|
+
"""Guard native libzmq separately from ordinary Python socket methods."""
|
|
35
|
+
for method in ("connect", "connect_ex", "bind"):
|
|
36
|
+
original = getattr(socket.socket, method)
|
|
37
|
+
|
|
38
|
+
def guarded(
|
|
39
|
+
sock: socket.socket, address: Any, *, _original: Any = original
|
|
40
|
+
) -> Any:
|
|
41
|
+
_check_address(sock, address)
|
|
42
|
+
return _original(sock, address)
|
|
43
|
+
|
|
44
|
+
monkeypatch.setattr(socket.socket, method, guarded)
|
|
45
|
+
sendto = socket.socket.sendto
|
|
46
|
+
|
|
47
|
+
def local_sendto(sock: socket.socket, *args: Any) -> int:
|
|
48
|
+
_check_address(sock, args[-1])
|
|
49
|
+
return sendto(sock, *args)
|
|
50
|
+
|
|
51
|
+
monkeypatch.setattr(socket.socket, "sendto", local_sendto)
|
|
52
|
+
if hasattr(socket.socket, "sendmsg"):
|
|
53
|
+
sendmsg = socket.socket.sendmsg
|
|
54
|
+
|
|
55
|
+
def local_sendmsg(sock: socket.socket, *args: Any) -> int:
|
|
56
|
+
if len(args) >= 4 and args[3] is not None:
|
|
57
|
+
_check_address(sock, args[3])
|
|
58
|
+
return sendmsg(sock, *args)
|
|
59
|
+
|
|
60
|
+
monkeypatch.setattr(socket.socket, "sendmsg", local_sendmsg)
|
|
61
|
+
getaddrinfo = socket.getaddrinfo
|
|
62
|
+
|
|
63
|
+
def local_getaddrinfo(host: Any, *args: Any, **kwargs: Any) -> Any:
|
|
64
|
+
_check_host(host)
|
|
65
|
+
return getaddrinfo(host, *args, **kwargs)
|
|
66
|
+
|
|
67
|
+
monkeypatch.setattr(socket, "getaddrinfo", local_getaddrinfo)
|
|
68
|
+
for method in ("gethostbyname", "gethostbyname_ex", "gethostbyaddr"):
|
|
69
|
+
resolve = getattr(socket, method)
|
|
70
|
+
|
|
71
|
+
def local_resolve(host: Any, *, _resolve: Any = resolve) -> Any:
|
|
72
|
+
_check_host(host)
|
|
73
|
+
return _resolve(host)
|
|
74
|
+
|
|
75
|
+
monkeypatch.setattr(socket, method, local_resolve)
|
|
76
|
+
for method in ("connect", "bind"):
|
|
77
|
+
zmq_original = getattr(zmq.Socket, method)
|
|
78
|
+
|
|
79
|
+
def local_zmq(
|
|
80
|
+
sock: zmq.Socket[Any], endpoint: str, *, _original: Any = zmq_original
|
|
81
|
+
) -> Any:
|
|
82
|
+
if (
|
|
83
|
+
not endpoint.startswith("inproc://")
|
|
84
|
+
and re.fullmatch(
|
|
85
|
+
r"tcp://(?:127\.0\.0\.1|\[::1\]):(?:[0-9]{1,5}|\*)", endpoint
|
|
86
|
+
)
|
|
87
|
+
is None
|
|
88
|
+
):
|
|
89
|
+
raise AssertionError("Protocol tests may only use loopback endpoints.")
|
|
90
|
+
return _original(sock, endpoint)
|
|
91
|
+
|
|
92
|
+
monkeypatch.setattr(zmq.Socket, method, local_zmq)
|
|
93
|
+
yield
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
# API usage
|
|
2
|
+
|
|
3
|
+
Create the asynchronous client in an active event loop. Always close it or use its async context manager. Client construction and cached properties do not send messages. Enrollment and release occur only when you call the related methods.
|
|
4
|
+
|
|
5
|
+
## Enrollment
|
|
6
|
+
|
|
7
|
+
```python
|
|
8
|
+
from ipguard_api import ExistingInstallationError, IpguardClient
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
async def enroll(identifier: str, label: str, read_code):
|
|
12
|
+
async with IpguardClient() as client:
|
|
13
|
+
await client.async_request_verification(identifier, label)
|
|
14
|
+
code = await read_code()
|
|
15
|
+
await client.async_verify_code(code)
|
|
16
|
+
try:
|
|
17
|
+
return await client.async_complete_registration()
|
|
18
|
+
except ExistingInstallationError:
|
|
19
|
+
# Ask the user before explicitly requesting replacement.
|
|
20
|
+
raise
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Use the email address or international phone number registered to the account. The client normalizes phone numbers to the Android API's `00` format. Keep verification codes as strings of six ASCII digits. Include leading zeros. Use a personal name or Android device name as the installation label. The handset model is separate and is fixed to `Pixel 7`.
|
|
24
|
+
|
|
25
|
+
`async_request_verification` requests an SMS or email. It resets the challenge credentials but preserves the identity for the same pending account. A second call explicitly requests a resend. `async_verify_code` validates the code and gets a server public key. `async_complete_registration` performs secure registration, requires fresh configuration and relay inventory, and returns an activated `Session`.
|
|
26
|
+
|
|
27
|
+
If registration would replace an installation, the client raises `ExistingInstallationError`. Replacement can disable the previous installation. After the user gives explicit consent, call `async_complete_registration(replace_existing=True)`. If the connection is interrupted while you wait for consent, do not send another code or replacement command without an explicit call. Enrollment and discovery do not test a physical release.
|
|
28
|
+
|
|
29
|
+
## Saved authorization and updates
|
|
30
|
+
|
|
31
|
+
Store `Session.to_dict()` in private storage. It contains credentials. Its `repr` omits sensitive fields. Use `Session.from_dict(data)` to restore it. Restoration alone does not authenticate the session.
|
|
32
|
+
|
|
33
|
+
```python
|
|
34
|
+
from ipguard_api import IpguardClient, Session
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
async def observe(saved_data, on_snapshot):
|
|
38
|
+
session = Session.from_dict(saved_data)
|
|
39
|
+
async with IpguardClient(session=session) as client:
|
|
40
|
+
unsubscribe = client.subscribe(on_snapshot)
|
|
41
|
+
try:
|
|
42
|
+
await client.async_connect(session)
|
|
43
|
+
return await client.async_get_relays()
|
|
44
|
+
finally:
|
|
45
|
+
unsubscribe()
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
For normal startup, call `async_connect`. This does not request a code or replace an installation. Keep the context open to receive cloud pushes. `subscribe` registers a synchronous event-loop callback and returns an unsubscribe function. Do not block inside a callback.
|
|
49
|
+
|
|
50
|
+
A `ClientSnapshot` contains cached relays, connection and revocation flags, a classified error, and the current session. If credentials change, explicitly serialize the session to save them. `client.connected`, `client.session`, and `client.snapshot` read cached values. Background recovery uses bounded exponential backoff and the saved session. Revocation stops reconnection and requires user-driven enrollment. `async_close` closes sockets, cancels recovery, and clears callbacks. You can call it more than once.
|
|
51
|
+
|
|
52
|
+
## Incoming calls
|
|
53
|
+
|
|
54
|
+
Call `subscribe_calls` before you connect, and keep the client open. It registers a synchronous event-loop callback and returns an unsubscribe function:
|
|
55
|
+
|
|
56
|
+
```python
|
|
57
|
+
from ipguard_api import IncomingCall, IpguardClient, Session
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
async def listen(saved_data, stop):
|
|
61
|
+
def on_call(call: IncomingCall) -> None:
|
|
62
|
+
print(call.board.name if call.board else "Incoming intercom call")
|
|
63
|
+
|
|
64
|
+
session = Session.from_dict(saved_data)
|
|
65
|
+
async with IpguardClient(session=session) as client:
|
|
66
|
+
unsubscribe = client.subscribe_calls(on_call)
|
|
67
|
+
try:
|
|
68
|
+
await client.async_connect(session)
|
|
69
|
+
await stop.wait()
|
|
70
|
+
finally:
|
|
71
|
+
unsubscribe()
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
`IncomingCall` contains only an optional `Board`. The client matches the board by exact identity against the latest cached inventory. Unknown or ambiguous callers still cause a callback, with `board=None`. Malformed or oversized optional board and site labels, and site identities, are omitted. Callback data does not expose call tokens, routing senders, SDP, or media credentials. The client validates and discards media descriptions. Offers must come from the current authenticated transport for an activated installation. The client ignores malformed offers and continues relay updates.
|
|
75
|
+
|
|
76
|
+
Callbacks can arrive before `async_connect` completes, including during reconnection. If your interface is not ready, briefly buffer sanitized notifications. With the default constructor, call receipt does not acknowledge an offer, answer, pick up, hang up, or negotiate media. The client does not use Firebase. Delivery depends on the provider routing the call to the active account connection.
|
|
77
|
+
|
|
78
|
+
The client suppresses repeated offers in a bounded in-memory cache. The cache expires after inactivity. It stays available across reconnects for the same installation. Explicit close or an installation change clears it. The client does not fetch or replay disconnected call history.
|
|
79
|
+
|
|
80
|
+
Video calling and camera streaming are not supported. The SDK has no API to retain offers, answer calls, or manage media sessions. It does not send ring acknowledgements or pickup commands.
|
|
81
|
+
|
|
82
|
+
### Automatic hangup
|
|
83
|
+
|
|
84
|
+
`IpguardClient(auto_hangup=True)` enables one immediate hangup attempt after each fresh, validated incoming-call notification. This is intended to trigger carrier-call fallback sooner. The provider and account configuration determine the actual routing and timing. The standalone SDK defaults to `auto_hangup=False`. In that mode, it gives incoming-call notifications without sending a hangup. Home Assistant has an **Auto hangup** option for each account. It is enabled by default. Find it under **Settings → Devices & services → IPGUARD → Configure**.
|
|
85
|
+
|
|
86
|
+
An attempt requires a current call, connection, and installation. The client skips busy, stale, disconnected, or superseded attempts. Call termination, disconnect, or shutdown cancels pending work. The client does not queue or replay attempts. It does not retry a send with an uncertain outcome. Duplicate suppression stays available across reconnects for the same installation. It does not persist after the client closes or the process restarts. The SDK has no manual hangup or call-answering API.
|
|
87
|
+
|
|
88
|
+
Sanitized DEBUG messages report `IPGUARD auto hangup outcome=attempted`, `sent`, `uncertain`, or `skipped`. `sent` confirms only a local transport write. It does not confirm carrier-call delivery.
|
|
89
|
+
|
|
90
|
+
## Release one relay
|
|
91
|
+
|
|
92
|
+
Select a current `Relay` with `remote_allowed=True` and no pending confirmation. Only for a deliberate user action, call `await client.async_release(relay.board_identity, relay.number)`. The SDK accepts relay numbers from 1 to 3.
|
|
93
|
+
|
|
94
|
+
The SDK checks the current permission and rejects a concurrent release for the same relay. It does not queue actions for a later connection. Success means that the board sent a matching acknowledgement. It does not show whether the door is physically open or closed.
|
|
95
|
+
|
|
96
|
+
`OutcomeUnknownError` means that the command can have reached the board. Report the uncertainty and do not replay the command automatically. `ReleaseRejectedError` reports a matching rejection. `RelayUnavailableError` covers absent or unpermitted relays. `AuthRevokedError` requires enrollment. `ConnectionFailureError` reports ordinary connection failures. All these errors derive from `IpguardError`. Authentication failures derive from `AuthenticationError`.
|
|
97
|
+
|
|
98
|
+
## Transport and logging
|
|
99
|
+
|
|
100
|
+
The default activation endpoint is `tcp://zmq.campiserveur.com:5579`. The default secure messaging endpoint is `tcp://zmq.campiserveur.com:5577`. Activation uses unencrypted TCP, including for retrieval of the server public key. CURVE protects the subsequent authenticated connection. The client does not implement an encrypted enrollment fallback. Do not disable CURVE authentication to work around handshake failures.
|
|
101
|
+
|
|
102
|
+
The constructor accepts test endpoints, `timeout`, `reconnect_delay`, and `max_reconnect_delay`. Saved sessions retain their endpoints.
|
|
103
|
+
|
|
104
|
+
Enable `ipguard_api` at DEBUG level for sanitized stage and event information. Outgoing metadata uses Android app values or mock Android handset details from the [handset profile](../src/ipguard_api/models.py). The [protocol implementation](../src/ipguard_api/protocol.py) validates these values. Do not log raw packets, identifiers, UUIDs, codes, passwords, keys, tokens, or arbitrary server text.
|
|
105
|
+
|
|
106
|
+
The supported timeout range is 0.001–300 seconds. Reconnect delays are 0.001–3,600 seconds. The maximum delay must be at least the initial delay. Routing identities must be valid UTF-8, with a maximum of 255 bytes and no NUL. Service messages are limited to 16 frames and 8 MiB in total. Inventory updates permit a maximum of 256 sites and 1,024 board entries. An oversized inventory update fails as a whole. These limits do not change saved session serialization.
|