-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstate.py
53 lines (42 loc) · 1.3 KB
/
state.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
53
from relays import Relays
import tracker
import os
import json
import logging
logger = logging.getLogger('State')
relays = Relays()
rooms = {}
tmpHold = False
settings = {}
weather = {}
# First, load defaults (or newly added settings
try:
with open('settings.default.json') as df:
settings = json.load(df)
except:
logger.error('Could not load default settings file!')
# Now try and load settings from a saved settings file
try:
with open('settings.json') as f:
settings = {**settings, **json.load(f)}
logger.info('Loaded settings from file:')
logger.info(settings)
except:
logger.warning('Settings file not found. Using default file!')
# Set the current avgTmp to the current setTmp
avgTmp = settings['setTmp']
# Save settings during shutdown!
def saveSettings():
logger.info('Saving settings to file.')
try:
with open('settings.json', 'w') as f:
json.dump(settings, f, indent=2)
except:
logger.error('Could not save settings to file!')
# Insure all relays are turned off if shutting down!
def relaysOff():
logger.info('Turning off all relays!')
relays.fanOff()
relays.heatOff()
relays.coolOff()
shutdownHandlers = [saveSettings, relaysOff, tracker.shutdown]