@@ -592,10 +592,7 @@ class AlarmDecoder(object): | |||||
alarm_zone = zone | alarm_zone = zone | ||||
if isinstance(message, Message): | if isinstance(message, Message): | ||||
alarm_status = message.alarm_sounding | alarm_status = message.alarm_sounding | ||||
try: | |||||
alarm_zone = int(message.numeric_code) | |||||
except ValueError: | |||||
alarm_zone = int(message.numeric_code, 16) | |||||
alarm_zone = message.parse_numeric_code() | |||||
if alarm_status != self._alarm_status: | if alarm_status != self._alarm_status: | ||||
self._alarm_status, old_status = alarm_status, self._alarm_status | self._alarm_status, old_status = alarm_status, self._alarm_status | ||||
@@ -109,8 +109,6 @@ class LRRSystem(object): | |||||
def _handle_unknown_message(self, message): | def _handle_unknown_message(self, message): | ||||
# TODO: Log this somewhere useful. | # TODO: Log this somewhere useful. | ||||
print("UNKNOWN LRR EVENT: {0}".format(message)) | |||||
return False | return False | ||||
def _get_event_status(self, message): | def _get_event_status(self, message): | ||||
@@ -130,6 +130,35 @@ class Message(BaseMessage): | |||||
# Current cursor location on the alpha display. | # Current cursor location on the alpha display. | ||||
self.cursor_location = int(self.panel_data[21:23], 16) | self.cursor_location = int(self.panel_data[21:23], 16) | ||||
def parse_numeric_code(self, force_hex=False): | |||||
""" | |||||
Parses and returns the numeric code as an integer. | |||||
The numeric code can be either base 10 or base 16, depending on | |||||
where the message came from. | |||||
:param force_hex: force the numeric code to be processed as base 16. | |||||
:type force_hex: boolean | |||||
:raises: ValueError | |||||
""" | |||||
code = None | |||||
got_error = False | |||||
if not force_hex: | |||||
try: | |||||
code = int(self.numeric_code) | |||||
except ValueError: | |||||
got_error = True | |||||
if force_hex or got_error: | |||||
try: | |||||
code = int(self.numeric_code, 16) | |||||
except ValueError: | |||||
raise | |||||
return code | |||||
def dict(self, **kwargs): | def dict(self, **kwargs): | ||||
""" | """ | ||||
Dictionary representation. | Dictionary representation. | ||||
@@ -178,13 +178,7 @@ class Zonetracker(object): | |||||
# Process fault | # Process fault | ||||
elif self.alarmdecoder_object.mode != DSC and (message.check_zone or message.text.startswith("FAULT") or message.text.startswith("ALARM")): | elif self.alarmdecoder_object.mode != DSC and (message.check_zone or message.text.startswith("FAULT") or message.text.startswith("ALARM")): | ||||
# Apparently this representation can be both base 10 | |||||
# or base 16, depending on where the message came | |||||
# from. | |||||
try: | |||||
zone = int(message.numeric_code) | |||||
except ValueError: | |||||
zone = int(message.numeric_code, 16) | |||||
zone = message.parse_numeric_code() | |||||
# NOTE: Odd case for ECP failures. Apparently they report as | # NOTE: Odd case for ECP failures. Apparently they report as | ||||
# zone 191 (0xBF) regardless of whether or not the | # zone 191 (0xBF) regardless of whether or not the | ||||