-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththermostat.py
38 lines (26 loc) · 854 Bytes
/
thermostat.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
"""Thermostat support via Google Assistant and Assistant Relay.
Get and install Assistant Relay (https://assistantrelay.com)
"""
import device
import gin
import requests
import os
from pathlib import Path
@gin.configurable
class Thermostat(device.Device):
def __init__(self, url:str, username:str):
super(Thermostat, self).__init__('thermostat')
self._url = url
self._username = username
def _tell(self, command:str):
msg = dict(
user=self._username,
command=command
)
response = requests.post(url=self._url, json=msg)
return response.ok
def turn_off(self):
return self._tell(command='set all thermostats to off')
def turn_on(self):
return self._tell(command='set all thermostats to on')
gin.parse_config_file(os.path.join(str(Path.home()), '.autohome/thermostat.gin'))