pygemstone 0.0.1__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.
- pygemstone-0.0.1/LICENSE +21 -0
- pygemstone-0.0.1/PKG-INFO +150 -0
- pygemstone-0.0.1/README.md +123 -0
- pygemstone-0.0.1/pyproject.toml +65 -0
- pygemstone-0.0.1/setup.cfg +4 -0
- pygemstone-0.0.1/src/pygemstone/__init__.py +71 -0
- pygemstone-0.0.1/src/pygemstone/__main__.py +100 -0
- pygemstone-0.0.1/src/pygemstone/appsync.py +393 -0
- pygemstone-0.0.1/src/pygemstone/auth.py +202 -0
- pygemstone-0.0.1/src/pygemstone/client.py +416 -0
- pygemstone-0.0.1/src/pygemstone/const.py +47 -0
- pygemstone-0.0.1/src/pygemstone/device.py +66 -0
- pygemstone-0.0.1/src/pygemstone/errors.py +40 -0
- pygemstone-0.0.1/src/pygemstone/models.py +648 -0
- pygemstone-0.0.1/src/pygemstone/py.typed +0 -0
- pygemstone-0.0.1/src/pygemstone.egg-info/PKG-INFO +150 -0
- pygemstone-0.0.1/src/pygemstone.egg-info/SOURCES.txt +22 -0
- pygemstone-0.0.1/src/pygemstone.egg-info/dependency_links.txt +1 -0
- pygemstone-0.0.1/src/pygemstone.egg-info/entry_points.txt +2 -0
- pygemstone-0.0.1/src/pygemstone.egg-info/requires.txt +11 -0
- pygemstone-0.0.1/src/pygemstone.egg-info/top_level.txt +1 -0
- pygemstone-0.0.1/tests/test_appsync.py +240 -0
- pygemstone-0.0.1/tests/test_client.py +565 -0
- pygemstone-0.0.1/tests/test_models.py +536 -0
pygemstone-0.0.1/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Stefan Slivinski
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pygemstone
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Python library for Gemstone Lights permanent-Christmas-lights controllers (AWS-backed cloud API)
|
|
5
|
+
Author-email: Stefan Slivinski <sslivins@gmail.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/sslivins/pygemstone
|
|
8
|
+
Project-URL: Bug Tracker, https://github.com/sslivins/pygemstone/issues
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Classifier: Topic :: Home Automation
|
|
13
|
+
Requires-Python: >=3.11
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
License-File: LICENSE
|
|
16
|
+
Requires-Dist: aiohttp>=3.11.12
|
|
17
|
+
Requires-Dist: pycognito>=2024.5.1
|
|
18
|
+
Provides-Extra: tests
|
|
19
|
+
Requires-Dist: pytest>=8.3.4; extra == "tests"
|
|
20
|
+
Requires-Dist: pytest-asyncio>=0.25.3; extra == "tests"
|
|
21
|
+
Requires-Dist: aioresponses>=0.7.8; extra == "tests"
|
|
22
|
+
Requires-Dist: python-dotenv>=1.0.1; extra == "tests"
|
|
23
|
+
Requires-Dist: pytest-cov>=5.0.0; extra == "tests"
|
|
24
|
+
Requires-Dist: ruff>=0.6.0; extra == "tests"
|
|
25
|
+
Requires-Dist: mypy>=1.10.0; extra == "tests"
|
|
26
|
+
Dynamic: license-file
|
|
27
|
+
|
|
28
|
+
# pygemstone
|
|
29
|
+
|
|
30
|
+
[](https://pypi.org/project/pygemstone/)
|
|
31
|
+
[](https://pypi.org/project/pygemstone/)
|
|
32
|
+
[](https://github.com/sslivins/pygemstone/blob/main/LICENSE)
|
|
33
|
+
|
|
34
|
+
Standalone Python library for **Gemstone Lights** permanent-Christmas-light
|
|
35
|
+
controllers.
|
|
36
|
+
|
|
37
|
+
Gemstone's mobile app talks to an AWS Amplify backend
|
|
38
|
+
([Cognito](https://aws.amazon.com/cognito/) +
|
|
39
|
+
[API Gateway](https://aws.amazon.com/api-gateway/) +
|
|
40
|
+
[AppSync](https://aws.amazon.com/appsync/)) in `us-west-2`, so this library
|
|
41
|
+
is essentially:
|
|
42
|
+
|
|
43
|
+
- a Cognito SRP login wrapper (delegated to
|
|
44
|
+
[`pycognito`](https://pypi.org/project/pycognito/))
|
|
45
|
+
- an aiohttp REST client for the public endpoints that control the
|
|
46
|
+
lights (`/deviceControl/onState`, `/deviceControl/play/pattern`, etc.)
|
|
47
|
+
|
|
48
|
+
> **Status:** alpha — under active reverse-engineering of the iOS
|
|
49
|
+
> `com.gemstone.lights` app. APIs will change.
|
|
50
|
+
|
|
51
|
+
## Features
|
|
52
|
+
|
|
53
|
+
- Async login / token refresh (via Cognito User Pool SRP)
|
|
54
|
+
- **Account & home group:**
|
|
55
|
+
- `account_profile()` — your user profile
|
|
56
|
+
- `homegroups()` / `homegroup_users(hg)`
|
|
57
|
+
- `invitations(status="pending")` — pending invites (raw dict; schema unknown)
|
|
58
|
+
- **Devices:**
|
|
59
|
+
- `devices(hg)` — list controllers
|
|
60
|
+
- `device_state(id)` / `set_on_state(id, on)` / `play_pattern(id, p)`
|
|
61
|
+
- `device_groups(hg)` — multi-device zones (raw dict; schema unknown)
|
|
62
|
+
- **Pattern catalogue:**
|
|
63
|
+
- `folders()` / `folder_patterns(page=N)` / `save_folder(id, body)`
|
|
64
|
+
- `swatches()` — colour palettes
|
|
65
|
+
- `downloadable_folders(page=N)` / `downloadable_patterns(page=N)` — Gemstone-curated catalogue
|
|
66
|
+
- **Autopilot / scheduling:**
|
|
67
|
+
- `events_settings(hg)` — daily on/off window + enabled categories
|
|
68
|
+
- `subscribed_events(hg, page=N)` — date-bound holiday/event subscriptions
|
|
69
|
+
- `events_categories()` — full catalogue of holiday / sport / event categories
|
|
70
|
+
- **Timers:**
|
|
71
|
+
- `timers_by_homegroup(hg)` — scheduled on/off timers with optional pattern
|
|
72
|
+
- **Misc:**
|
|
73
|
+
- `announcements()` — in-app announcements
|
|
74
|
+
|
|
75
|
+
## A note on AppSync (real-time)
|
|
76
|
+
|
|
77
|
+
The library ships an AppSync GraphQL HTTP + WebSocket transport
|
|
78
|
+
(`pygemstone.appsync.AppSyncClient`), but **two iOS-app captures show
|
|
79
|
+
the official app never opens a GraphQL connection** — only
|
|
80
|
+
unauthenticated `/ping` healthchecks. State updates propagate via REST
|
|
81
|
+
polling of `/deviceControl/currentlyPlaying`. The AppSync auth scheme
|
|
82
|
+
is therefore unknown and the transport is currently un-runnable
|
|
83
|
+
against the real backend; it's kept as scaffolding for if Gemstone
|
|
84
|
+
ever flips real-time on.
|
|
85
|
+
|
|
86
|
+
## Planned
|
|
87
|
+
|
|
88
|
+
- Cognito global sign-out (currently only clears local tokens)
|
|
89
|
+
- Schedule/event subscribe + unsubscribe mutations
|
|
90
|
+
- Timer create / update / delete (only list is currently captured)
|
|
91
|
+
|
|
92
|
+
## Installation
|
|
93
|
+
|
|
94
|
+
```
|
|
95
|
+
pip install pygemstone
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## Usage
|
|
99
|
+
|
|
100
|
+
```python
|
|
101
|
+
import asyncio
|
|
102
|
+
from pygemstone import GemstoneClient
|
|
103
|
+
|
|
104
|
+
async def main():
|
|
105
|
+
async with GemstoneClient("you@example.com", "...") as gc:
|
|
106
|
+
await gc.login()
|
|
107
|
+
for group in await gc.homegroups():
|
|
108
|
+
print(group.name)
|
|
109
|
+
for device in await gc.devices(group.id):
|
|
110
|
+
state = await device.refresh()
|
|
111
|
+
print(" ", device.name, "on" if state.on_state else "off")
|
|
112
|
+
if not state.on_state:
|
|
113
|
+
await device.turn_on()
|
|
114
|
+
|
|
115
|
+
asyncio.run(main())
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## CLI
|
|
119
|
+
|
|
120
|
+
A small CLI is provided for manual testing:
|
|
121
|
+
|
|
122
|
+
```
|
|
123
|
+
python -m pygemstone login
|
|
124
|
+
python -m pygemstone list
|
|
125
|
+
python -m pygemstone state <DEVICE_ID>
|
|
126
|
+
python -m pygemstone on <DEVICE_ID>
|
|
127
|
+
python -m pygemstone off <DEVICE_ID>
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
Credentials are read from `GEMSTONE_EMAIL` / `GEMSTONE_PASSWORD` env
|
|
131
|
+
vars, or a `.env` file in the working directory.
|
|
132
|
+
|
|
133
|
+
## Security note
|
|
134
|
+
|
|
135
|
+
Like the other Amplify-based IoT services, Gemstone's Cognito user pool
|
|
136
|
+
id and app client id are public values that any decompiled IPA / packet
|
|
137
|
+
capture exposes — they're shipped in [`const.py`](src/pygemstone/const.py)
|
|
138
|
+
as defaults. Do **not** commit credential files, JWT tokens, or
|
|
139
|
+
mitmproxy `.flows` files.
|
|
140
|
+
|
|
141
|
+
## Reverse-engineering notes
|
|
142
|
+
|
|
143
|
+
The endpoint catalogue was derived from a `mitmproxy --mode wireguard`
|
|
144
|
+
capture of the official iOS app. Notes are kept private (the capture
|
|
145
|
+
contains a live Cognito session); the public endpoint shape is in
|
|
146
|
+
[`const.py`](src/pygemstone/const.py).
|
|
147
|
+
|
|
148
|
+
## License
|
|
149
|
+
|
|
150
|
+
MIT — see [`LICENSE`](LICENSE).
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
# pygemstone
|
|
2
|
+
|
|
3
|
+
[](https://pypi.org/project/pygemstone/)
|
|
4
|
+
[](https://pypi.org/project/pygemstone/)
|
|
5
|
+
[](https://github.com/sslivins/pygemstone/blob/main/LICENSE)
|
|
6
|
+
|
|
7
|
+
Standalone Python library for **Gemstone Lights** permanent-Christmas-light
|
|
8
|
+
controllers.
|
|
9
|
+
|
|
10
|
+
Gemstone's mobile app talks to an AWS Amplify backend
|
|
11
|
+
([Cognito](https://aws.amazon.com/cognito/) +
|
|
12
|
+
[API Gateway](https://aws.amazon.com/api-gateway/) +
|
|
13
|
+
[AppSync](https://aws.amazon.com/appsync/)) in `us-west-2`, so this library
|
|
14
|
+
is essentially:
|
|
15
|
+
|
|
16
|
+
- a Cognito SRP login wrapper (delegated to
|
|
17
|
+
[`pycognito`](https://pypi.org/project/pycognito/))
|
|
18
|
+
- an aiohttp REST client for the public endpoints that control the
|
|
19
|
+
lights (`/deviceControl/onState`, `/deviceControl/play/pattern`, etc.)
|
|
20
|
+
|
|
21
|
+
> **Status:** alpha — under active reverse-engineering of the iOS
|
|
22
|
+
> `com.gemstone.lights` app. APIs will change.
|
|
23
|
+
|
|
24
|
+
## Features
|
|
25
|
+
|
|
26
|
+
- Async login / token refresh (via Cognito User Pool SRP)
|
|
27
|
+
- **Account & home group:**
|
|
28
|
+
- `account_profile()` — your user profile
|
|
29
|
+
- `homegroups()` / `homegroup_users(hg)`
|
|
30
|
+
- `invitations(status="pending")` — pending invites (raw dict; schema unknown)
|
|
31
|
+
- **Devices:**
|
|
32
|
+
- `devices(hg)` — list controllers
|
|
33
|
+
- `device_state(id)` / `set_on_state(id, on)` / `play_pattern(id, p)`
|
|
34
|
+
- `device_groups(hg)` — multi-device zones (raw dict; schema unknown)
|
|
35
|
+
- **Pattern catalogue:**
|
|
36
|
+
- `folders()` / `folder_patterns(page=N)` / `save_folder(id, body)`
|
|
37
|
+
- `swatches()` — colour palettes
|
|
38
|
+
- `downloadable_folders(page=N)` / `downloadable_patterns(page=N)` — Gemstone-curated catalogue
|
|
39
|
+
- **Autopilot / scheduling:**
|
|
40
|
+
- `events_settings(hg)` — daily on/off window + enabled categories
|
|
41
|
+
- `subscribed_events(hg, page=N)` — date-bound holiday/event subscriptions
|
|
42
|
+
- `events_categories()` — full catalogue of holiday / sport / event categories
|
|
43
|
+
- **Timers:**
|
|
44
|
+
- `timers_by_homegroup(hg)` — scheduled on/off timers with optional pattern
|
|
45
|
+
- **Misc:**
|
|
46
|
+
- `announcements()` — in-app announcements
|
|
47
|
+
|
|
48
|
+
## A note on AppSync (real-time)
|
|
49
|
+
|
|
50
|
+
The library ships an AppSync GraphQL HTTP + WebSocket transport
|
|
51
|
+
(`pygemstone.appsync.AppSyncClient`), but **two iOS-app captures show
|
|
52
|
+
the official app never opens a GraphQL connection** — only
|
|
53
|
+
unauthenticated `/ping` healthchecks. State updates propagate via REST
|
|
54
|
+
polling of `/deviceControl/currentlyPlaying`. The AppSync auth scheme
|
|
55
|
+
is therefore unknown and the transport is currently un-runnable
|
|
56
|
+
against the real backend; it's kept as scaffolding for if Gemstone
|
|
57
|
+
ever flips real-time on.
|
|
58
|
+
|
|
59
|
+
## Planned
|
|
60
|
+
|
|
61
|
+
- Cognito global sign-out (currently only clears local tokens)
|
|
62
|
+
- Schedule/event subscribe + unsubscribe mutations
|
|
63
|
+
- Timer create / update / delete (only list is currently captured)
|
|
64
|
+
|
|
65
|
+
## Installation
|
|
66
|
+
|
|
67
|
+
```
|
|
68
|
+
pip install pygemstone
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Usage
|
|
72
|
+
|
|
73
|
+
```python
|
|
74
|
+
import asyncio
|
|
75
|
+
from pygemstone import GemstoneClient
|
|
76
|
+
|
|
77
|
+
async def main():
|
|
78
|
+
async with GemstoneClient("you@example.com", "...") as gc:
|
|
79
|
+
await gc.login()
|
|
80
|
+
for group in await gc.homegroups():
|
|
81
|
+
print(group.name)
|
|
82
|
+
for device in await gc.devices(group.id):
|
|
83
|
+
state = await device.refresh()
|
|
84
|
+
print(" ", device.name, "on" if state.on_state else "off")
|
|
85
|
+
if not state.on_state:
|
|
86
|
+
await device.turn_on()
|
|
87
|
+
|
|
88
|
+
asyncio.run(main())
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## CLI
|
|
92
|
+
|
|
93
|
+
A small CLI is provided for manual testing:
|
|
94
|
+
|
|
95
|
+
```
|
|
96
|
+
python -m pygemstone login
|
|
97
|
+
python -m pygemstone list
|
|
98
|
+
python -m pygemstone state <DEVICE_ID>
|
|
99
|
+
python -m pygemstone on <DEVICE_ID>
|
|
100
|
+
python -m pygemstone off <DEVICE_ID>
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
Credentials are read from `GEMSTONE_EMAIL` / `GEMSTONE_PASSWORD` env
|
|
104
|
+
vars, or a `.env` file in the working directory.
|
|
105
|
+
|
|
106
|
+
## Security note
|
|
107
|
+
|
|
108
|
+
Like the other Amplify-based IoT services, Gemstone's Cognito user pool
|
|
109
|
+
id and app client id are public values that any decompiled IPA / packet
|
|
110
|
+
capture exposes — they're shipped in [`const.py`](src/pygemstone/const.py)
|
|
111
|
+
as defaults. Do **not** commit credential files, JWT tokens, or
|
|
112
|
+
mitmproxy `.flows` files.
|
|
113
|
+
|
|
114
|
+
## Reverse-engineering notes
|
|
115
|
+
|
|
116
|
+
The endpoint catalogue was derived from a `mitmproxy --mode wireguard`
|
|
117
|
+
capture of the official iOS app. Notes are kept private (the capture
|
|
118
|
+
contains a live Cognito session); the public endpoint shape is in
|
|
119
|
+
[`const.py`](src/pygemstone/const.py).
|
|
120
|
+
|
|
121
|
+
## License
|
|
122
|
+
|
|
123
|
+
MIT — see [`LICENSE`](LICENSE).
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# pyproject.toml
|
|
2
|
+
|
|
3
|
+
[build-system]
|
|
4
|
+
requires = ["setuptools>=61.0", "wheel"]
|
|
5
|
+
build-backend = "setuptools.build_meta"
|
|
6
|
+
|
|
7
|
+
[project]
|
|
8
|
+
name = "pygemstone"
|
|
9
|
+
version = "0.0.1"
|
|
10
|
+
description = "Python library for Gemstone Lights permanent-Christmas-lights controllers (AWS-backed cloud API)"
|
|
11
|
+
readme = "README.md"
|
|
12
|
+
license = { text = "MIT" }
|
|
13
|
+
authors = [
|
|
14
|
+
{ name = "Stefan Slivinski", email = "sslivins@gmail.com" }
|
|
15
|
+
]
|
|
16
|
+
requires-python = ">=3.11"
|
|
17
|
+
classifiers = [
|
|
18
|
+
"Programming Language :: Python :: 3",
|
|
19
|
+
"License :: OSI Approved :: MIT License",
|
|
20
|
+
"Operating System :: OS Independent",
|
|
21
|
+
"Topic :: Home Automation"
|
|
22
|
+
]
|
|
23
|
+
# Runtime dependencies
|
|
24
|
+
#
|
|
25
|
+
# pycognito provides the AWS Cognito User-Pool SRP auth flow without
|
|
26
|
+
# pulling in the full boto3 stack. It is synchronous; we wrap it via
|
|
27
|
+
# asyncio.to_thread for the async client surface.
|
|
28
|
+
dependencies = [
|
|
29
|
+
"aiohttp>=3.11.12",
|
|
30
|
+
"pycognito>=2024.5.1"
|
|
31
|
+
]
|
|
32
|
+
|
|
33
|
+
[project.optional-dependencies]
|
|
34
|
+
tests = [
|
|
35
|
+
"pytest>=8.3.4",
|
|
36
|
+
"pytest-asyncio>=0.25.3",
|
|
37
|
+
"aioresponses>=0.7.8",
|
|
38
|
+
"python-dotenv>=1.0.1",
|
|
39
|
+
"pytest-cov>=5.0.0",
|
|
40
|
+
"ruff>=0.6.0",
|
|
41
|
+
"mypy>=1.10.0"
|
|
42
|
+
]
|
|
43
|
+
|
|
44
|
+
[project.urls]
|
|
45
|
+
"Homepage" = "https://github.com/sslivins/pygemstone"
|
|
46
|
+
"Bug Tracker" = "https://github.com/sslivins/pygemstone/issues"
|
|
47
|
+
|
|
48
|
+
[project.scripts]
|
|
49
|
+
pygemstone = "pygemstone.__main__:main"
|
|
50
|
+
|
|
51
|
+
[tool.setuptools]
|
|
52
|
+
package-dir = {"" = "src"}
|
|
53
|
+
|
|
54
|
+
[tool.setuptools.packages.find]
|
|
55
|
+
where = ["src"]
|
|
56
|
+
|
|
57
|
+
[tool.mypy]
|
|
58
|
+
python_version = "3.11"
|
|
59
|
+
strict_optional = true
|
|
60
|
+
warn_unused_ignores = true
|
|
61
|
+
ignore_missing_imports = false
|
|
62
|
+
|
|
63
|
+
[[tool.mypy.overrides]]
|
|
64
|
+
module = ["pycognito", "pycognito.*"]
|
|
65
|
+
ignore_missing_imports = true
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"""pygemstone — Python client for Gemstone Lights permanent Christmas lights."""
|
|
2
|
+
|
|
3
|
+
from .appsync import AppSyncClient
|
|
4
|
+
from .auth import GemstoneAuth, TokenSet
|
|
5
|
+
from .client import GemstoneClient
|
|
6
|
+
from .device import Device
|
|
7
|
+
from .errors import (
|
|
8
|
+
GemstoneApiError,
|
|
9
|
+
GemstoneAuthError,
|
|
10
|
+
GemstoneConnectionError,
|
|
11
|
+
GemstoneError,
|
|
12
|
+
GemstoneNotFoundError,
|
|
13
|
+
GemstoneValueError,
|
|
14
|
+
)
|
|
15
|
+
from .models import Device as DeviceRecord
|
|
16
|
+
from .models import (
|
|
17
|
+
AccountProfile,
|
|
18
|
+
Announcement,
|
|
19
|
+
DeviceState,
|
|
20
|
+
DownloadableFolder,
|
|
21
|
+
DownloadablePattern,
|
|
22
|
+
EventCategory,
|
|
23
|
+
EventsScheduleWindow,
|
|
24
|
+
EventsSettings,
|
|
25
|
+
Folder,
|
|
26
|
+
FolderPattern,
|
|
27
|
+
HomeGroup,
|
|
28
|
+
HomeGroupUser,
|
|
29
|
+
Pattern,
|
|
30
|
+
SubscribedEvent,
|
|
31
|
+
Swatch,
|
|
32
|
+
SwatchColor,
|
|
33
|
+
Timer,
|
|
34
|
+
TimerData,
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
__version__ = "0.0.1"
|
|
38
|
+
|
|
39
|
+
__all__ = [
|
|
40
|
+
"GemstoneClient",
|
|
41
|
+
"GemstoneAuth",
|
|
42
|
+
"AppSyncClient",
|
|
43
|
+
"TokenSet",
|
|
44
|
+
"Device",
|
|
45
|
+
"DeviceRecord",
|
|
46
|
+
"DeviceState",
|
|
47
|
+
"HomeGroup",
|
|
48
|
+
"Pattern",
|
|
49
|
+
"AccountProfile",
|
|
50
|
+
"Announcement",
|
|
51
|
+
"DownloadableFolder",
|
|
52
|
+
"DownloadablePattern",
|
|
53
|
+
"EventCategory",
|
|
54
|
+
"EventsScheduleWindow",
|
|
55
|
+
"EventsSettings",
|
|
56
|
+
"Folder",
|
|
57
|
+
"FolderPattern",
|
|
58
|
+
"HomeGroupUser",
|
|
59
|
+
"SubscribedEvent",
|
|
60
|
+
"Swatch",
|
|
61
|
+
"SwatchColor",
|
|
62
|
+
"Timer",
|
|
63
|
+
"TimerData",
|
|
64
|
+
"GemstoneError",
|
|
65
|
+
"GemstoneAuthError",
|
|
66
|
+
"GemstoneApiError",
|
|
67
|
+
"GemstoneConnectionError",
|
|
68
|
+
"GemstoneNotFoundError",
|
|
69
|
+
"GemstoneValueError",
|
|
70
|
+
"__version__",
|
|
71
|
+
]
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"""Tiny CLI for manual smoke-testing pygemstone.
|
|
2
|
+
|
|
3
|
+
Usage:
|
|
4
|
+
|
|
5
|
+
python -m pygemstone login # verify credentials work
|
|
6
|
+
python -m pygemstone list # list home groups + devices
|
|
7
|
+
python -m pygemstone state <DSN> # print currentlyPlaying for a device
|
|
8
|
+
python -m pygemstone on <DSN> # turn a device on
|
|
9
|
+
python -m pygemstone off <DSN> # turn a device off
|
|
10
|
+
python -m pygemstone introspect # dump the AppSync GraphQL schema
|
|
11
|
+
# (json on stdout)
|
|
12
|
+
|
|
13
|
+
Credentials come from ``$GEMSTONE_EMAIL`` and ``$GEMSTONE_PASSWORD``
|
|
14
|
+
or, if absent, a ``.env`` file in the current directory.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
19
|
+
import asyncio
|
|
20
|
+
import json
|
|
21
|
+
import os
|
|
22
|
+
import sys
|
|
23
|
+
|
|
24
|
+
from .client import GemstoneClient
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def _load_env() -> tuple[str, str]:
|
|
28
|
+
email = os.environ.get("GEMSTONE_EMAIL")
|
|
29
|
+
password = os.environ.get("GEMSTONE_PASSWORD")
|
|
30
|
+
if not (email and password):
|
|
31
|
+
try:
|
|
32
|
+
from dotenv import load_dotenv
|
|
33
|
+
|
|
34
|
+
load_dotenv()
|
|
35
|
+
except ImportError:
|
|
36
|
+
pass
|
|
37
|
+
email = os.environ.get("GEMSTONE_EMAIL")
|
|
38
|
+
password = os.environ.get("GEMSTONE_PASSWORD")
|
|
39
|
+
if not (email and password):
|
|
40
|
+
print(
|
|
41
|
+
"Missing GEMSTONE_EMAIL / GEMSTONE_PASSWORD in environment.",
|
|
42
|
+
file=sys.stderr,
|
|
43
|
+
)
|
|
44
|
+
sys.exit(2)
|
|
45
|
+
return email, password
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
async def _run(argv: list[str]) -> int:
|
|
49
|
+
if not argv:
|
|
50
|
+
print(__doc__, file=sys.stderr)
|
|
51
|
+
return 2
|
|
52
|
+
cmd, rest = argv[0], argv[1:]
|
|
53
|
+
email, password = _load_env()
|
|
54
|
+
async with GemstoneClient(email, password) as gc:
|
|
55
|
+
await gc.login()
|
|
56
|
+
if cmd == "login":
|
|
57
|
+
tokens = gc.auth.tokens
|
|
58
|
+
assert tokens is not None
|
|
59
|
+
print(f"OK, access token expires at {tokens.expires_at:.0f}")
|
|
60
|
+
return 0
|
|
61
|
+
if cmd == "list":
|
|
62
|
+
for group in await gc.homegroups():
|
|
63
|
+
print(f"[{group.id}] {group.name} (role={group.role})")
|
|
64
|
+
for dev in await gc.devices(group.id):
|
|
65
|
+
print(f" {dev.id} {dev.name} fw={dev.firmware}")
|
|
66
|
+
return 0
|
|
67
|
+
if cmd == "state" and rest:
|
|
68
|
+
state = await gc.device_state(rest[0])
|
|
69
|
+
pat = state.pattern
|
|
70
|
+
print(
|
|
71
|
+
f"on={state.on_state} "
|
|
72
|
+
f"pattern={(pat.name if pat else None)!r} "
|
|
73
|
+
f"updated={state.last_updated_at}"
|
|
74
|
+
)
|
|
75
|
+
return 0
|
|
76
|
+
if cmd in ("on", "off") and rest:
|
|
77
|
+
tx = await gc.set_on_state(rest[0], cmd == "on")
|
|
78
|
+
print(f"OK tx={tx}")
|
|
79
|
+
return 0
|
|
80
|
+
if cmd == "introspect":
|
|
81
|
+
schema = await gc.introspect_schema()
|
|
82
|
+
if not schema:
|
|
83
|
+
print(
|
|
84
|
+
"Introspection returned no data — the operator may have "
|
|
85
|
+
"disabled it on this AppSync API.",
|
|
86
|
+
file=sys.stderr,
|
|
87
|
+
)
|
|
88
|
+
return 1
|
|
89
|
+
print(json.dumps(schema, indent=2))
|
|
90
|
+
return 0
|
|
91
|
+
print(__doc__, file=sys.stderr)
|
|
92
|
+
return 2
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def main() -> None: # pragma: no cover - entry point
|
|
96
|
+
sys.exit(asyncio.run(_run(sys.argv[1:])))
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
if __name__ == "__main__": # pragma: no cover
|
|
100
|
+
main()
|