Skip to content

Commit 7326036

Browse files
committed
Add validation for module addresses and pgm counts; update test function names
1 parent 53d5eff commit 7326036

2 files changed

Lines changed: 35 additions & 10 deletions

File tree

paradox/paradox.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
async_loop_unhandled_exception_handler,
2323
)
2424
from paradox.hardware import Panel, create_panel
25+
from paradox.hardware.evo.parsers import MODULE_PGM_PACKET_SLOTS
2526
from paradox.lib import ps
2627
from paradox.lib.async_message_manager import ErrorMessageHandler, EventMessageHandler
2728
from paradox.lib.handlers import PersistentHandler
@@ -492,6 +493,22 @@ async def control_partition(self, partition: str, command: str) -> bool:
492493

493494
def _init_module_pgms(self):
494495
for addr, pgm_count in cfg.MODULE_PGM_ADDRESSES.items():
496+
if not isinstance(addr, int) or not (1 <= addr <= 254):
497+
logger.warning(
498+
"MODULE_PGM_ADDRESSES: invalid module address %r (expected int 1-254), skipping",
499+
addr,
500+
)
501+
continue
502+
if not isinstance(pgm_count, int) or not (
503+
1 <= pgm_count <= MODULE_PGM_PACKET_SLOTS
504+
):
505+
logger.warning(
506+
"MODULE_PGM_ADDRESSES: invalid pgm_count %r for address %d (expected int 1-%d), skipping",
507+
pgm_count,
508+
addr,
509+
MODULE_PGM_PACKET_SLOTS,
510+
)
511+
continue
495512
for pgm_index in range(1, pgm_count + 1):
496513
key = f"module{addr}_pgm{pgm_index}"
497514
self.storage.get_container("module_pgm")[key] = {
@@ -533,15 +550,19 @@ async def control_output(self, output, command) -> bool:
533550
out["module_address"], out["pgm_index"], command
534551
)
535552
except NotImplementedError:
536-
logger.error("control_module_pgm_outputs is not implemented for this alarm type")
553+
logger.error(
554+
"control_module_pgm_outputs is not implemented for this alarm type"
555+
)
537556
except asyncio.CancelledError:
538-
logger.error("control_output canceled")
557+
logger.error("control_module_pgm_output canceled")
539558
raise
540559
except asyncio.TimeoutError:
541560
logger.error("control_output timeout")
542561
if accepted:
543562
is_on = command in ("on", "on_override")
544-
self.storage.update_container_object("module_pgm", out["key"], {"on": is_on})
563+
self.storage.update_container_object(
564+
"module_pgm", out["key"], {"on": is_on}
565+
)
545566
return accepted
546567

547568
logger.error("No outputs selected")

tests/hardware/evo/test_pgm.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
from binascii import hexlify, unhexlify
1+
from binascii import unhexlify
22

33
from paradox.hardware.evo.adapters import PGMFlags
4-
from paradox.hardware.evo.parsers import (BroadcastRequest, BroadcastResponse,
5-
PerformPGMAction,
6-
PGMBroadcastCommand)
4+
from paradox.hardware.evo.parsers import PerformActionResponse, PerformPGMAction
75

86

97
def test_pgm3_activate_and_monitor():
@@ -50,7 +48,7 @@ def test_pgm3_deactivate_and_monitor():
5048
assert a == expected_out
5149

5250

53-
def test_module_pgm_activate_and_monitor():
51+
def test_pgm4_activate_and_monitor():
5452
expected_out = unhexlify("40130600000008000000000000000300000064")
5553

5654
pgms = [4]
@@ -60,7 +58,7 @@ def test_module_pgm_activate_and_monitor():
6058
assert a == expected_out
6159

6260

63-
def test_module_pgm_deactivate_and_monitor():
61+
def test_pgm4_deactivate_and_monitor():
6462
expected_out = unhexlify("40130600000008000000000000000100000062")
6563

6664
pgms = [4]
@@ -119,4 +117,10 @@ def test_pgm_flags_3():
119117

120118

121119
def test_pgm_confirmation():
122-
payload = unhexlify("42070000000049")
120+
raw = unhexlify("42070000000049")
121+
parsed = PerformActionResponse.parse(raw)
122+
123+
assert parsed.fields.value.po.command == 0x4
124+
assert parsed.fields.value.po.status.Winload_connected is True
125+
assert parsed.fields.value.po.status.alarm_reporting_pending is False
126+
assert parsed.fields.value.packet_length == 7

0 commit comments

Comments
 (0)