Browse Source

Rudimentary support for alarm/bypass LRR events.

pyserial_fix
Scott Petersen 7 years ago
parent
commit
7f742f066f
3 changed files with 64 additions and 13 deletions
  1. +28
    -10
      alarmdecoder/decoder.py
  2. +23
    -0
      alarmdecoder/messages/lrr/events.py
  3. +13
    -3
      alarmdecoder/messages/lrr/system.py

+ 28
- 10
alarmdecoder/decoder.py View File

@@ -578,7 +578,7 @@ class AlarmDecoder(object):


return self._power_status return self._power_status


def _update_alarm_status(self, message):
def _update_alarm_status(self, message=None, status=None, zone=None, user=None):
""" """
Uses the provided message to update the alarm state. Uses the provided message to update the alarm state.


@@ -588,18 +588,29 @@ class AlarmDecoder(object):
:returns: bool indicating the new status :returns: bool indicating the new status
""" """


if message.alarm_sounding != self._alarm_status:
self._alarm_status, old_status = message.alarm_sounding, self._alarm_status
alarm_status = status
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)


if old_status is not None:
print("_update_alarm_status: status={} zone={} user={}".format(alarm_status, alarm_zone, user))

if alarm_status != self._alarm_status:
self._alarm_status, old_status = alarm_status, self._alarm_status

if old_status is not None or status is not None:
if self._alarm_status: if self._alarm_status:
self.on_alarm(zone=message.numeric_code)
self.on_alarm(zone=alarm_zone)
else: else:
self.on_alarm_restored(zone=message.numeric_code)
self.on_alarm_restored(zone=alarm_zone, user=user)


return self._alarm_status return self._alarm_status


def _update_zone_bypass_status(self, message=None, status=None):
def _update_zone_bypass_status(self, message=None, status=None, zone=None):
""" """
Uses the provided message to update the zone bypass state. Uses the provided message to update the zone bypass state.


@@ -609,8 +620,13 @@ class AlarmDecoder(object):
:returns: bool indicating the new status :returns: bool indicating the new status
""" """
bypass_status = status bypass_status = status
bypass_zone = zone
if isinstance(message, Message): if isinstance(message, Message):
bypass_status = message.zone_bypassed bypass_status = message.zone_bypassed
try:
bypass_zone = int(message.numeric_code)
except ValueError:
bypass_zone = int(message.numeric_code, 16)


if bypass_status is None: if bypass_status is None:
return return
@@ -618,8 +634,8 @@ class AlarmDecoder(object):
if bypass_status != self._bypass_status: if bypass_status != self._bypass_status:
self._bypass_status, old_status = bypass_status, self._bypass_status self._bypass_status, old_status = bypass_status, self._bypass_status


if old_status is not None:
self.on_bypass(status=self._bypass_status)
if old_status is not None or message is None:
self.on_bypass(status=self._bypass_status, zone=bypass_zone)


return self._bypass_status return self._bypass_status


@@ -639,6 +655,8 @@ class AlarmDecoder(object):
arm_status = message.armed_away arm_status = message.armed_away
stay_status = message.armed_home stay_status = message.armed_home


print("_update_armed_status: status={} status_stay={} - arm_status={} stay_status={}".format(status, status_stay, arm_status, stay_status))

if arm_status is None or stay_status is None: if arm_status is None or stay_status is None:
return return


@@ -694,7 +712,7 @@ class AlarmDecoder(object):
fire_status = message.fire_alarm fire_status = message.fire_alarm


last_status, last_update = self._fire_status last_status, last_update = self._fire_status
print("_update_fire_status: fire_status={fire_status} last_status={last_status} last_update={last_update}".format(fire_status=fire_status, last_status=last_status, last_update=last_update))
#print("_update_fire_status: fire_status={fire_status} last_status={last_status} last_update={last_update}".format(fire_status=fire_status, last_status=last_status, last_update=last_update))




if self._fire_state == FireState.NONE: if self._fire_state == FireState.NONE:


+ 23
- 0
alarmdecoder/messages/lrr/events.py View File

@@ -681,6 +681,29 @@ LRR_FIRE_EVENTS = [
LRR_CID_EVENT.OPENCLOSE_CANCEL_BY_USER LRR_CID_EVENT.OPENCLOSE_CANCEL_BY_USER
] ]


