Skip to content

Commit

Permalink
fixed response packet data layout
Browse files Browse the repository at this point in the history
basic __str__ for Timer
fixed parsing of execution time
  • Loading branch information
markusressel committed Mar 15, 2018
1 parent 6ea5eda commit 63b2fb6
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 24 deletions.
18 changes: 10 additions & 8 deletions sunix_ledstrip_controller_client/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,19 +241,22 @@ def get_timers(self) -> [Timer]:
"""

def extract_timer_time(data: dict, idx: int) -> datetime:
# combination of constants
dayofweek = data["dayofweek_%d" % idx]
if dayofweek != 0:
return None

year = data["year_%d" % idx] + 2000
month = data["month_%d" % idx]
day = data["day_%d" % idx]
hour = data["hour_%d" % idx]
minute = data["minute_%d" % idx]
second = data["second_%d" % idx]

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




return datetime.datetime.now()
return execution_time

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

# TODO
return datetime.datetime.now()
return mode

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

timers = []

for idx in range(1, 7):
time = extract_timer_time(timers_data, idx)
pattern = extract_timer_pattern(timers_data, idx)
Expand Down
17 changes: 11 additions & 6 deletions sunix_ledstrip_controller_client/packets/responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ def __init__(self, data: bytearray):
"warm_white_1" / Int8ub,
"cold_white_1" / Int8ub,

"unknown_end_1" / Int8ub,

"is_active_2" / Int8ub,

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

"unknown_end_2" / Int8ub,

"is_active_3" / Int8ub,

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

"unknown_end_3" / Int8ub,

"is_active_4" / Int8ub,

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

"unknown_end_4" / Int8ub,

"is_active_5" / Int8ub,

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

"unknown_end_5" / Int8ub,

"is_active_6" / Int8ub,

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

"unknown_end_1" / Int8ub,
"unknown_end_2" / Int8ub,
"unknown_end_3" / Int8ub,

"unknown_end_4" / Int8ub,
"unknown_end_5" / Int8ub,
"unknown_end_6" / Int8ub,

"unknown_end_7" / Int8ub,

"checksum" / Int8ub
Expand Down
36 changes: 26 additions & 10 deletions sunix_ledstrip_controller_client/timer.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,37 @@ class Timer:
def __init__(self, enabled: bool,
execution_time: datetime, pattern: any,
red: int, green: int, blue: int):
self.enabled = enabled
self._enabled = enabled

self.execution_time = execution_time
self.execution_pattern = pattern
self._execution_time = execution_time
self._execution_pattern = pattern

self.red = red
self.green = green
self.blue = blue
self._red = red
self._green = green
self._blue = blue

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

def get_time(self):
return self.execution_time
def get_enabled(self):
"""
:return: True if this timer is enabled
"""
return self._enabled

def get_execution_time(self):
"""
:return: the time when this timer will execute
"""
return self._execution_time

def get_execution_pattern(self):
"""
:return: the execution pattern for this timer
"""
return self._execution_pattern


class Weekday(Enum):
Expand Down

0 comments on commit 63b2fb6

Please sign in to comment.