Repository navigation
Expand file tree
/
Copy pathmain.py
More file actions
37 lines (31 loc) · 1.73 KB
/
Copy pathmain.py
File metadata and controls
37 lines (31 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
"""List your hubs and shockers, and the shockers other people shared with you."""
import os
import sys
from openshock import OpenShockClient, unwrap
from openshock.rest.api.meta import version_get_backend_info
from openshock.rest.api.shockers import shocker_list_shared_shockers, shocker_list_shockers
from openshock.rest.api.users import users_get_self
from openshock.rest.types import Unset
APP_NAME = "OpenShock.SDK.Python.Examples"
APP_VERSION = "1.0.0"
BASE_URL = os.environ.get("OPENSHOCK_API_URL", "https://api.openshock.app")
API_TOKEN = os.environ.get("OPENSHOCK_API_TOKEN") or sys.exit(
"Set OPENSHOCK_API_TOKEN to an API token from https://openshock.app (Settings > API Tokens)."
)
with OpenShockClient(API_TOKEN, base_url=BASE_URL, app_name=APP_NAME, app_version=APP_VERSION) as client:
info = unwrap(version_get_backend_info.sync(client=client)).data
me = unwrap(users_get_self.sync(client=client)).data
print(f"OpenShock {info.version}, signed in as {me.name}\n")
print("Own:")
for hub in unwrap(shocker_list_shockers.sync(client=client)).data:
print(f" {hub.name} ({hub.id})")
for shocker in hub.shockers:
paused = " [paused]" if shocker.is_paused else ""
print(f" {shocker.name} {shocker.model} ({shocker.id}){paused}")
print("\nShared with me:")
for owner in unwrap(shocker_list_shared_shockers.sync(client=client)).data:
for shared_hub in owner.devices:
for shared in shared_hub.shockers:
intensity = shared.limits.intensity
limit = 100 if intensity is None or isinstance(intensity, Unset) else intensity
print(f" {owner.name} / {shared_hub.name} / {shared.name} max {limit}% ({shared.id})")