LRR_ALARM_EVENTS = [
LRR_CID_EVENT.BURGLARY,
LRR_CID_EVENT.BURGLARY_PERIMETER,
LRR_CID_EVENT.BURGLARY_INTERIOR,
LRR_CID_EVENT.BURGLARY_AUX,
LRR_CID_EVENT.BURGLARY_ENTRYEXIT,
LRR_CID_EVENT.BURGLARY_DAYNIGHT,
LRR_CID_EVENT.BURGLARY_OUTDOOR,
LRR_CID_EVENT.ALARM_GENERAL,
LRR_CID_EVENT.BURGLARY_SILENT,
LRR_CID_EVENT.ALARM_AUX,
LRR_CID_EVENT.ALARM_GAS_DETECTED,
LRR_CID_EVENT.ALARM_REFRIDGERATION,
LRR_CID_EVENT.ALARM_LOSS_OF_HEAT,
LRR_CID_EVENT.ALARM_WATER_LEAKAGE,
LRR_CID_EVENT.ALARM_LOW_BOTTLED_GAS_LEVEL,
LRR_CID_EVENT.ALARM_HIGH_TEMP,
LRR_CID_EVENT.ALARM_LOW_TEMP,
LRR_CID_EVENT.ALARM_LOSS_OF_AIR_FLOW,
LRR_CID_EVENT.ALARM_CARBON_MONOXIDE,
LRR_CID_EVENT.OPENCLOSE_CANCEL_BY_USER
]

LRR_POWER_EVENTS = [ LRR_POWER_EVENTS = [
LRR_CID_EVENT.TROUBLE_AC_LOSS LRR_CID_EVENT.TROUBLE_AC_LOSS
] ]


+ 13
- 3
alarmdecoder/messages/lrr/system.py View File

@@ -1,7 +1,7 @@


from .events import LRR_EVENT_TYPE, LRR_EVENT_STATUS, LRR_CID_EVENT from .events import LRR_EVENT_TYPE, LRR_EVENT_STATUS, LRR_CID_EVENT
from .events import LRR_FIRE_EVENTS, LRR_POWER_EVENTS, LRR_BYPASS_EVENTS, LRR_BATTERY_EVENTS, \ from .events import LRR_FIRE_EVENTS, LRR_POWER_EVENTS, LRR_BYPASS_EVENTS, LRR_BATTERY_EVENTS, \
LRR_PANIC_EVENTS, LRR_ARM_EVENTS, LRR_STAY_EVENTS
LRR_PANIC_EVENTS, LRR_ARM_EVENTS, LRR_STAY_EVENTS, LRR_ALARM_EVENTS




class LRRSystem(object): class LRRSystem(object):
@@ -51,16 +51,26 @@ class LRRSystem(object):
if message.event_code == LRR_CID_EVENT.OPENCLOSE_CANCEL_BY_USER: if message.event_code == LRR_CID_EVENT.OPENCLOSE_CANCEL_BY_USER:
status = False status = False


print("FIRE, status={}".format(status))
self._alarmdecoder._update_fire_status(status=status) self._alarmdecoder._update_fire_status(status=status)
handled = True handled = True
if message.event_code in LRR_ALARM_EVENTS:
kwargs = {}
field_name = 'zone'
if not status:
field_name = 'user'

kwargs[field_name] = int(message.event_data)
self._alarmdecoder._update_alarm_status(status=status, **kwargs)
handled = True

if message.event_code in LRR_POWER_EVENTS: if message.event_code in LRR_POWER_EVENTS:
self._alarmdecoder._update_power_status(status=status) self._alarmdecoder._update_power_status(status=status)
handled = True handled = True


if message.event_code in LRR_BYPASS_EVENTS: if message.event_code in LRR_BYPASS_EVENTS:
self._alarmdecoder._update_zone_bypass_status(status=status)
zone = int(message.event_data)
self._alarmdecoder._update_zone_bypass_status(status=status, zone=zone)
handled = True handled = True


if message.event_code in LRR_BATTERY_EVENTS: if message.event_code in LRR_BATTERY_EVENTS:


Loading…
Cancel
Save