-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtriggers.py
More file actions
62 lines (45 loc) · 1.7 KB
/
triggers.py
File metadata and controls
62 lines (45 loc) · 1.7 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
__author__ = 'john'
import datetime
import fetcher
import logging
logger = logging.getLogger('pump_control')
class ScheduledTrigger:
def __init__(self):
return
def shouldBeOn(self,config,now):
hour=now.hour
for starthour,endhour in zip(config['scheduledStartHour'],config['scheduledEndHour']):
print starthour,endhour
if hour>=starthour:
if hour < endhour:
logger.info("In scheduled hour, pump should be on")
return True
return False
#fetch wind speed every windpollminutes
class WindTrigger:
def __init__(self,fetcher):
self.fetcher=fetcher
self.lastfetch=False
self.max_speed=0
def shouldBeOn(self,config,now):
d = datetime.timedelta(minutes=config['windpollminutes'])
if self.lastfetch==False or now >= d+self.lastfetch:
logger.info("Fetching wind speed...")
self.max_speed=self.fetcher.get_max_speed(config['onLookbackMins'], now)
logger.info("Max windspeed in last period is %u" % self.max_speed)
self.lastfetch=now
if (self.max_speed >= config['onTriggerSpeed']):
logger.info("Speed is greater than trigger speed %u, pump should be on" % config['onTriggerSpeed'])
return True
return False
class ManualTrigger:
def __init__(self):
return
def shouldBeOn(self,config,now):
if not 'manualEndTime' in config:
return False
manualEndTime=config['manualEndTime']
if now < manualEndTime:
logger.info("Running in manual mode, pump should be on")
return True
return False