-
Notifications
You must be signed in to change notification settings - Fork 1
/
advance.py
52 lines (45 loc) · 1.63 KB
/
advance.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
49
50
51
52
#!/usr/bin/python3
from wiserHeatingAPI import wiserHub
import json
import sys
import logging
logging.basicConfig(stream=sys.stdout, level=logging.INFO)
#logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
_LOGGER = logging.getLogger(__name__)
# the command line parameter is the name of the room that you want to advance or All for all rooms
# quote any room names with spaces in them eg "Bed 3"
# Get Wiser Parameters from keyfile
try:
with open('wiserkeys.params', 'r') as f:
data = f.read().split('\n')
except FileNotFoundError as e:
_LOGGER.info("{}, {}/{}".format(e.strerror, 'wiserkeys.params', keyfile) )
else:
if len(sys.argv) > 1:
adv_room = sys.argv[1]
else:
_LOGGER.info("No room specified")
sys. exit()
wiserkey=""
wiserip=""
for lines in data:
line=lines.split('=')
if line[0] == 'wiserkey':
wiserkey = line[1]
if line[0] == 'wiserhubip':
wiserip = line[1]
try:
try:
wh = wiserHub.wiserHub(wiserip,wiserkey)
except:
_LOGGER.info("Unable to connect to Wiser Hub {}".format(sys.exc_info()[1]) )
_LOGGER.info(' Wiser Hub IP= {}\n WiserKey= {}'.format(wiserip,wiserkey))
else:
for room in wh.getRooms():
id = room.get("id")
name = room.get("Name")
_LOGGER.info("# {} - {}".format(id,name))
if adv_room == "All" or name == adv_room:
wh.setRoomScheduleAdvance(id)
except json.decoder.JSONDecodeError as ex:
_LOGGER.info("JSON Exception")