Skip to content

Commit 63b2fb6

Browse files
committed
fixed response packet data layout
basic __str__ for Timer fixed parsing of execution time
1 parent 6ea5eda commit 63b2fb6

File tree

3 files changed

+47
-24
lines changed

3 files changed

+47
-24
lines changed

sunix_ledstrip_controller_client/controller.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -241,19 +241,22 @@ def get_timers(self) -> [Timer]:
241241
"""
242242

243243
def extract_timer_time(data: dict, idx: int) -> datetime:
244+
# combination of constants
245+
dayofweek = data["dayofweek_%d" % idx]
246+
if dayofweek != 0:
247+
return None
248+
244249
year = data["year_%d" % idx] + 2000
245250
month = data["month_%d" % idx]
246251
day = data["day_%d" % idx]
252+
hour = data["hour_%d" % idx]
247253
minute = data["minute_%d" % idx]
248254
second = data["second_%d" % idx]
249255

250-
# combination of constants
251-
dayofweek = data["dayofweek_%d" % idx]
256+
execution_time = datetime.datetime.now().replace(day=day, month=month, year=year,
257+
hour=hour, minute=minute, second=second)
252258

253-
254-
255-
256-
return datetime.datetime.now()
259+
return execution_time
257260

258261
def extract_timer_pattern(data: dict, idx: int) -> datetime:
259262
mode = data["action_code_%d" % idx]
@@ -262,12 +265,11 @@ def extract_timer_pattern(data: dict, idx: int) -> datetime:
262265
pass
263266

264267
# TODO
265-
return datetime.datetime.now()
268+
return mode
266269

267270
timers_data = self._api.get_timers(self._host, self._port)
268271

269272
timers = []
270-
271273
for idx in range(1, 7):
272274
time = extract_timer_time(timers_data, idx)
273275
pattern = extract_timer_pattern(timers_data, idx)

sunix_ledstrip_controller_client/packets/responses.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ def __init__(self, data: bytearray):
120120
"warm_white_1" / Int8ub,
121121
"cold_white_1" / Int8ub,
122122

123+
"unknown_end_1" / Int8ub,
124+
123125
"is_active_2" / Int8ub,
124126

125127
# (0f=15??) add 2000 to this value to get the correct year
@@ -143,6 +145,8 @@ def __init__(self, data: bytearray):
143145
"warm_white_2" / Int8ub,
144146
"cold_white_2" / Int8ub,
145147

148+
"unknown_end_2" / Int8ub,
149+
146150
"is_active_3" / Int8ub,
147151

148152
# (0f=15??) add 2000 to this value to get the correct year
@@ -166,6 +170,8 @@ def __init__(self, data: bytearray):
166170
"warm_white_3" / Int8ub,
167171
"cold_white_3" / Int8ub,
168172

173+
"unknown_end_3" / Int8ub,
174+
169175
"is_active_4" / Int8ub,
170176

171177
# (0f=15??) add 2000 to this value to get the correct year
@@ -189,6 +195,8 @@ def __init__(self, data: bytearray):
189195
"warm_white_4" / Int8ub,
190196
"cold_white_4" / Int8ub,
191197

198+
"unknown_end_4" / Int8ub,
199+
192200
"is_active_5" / Int8ub,
193201

194202
# (0f=15??) add 2000 to this value to get the correct year
@@ -212,6 +220,8 @@ def __init__(self, data: bytearray):
212220
"warm_white_5" / Int8ub,
213221
"cold_white_5" / Int8ub,
214222

223+
"unknown_end_5" / Int8ub,
224+
215225
"is_active_6" / Int8ub,
216226

217227
# (0f=15??) add 2000 to this value to get the correct year
@@ -235,13 +245,8 @@ def __init__(self, data: bytearray):
235245
"warm_white_6" / Int8ub,
236246
"cold_white_6" / Int8ub,
237247

238-
"unknown_end_1" / Int8ub,
239-
"unknown_end_2" / Int8ub,
240-
"unknown_end_3" / Int8ub,
241-
242-
"unknown_end_4" / Int8ub,
243-
"unknown_end_5" / Int8ub,
244248
"unknown_end_6" / Int8ub,
249+
245250
"unknown_end_7" / Int8ub,
246251

247252
"checksum" / Int8ub

sunix_ledstrip_controller_client/timer.py

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,37 @@ class Timer:
1010
def __init__(self, enabled: bool,
1111
execution_time: datetime, pattern: any,
1212
red: int, green: int, blue: int):
13-
self.enabled = enabled
13+
self._enabled = enabled
1414

15-
self.execution_time = execution_time
16-
self.execution_pattern = pattern
15+
self._execution_time = execution_time
16+
self._execution_pattern = pattern
1717

18-
self.red = red
19-
self.green = green
20-
self.blue = blue
18+
self._red = red
19+
self._green = green
20+
self._blue = blue
2121

2222
def __str__(self):
23-
# TODO
24-
return super().__str__()
23+
return ("Enabled: %s\n" % (self.get_enabled()) +
24+
"Execution Time: %s\n" % (self.get_execution_time()) +
25+
"Execution Pattern: %s\n" % (self.get_execution_pattern()))
2526

26-
def get_time(self):
27-
return self.execution_time
27+
def get_enabled(self):
28+
"""
29+
:return: True if this timer is enabled
30+
"""
31+
return self._enabled
32+
33+
def get_execution_time(self):
34+
"""
35+
:return: the time when this timer will execute
36+
"""
37+
return self._execution_time
38+
39+
def get_execution_pattern(self):
40+
"""
41+
:return: the execution pattern for this timer
42+
"""
43+
return self._execution_pattern
2844

2945

3046
class Weekday(Enum):

0 commit comments

Comments
 (0)