9
9
from .becker_helper import generate_code
10
10
11
11
COMMAND_UP = 0x20
12
- COMMAND_UP2 = 0x24 # intermediate position "up"
12
+ COMMAND_UP2 = 0x21 # move up
13
+ COMMAND_UP3 = 0x22 # move up
14
+ COMMAND_UP4 = 0x23 # move up
15
+ COMMAND_UP5 = 0x24 # intermediate position "up"
13
16
COMMAND_DOWN = 0x40
14
- COMMAND_DOWN2 = 0x44 # intermediate position "down"
17
+ COMMAND_DOWN2 = 0x41 # move down
18
+ COMMAND_DOWN3 = 0x42 # move down
19
+ COMMAND_DOWN4 = 0x43 # move down
20
+ COMMAND_DOWN5 = 0x44 # intermediate position "down" (sun protection)
15
21
COMMAND_HALT = 0x10
16
22
COMMAND_PAIR = 0x80 # pair button press
17
23
COMMAND_PAIR2 = 0x81 # pair button pressed for 3 seconds (without releasing)
18
24
COMMAND_PAIR3 = 0x82 # pair button pressed for 6 seconds (without releasing)
19
25
COMMAND_PAIR4 = 0x83 # pair button pressed for 10 seconds (without releasing)
20
26
27
+ COMMAND_CLEARPOS = 0x90
28
+ COMMAND_CLEARPOS2 = 0x91
29
+ COMMAND_CLEARPOS3 = 0x92
30
+ COMMAND_CLEARPOS4 = 0x93
31
+
21
32
DEFAULT_DEVICE_NAME = '/dev/serial/by-id/usb-BECKER-ANTRIEBE_GmbH_CDC_RS232_v125_Centronic-if00'
22
33
23
34
logging .basicConfig ()
24
35
_LOGGER = logging .getLogger (__name__ )
25
36
26
37
27
38
class Becker :
39
+ """
40
+ Becker Shutter Controller
41
+ =========================
42
+
43
+ Use this class to perform operations on your Becker Shutter using a centronic USB Stick
44
+ This class will as well maintain a call increment in an internal database
45
+ """
46
+ def __init__ (self , device_name = DEFAULT_DEVICE_NAME , init_dummy = False ):
47
+ """
48
+ Create a new instance of the Becker controller
28
49
29
- def __init__ (self , device_name = DEFAULT_DEVICE_NAME ):
50
+ :param device_name: The path for the centronic stick (default /dev/serial/by-id/usb-BECKER-ANTRIEBE_GmbH_CDC_RS232_v125_Centronic-if00).
51
+ :param init_dummy: Boolean that indicate if the database should be initialized with a dummy unit (default False).
52
+ :type device_name: str
53
+ :type init_dummy: bool
54
+ """
30
55
self .is_serial = "/" in device_name
31
56
if self .is_serial and not os .path .exists (device_name ):
32
57
raise FileExistsError (device_name + " don't exists" )
33
58
self .device = device_name
34
59
self .db = Database ()
60
+
61
+ # If no unit is defined create a dummy one
62
+ units = self .db .get_all_units ()
63
+ if not units and init_dummy :
64
+ self .db .init_dummy ()
65
+
35
66
if self .is_serial :
36
67
self .s = serial .Serial (self .device , 115200 , timeout = 1 )
37
68
self .write_function = self .s .write
@@ -59,13 +90,13 @@ async def run_codes(self, channel, unit, cmd, test):
59
90
if cmd == "UP" :
60
91
codes .append (generate_code (channel , unit , COMMAND_UP ))
61
92
elif cmd == "UP2" :
62
- codes .append (generate_code (channel , unit , COMMAND_UP2 ))
93
+ codes .append (generate_code (channel , unit , COMMAND_UP5 ))
63
94
elif cmd == "HALT" :
64
95
codes .append (generate_code (channel , unit , COMMAND_HALT ))
65
96
elif cmd == "DOWN" :
66
97
codes .append (generate_code (channel , unit , COMMAND_DOWN ))
67
98
elif cmd == "DOWN2" :
68
- codes .append (generate_code (channel , unit , COMMAND_DOWN2 ))
99
+ codes .append (generate_code (channel , unit , COMMAND_DOWN5 ))
69
100
elif cmd == "TRAIN" :
70
101
codes .append (generate_code (channel , unit , COMMAND_PAIR ))
71
102
unit [1 ] += 1
@@ -76,6 +107,16 @@ async def run_codes(self, channel, unit, cmd, test):
76
107
codes .append (generate_code (channel , unit , COMMAND_PAIR2 ))
77
108
# set unit as configured
78
109
unit [2 ] = 1
110
+ elif cmd == "CLEARPOS" :
111
+ codes .append (generate_code (channel , unit , COMMAND_PAIR ))
112
+ unit [1 ] += 1
113
+ codes .append (generate_code (channel , unit , COMMAND_CLEARPOS ))
114
+ unit [1 ] += 1
115
+ codes .append (generate_code (channel , unit , COMMAND_CLEARPOS2 ))
116
+ unit [1 ] += 1
117
+ codes .append (generate_code (channel , unit , COMMAND_CLEARPOS3 ))
118
+ unit [1 ] += 1
119
+ codes .append (generate_code (channel , unit , COMMAND_CLEARPOS4 ))
79
120
elif cmd == "REMOVE" :
80
121
codes .append (generate_code (channel , unit , COMMAND_PAIR ))
81
122
unit [1 ] += 1
@@ -125,43 +166,55 @@ async def send(self, channel, cmd, test=False):
125
166
await self .run_codes (ch , unit , cmd , test )
126
167
127
168
async def move_up (self , channel ):
128
- """ Sent the command to move up for a given channel.
169
+ """
170
+ Send the command to move up for a given channel.
129
171
130
- :param channel: the channel on which the shutter is listening
172
+ :param channel: the channel on which the shutter is listening
173
+ :type channel: str
131
174
"""
132
175
await self .send (channel , "UP" )
133
176
134
177
async def move_up_intermediate (self , channel ):
135
- """ Sent the command to move up in the intermediate position for a given channel.
178
+ """
179
+ Send the command to move up in the intermediate position for a given channel.
136
180
137
- :param channel: the channel on which the shutter is listening
181
+ :param channel: the channel on which the shutter is listening
182
+ :type channel: str
138
183
"""
139
184
await self .send (channel , "UP2" )
140
185
141
186
async def move_down (self , channel ):
142
- """ Sent the command to move down for a given channel.
187
+ """
188
+ Sent the command to move down for a given channel.
143
189
144
- :param channel: the channel on which the shutter is listening
190
+ :param channel: the channel on which the shutter is listening
191
+ :type channel: str
145
192
"""
146
193
await self .send (channel , "DOWN" )
147
194
148
195
async def move_down_intermediate (self , channel ):
149
- """ Sent the command to move down in the intermediate position for a given channel.
196
+ """
197
+ Send the command to move down in the intermediate position for a given channel.
150
198
151
- :param channel: the channel on which the shutter is listening
199
+ :param channel: the channel on which the shutter is listening
200
+ :type channel: str
152
201
"""
153
202
await self .send (channel , "DOWN2" )
154
203
155
204
async def stop (self , channel ):
156
- """ Sent the command to stop for a given channel.
205
+ """
206
+ Send the command to stop for a given channel.
157
207
158
- :param channel: the channel on which the shutter is listening
208
+ :param channel: the channel on which the shutter is listening
209
+ :type channel: str
159
210
"""
160
211
await self .send (channel , "HALT" )
161
212
162
213
async def pair (self , channel ):
163
- """ Initiate the pairing for a given channel.
214
+ """
215
+ Initiate the pairing for a given channel.
164
216
165
- :param channel: the channel on which the shutter is listening
217
+ :param channel: the channel on which the shutter is listening
218
+ :type channel: str
166
219
"""
167
220
await self .send (channel , "TRAIN" )
0 commit comments