forked from jabesq/netatmo-api-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path__main__.py
More file actions
73 lines (59 loc) · 1.91 KB
/
Copy path__main__.py
File metadata and controls
73 lines (59 loc) · 1.91 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
from .auth import ClientAuth
from .camera import CameraData
from .exceptions import NoDevice
from .public_data import PublicData
from .thermostat import HomeData
from .weather_station import WeatherStationData
def main():
import sys
try:
import os
if (
os.environ["CLIENT_ID"]
and os.environ["CLIENT_SECRET"]
and os.environ["USERNAME"]
and os.environ["PASSWORD"]
):
CLIENT_ID = os.environ["CLIENT_ID"]
CLIENT_SECRET = os.environ["CLIENT_SECRET"]
USERNAME = os.environ["USERNAME"]
PASSWORD = os.environ["PASSWORD"]
except KeyError:
sys.stderr.write(
"No credentials passed to pyatmo.py (client_id, client_secret, username, password)\n"
)
sys.exit(1)
authorization = ClientAuth(
clientId=CLIENT_ID,
clientSecret=CLIENT_SECRET,
username=USERNAME,
password=PASSWORD,
scope=(
"read_station read_camera access_camera read_thermostat "
"write_thermostat read_presence access_presence read_homecoach "
"read_smokedetector"
),
)
try:
WeatherStationData(authorization)
except NoDevice:
if sys.stdout.isatty():
print("pyatmo.py : warning, no weather station available for testing")
try:
CameraData(authorization)
except NoDevice:
if sys.stdout.isatty():
print("pyatmo.py : warning, no camera available for testing")
try:
HomeData(authorization)
except NoDevice:
if sys.stdout.isatty():
print("pyatmo.py : warning, no thermostat available for testing")
PublicData(authorization)
# If we reach this line, all is OK
# If launched interactively, display OK message
if sys.stdout.isatty():
print("pyatmo: OK")
sys.exit(0)
if __name__ == "__main__":
main()