-
Notifications
You must be signed in to change notification settings - Fork 0
/
state.py
51 lines (40 loc) · 1.21 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
from bitarray import bitarray
from enum import Enum
class Mode(Enum):
COOL = bitarray('000')
DRY = bitarray('001')
AUTO = bitarray('010')
HEAT = bitarray('011')
FAN = bitarray('100')
class FanSpeed(Enum):
NONE = bitarray('000')
MIN = bitarray('001')
MED = bitarray('010')
MAX = bitarray('011')
AUTO = bitarray('100')
class State(object):
def __init__(self):
pass
class StateOff(State):
def __init__(self):
pass
def __str__(self):
return "OFF"
def data(self):
return "1010000100000000010000001111111111111111"
class StateOn(State):
def __init__(self, mode, temperature, fanSpeed):
self.__mode = mode
self.__temperature = temperature
self.__fanSpeed = fanSpeed
def __str__(self):
return "ON Mode:{} Temperature:{} Fan:{}".format(self.__mode.name, self.__temperature, self.__fanSpeed.name)
def data(self):
t = bitarray()
t.frombytes(bytes([self.__temperature-17]))
data = bitarray("1010000110{}{}0100{}1111111111111111".format(
self.__fanSpeed.value.to01(),
self.__mode.value.to01(),
t.to01()[-4:],
))
return data