-
Notifications
You must be signed in to change notification settings - Fork 23
/
time_rule.py
36 lines (23 loc) · 841 Bytes
/
time_rule.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
import datetime
import time
import HABApp
class MyRule(HABApp.Rule):
def __init__(self):
super().__init__()
self.run_on_day_of_week(
datetime.time(14, 34, 20),
weekdays=['Mo'],
callback=self.run_mondays
)
self.run_every(datetime.timedelta(seconds=5), 3, self.run_every_3s, 'arg 1', asdf='kwarg 1')
self.run_on_workdays(datetime.time( 15, 00), self.run_workdays)
self.run_on_weekends(datetime.time( 15, 00), self.run_weekends)
def run_every_3s(self, arg, asdf = None):
print( f'run_ever_3s: {time.time():.3f} : {arg}, {asdf}')
def run_mondays(self):
print('Today is monday!')
def run_workdays(self):
print('Today is a workday!')
def run_weekends(self):
print('Today is weekend!')
a = MyRule()