-
Notifications
You must be signed in to change notification settings - Fork 0
/
timer.py
64 lines (49 loc) · 1.45 KB
/
timer.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
54
55
56
57
58
59
60
61
62
63
64
'''
Timer settings.
'''
__all__ = (
'AutoOn',
'AutoOff',
)
import logging
from rocket_r60v.exceptions import SettingValueError
from .base import WritableSetting
LOGGER = logging.getLogger(__name__)
class AutoOn(WritableSetting):
'''
The auto on time.
'''
address = 0x51
length = 2
def get(self, *args, **kwargs): # pylint: disable=arguments-differ
'''
Get the time value from the machine.
The time is sent in 4 bytes. The first two bytes are the hour in hex,
the second two bytes are the minute in hex.
:return: The time
:rtype: str
'''
hour, minute = super().get(*args, **kwargs)
return f'{hour:02d}:{minute:02d}'
def set(self, time, *args, **kwargs): # pylint: disable=arguments-differ
'''
Set the time on the machine.
:param str time: The time
'''
try:
hour, minute = str(time).split(':')
hour = int(hour)
minute = int(minute)
assert 0 <= hour <= 23
assert 0 <= minute <= 59
return super().set([hour, minute], *args, **kwargs)
except (ValueError, AssertionError):
error = 'Value "%s" is not a valid time (HH:MM)'
LOGGER.error(error, time)
raise SettingValueError(error % time)
class AutoOff(AutoOn):
'''
The auto off (standby) time.
'''
address = 0x53
length = 2