-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmower_info.py
executable file
·49 lines (40 loc) · 1.26 KB
/
mower_info.py
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
#!/usr/bin/env python3
# ---------------------------------------------------------------------------
# Mähroboter Infos ermitteln
#
# Mario Zimmermann <[email protected]>
# 2024-06-03
# ---------------------------------------------------------------------------
from configparser import ConfigParser
import requests
import json
# ConfigFile lesen
config_object = ConfigParser()
config_object.read("mower_weather.ini")
HUSQVARNA_API = config_object["HUSQVARNA_API"]
# ---------------------------------------------------------------------------
# Authentifizierung
response = requests.post(
HUSQVARNA_API["auth_url"],
headers = {
"Content-Type": "application/x-www-form-urlencoded"
},
data = {
"grant_type": "client_credentials",
"client_id": HUSQVARNA_API["client_id"],
"client_secret": HUSQVARNA_API["client_secret"]
}
)
data = json.loads(response.text)
access_token = data["access_token"]
# Daten abfragen
response = requests.get(
f"{HUSQVARNA_API['base_url']}/mowers",
headers = {
"Authorization-Provider": "husqvarna",
"Authorization": f"Bearer {access_token}",
"X-Api-Key": HUSQVARNA_API["client_id"]
}
)
data = json.loads(response.text)
print(json.dumps(data, indent=2, ensure_ascii=False))