Pārlūkot izejas kodu

Refactoring the code used to parse the numeric_code in Message.

pyserial_fix
Scott Petersen pirms 6 gadiem
vecāks
revīzija
8b4aed5990
4 mainītis faili ar 31 papildinājumiem un 13 dzēšanām
  1. +1
    -4
      alarmdecoder/decoder.py
  2. +0
    -2
      alarmdecoder/messages/lrr/system.py
  3. +29
    -0
      alarmdecoder/messages/panel_message.py
  4. +1
    -7
      alarmdecoder/zonetracking.py

+ 1
- 4
alarmdecoder/decoder.py Parādīt failu

@@ -592,10 +592,7 @@ class AlarmDecoder(object):
alarm_zone = zone
if isinstance(message, Message):
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:
self._alarm_status, old_status = alarm_status, self._alarm_status


+ 0
- 2
alarmdecoder/messages/lrr/system.py Parādīt failu

@@ -109,8 +109,6 @@ class LRRSystem(object):

def _handle_unknown_message(self, message):
# TODO: Log this somewhere useful.
print("UNKNOWN LRR EVENT: {0}".format(message))

return False

def _get_event_status(self, message):


+ 29
- 0
alarmdecoder/messages/panel_message.py Parādīt failu

@@ -130,6 +130,35 @@ class Message(BaseMessage):
# Current cursor location on the alpha display.
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):
"""
Dictionary representation.


+ 1
- 7
alarmdecoder/zonetracking.py Parādīt failu

@@ -178,13 +178,7 @@ class Zonetracker(object):

# Process fault
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
# zone 191 (0xBF) regardless of whether or not the


Notiek ielāde…
Atcelt
Saglabāt