Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Current Queue encode/decode support for TM2 #97

Merged
merged 1 commit into from
Jan 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 39 additions & 17 deletions pyrainbird/rainbird.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,29 +98,51 @@ def decode_queue(data: str, cmd_template: dict[str, Any]) -> dict[str, Any]:
rest = data[4:]
if page == 0:
# Currently running program
return {
"program": {
"program": int(rest[0:2], 16),
"running": bool(int(rest[2:4], 16)),
"zonesRemaining": int(rest[4:6], 16),
if len(data) == 24: # TM2 etc
runtime = int(data[8:12], 16)
program = int(data[18:20], 16)
if program > 4: # Max programs differs by device
program = 0
return {
"program": {
"seconds": runtime,
"program": program,
"zone": int(data[16:18], 16),
"active": (runtime > 0),
}
}
}
if len(data) == 14: # me3
return {
"program": {
"program": int(rest[0:2], 16),
"running": bool(int(rest[2:4], 16)),
"zonesRemaining": int(rest[4:6], 16),
}
}
return {"data": data}

if page == 1:
queue = []
for i in range(0, 8):
base = i * 8
program = int(data[base + 4 : base + 6], 16)
zone = int(data[base + 6 : base + 8], 16)
runtime = int(data[base + 8 : base + 12], 16)
if runtime > 0:
runtime = ((runtime & 0xFF00) >> 8) | ((runtime & 0xFF) << 8)
if zone:
queue.append({"program": program, "zone": zone, "seconds": runtime})
if len(data) == 70: # TM2
for i in range(0, 11):
base = i * 6
zone = int(data[base + 4 : base + 6], 16) & 31
runtime = int(data[base + 6 : base + 10], 16)
if zone:
queue.append({"zone": zone, "seconds": runtime})
else: # ME3
for i in range(0, 8):
base = i * 8
program = int(data[base + 4 : base + 6], 16)
zone = int(data[base + 6 : base + 8], 16)
runtime = int(data[base + 8 : base + 12], 16)
if runtime > 0:
runtime = ((runtime & 0xFF00) >> 8) | ((runtime & 0xFF) << 8)
if zone:
queue.append({"program": program, "zone": zone, "seconds": runtime})
return {"zones": queue}

if len(data) == 100:
_LOGGER.debug("data=%s", data)
queue = []
for i in range(0, 8):
base = i * 12
Expand Down Expand Up @@ -169,7 +191,7 @@ def encode(command: str, *args) -> str:
def encode_command(command_set: dict[str, Any], *args) -> str:
"""Encode a rainbird tunnelSip command request."""
cmd_code = command_set["command"]
if not (length := command_set[LENGTH]):
if not (length := command_set.get(LENGTH)):
raise RainbirdCodingException(
f"Unable to encode command missing length: {command_set}"
)
Expand Down
3 changes: 3 additions & 0 deletions pyrainbird/resources/sipcommands.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ ControllerCommands:
parameter: 0
response: '01'
length: 2
program:
position: 2
length: 2
ManuallyRunStationRequest:
command: '39'
parameterOne: 0
Expand Down
83 changes: 83 additions & 0 deletions tests/testdata/current_queue_tm2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
data:
- "3800"
- 3B00
- BB00050005D0000001000001
- 3B01
- BB012105D02204B02301A42404B0250258000000000000000000000000000000000000
- 3B00
- BB00050005C1000001000001
- 3B01
- BB012105C12204B02301A42404B0250258000000000000000000000000000000000000
- 3B00
- BB00050005A3000001000001
- 3B01
- BB012105A32204B02301A42404B0250258000000000000000000000000000000000000
decoded_data:
- type: ManuallyRunProgramRequest
program: 0
- type: CurrentQueueRequest
page: 0
- type: CurrentQueueResponse
program:
program: 0
zone: 1
seconds: 1488
active: true
- type: CurrentQueueRequest
page: 1
- type: CurrentQueueResponse
zones:
- zone: 1
seconds: 1488
- zone: 2
seconds: 1200
- zone: 3
seconds: 420
- zone: 4
seconds: 1200
- zone: 5
seconds: 600
- type: CurrentQueueRequest
page: 0
- type: CurrentQueueResponse
program:
program: 0
zone: 1
seconds: 1473
active: true
- type: CurrentQueueRequest
page: 1
- type: CurrentQueueResponse
zones:
- zone: 1
seconds: 1473
- zone: 2
seconds: 1200
- zone: 3
seconds: 420
- zone: 4
seconds: 1200
- zone: 5
seconds: 600
- type: CurrentQueueRequest
page: 0
- type: CurrentQueueResponse
program:
program: 0
zone: 1
seconds: 1443
active: true
- type: CurrentQueueRequest
page: 1
- type: CurrentQueueResponse
zones:
- zone: 1
seconds: 1443
- zone: 2
seconds: 1200
- zone: 3
seconds: 420
- zone: 4
seconds: 1200
- zone: 5
seconds: 600