Page 1 of 1

New Error When Arming

PostPosted: Sat Sep 09, 2017 12:48 pm
by Rene
I am running a standard loop to check status and call arm/disarm functions. This has worked perfectly but I noticed that recently it started failing. This could have started after the last update downloaded but I am not sure. I don't know how to fix this. My code has been running for almost a year without any issues. Ideas?

code snippet:
try:
# Retrieved an AD2 device that has been exposed with ser2sock on localhost:10000
# and set up SSL values.
ssl_device = SocketDevice(interface=(SER2SOCK_HOST,SER2SOCK_PORT))
ssl_device.ssl = True
ssl_device.ssl_ca = SSL_CA
ssl_device.ssl_key = SSL_KEY
ssl_device.ssl_certificate = SSL_CERT

device = AlarmDecoder(ssl_device)

device.on_message += handle_message
device.on_arm += handle_arm
device.on_disarm += handle_disarm

print 'Running...'

with device.open():
while True:
time.sleep(1)

except Exception, ex:
print 'Exception:', ex


Log of the error message after I arm the alarm in Away mode:

[10010001000000003A--],002,[f70000008002001c08000000000000],"****DISARMED**** READY TO ARM "
[10010001000000003A--],002,[f70000008002001c08000000000000],"****DISARMED**** READY TO ARM "

{Arm alarm via key pad}

Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 552, in __bootstrap_inner
self.run()
File "/opt/alarmdecoder/alarmdecoder/devices.py", line 196, in run
self._device.read_line(timeout=self.READ_TIMEOUT)
File "/opt/alarmdecoder/alarmdecoder/devices.py", line 1219, in read_line
self.on_read(data=ret)
File "/opt/alarmdecoder/alarmdecoder/event/event.py", line 80, in fire
func(self.obj, *args, **kwargs)
File "/opt/alarmdecoder/alarmdecoder/decoder.py", line 724, in _on_read
self._handle_message(data)
File "/opt/alarmdecoder/alarmdecoder/decoder.py", line 371, in _handle_message
msg = self._handle_keypad_message(data)
File "/opt/alarmdecoder/alarmdecoder/decoder.py", line 408, in _handle_keypad_message
self._update_internal_states(msg)
File "/opt/alarmdecoder/alarmdecoder/decoder.py", line 541, in _update_internal_states
self._update_armed_status(message)
File "/opt/alarmdecoder/alarmdecoder/decoder.py", line 621, in _update_armed_status
self.on_arm(stay=message.armed_home)
File "/opt/alarmdecoder/alarmdecoder/event/event.py", line 80, in fire
func(self.obj, *args, **kwargs)
TypeError: handle_arm() got an unexpected keyword argument 'stay'

Re: New Error When Arming

PostPosted: Sat Sep 09, 2017 5:08 pm
by kevin
Arm Mode is now passed in the event, check you have updated the alarmdecoder library

If this is your custom code, make sure you are handling the kwargs

Re: New Error When Arming

PostPosted: Sun Sep 10, 2017 4:16 pm
by Rene
My code was based on a the standard examples except I call a shell script to activate cameras. It looks like this:

def handle_message(sender, message):
print message.raw

def handle_arm(sender):
print sender
print 'Arming cameras...'
#bash shell scripts must have execute permissions.
subprocess.call("/home/pi/armcameras.sh", shell=True)
print 'Cameras armed !'

def handle_disarm(sender):
print sender
print 'Disarming Cameras...'
#bash shell script must have excute permissions.
subprocess.call("/home/pi/disarmcameras.sh", shell=True)
print 'Cameras disarmed !'

if __name__ == '__main__':
main()


================
My work around was to change line 621 in the decoder.py to remove the parameter.
# self.on_arm(stay=message.armed_home)
self.on_arm()

I could not figure out how to make the handle_arm function accept the return parameter "stay-message.armed_home). If you could post a sample of that snippet of code, that would be great and I can put the decoder.py file back to its original version. Thanks

Re: New Error When Arming

PostPosted: Sun Sep 10, 2017 9:30 pm
by kevin
Try passing stay in as a kwarg - **kwargs - something like def handle_arm( sender, **kwargs): stay = kwargs.get('stay', False)

Re: New Error When Arming

PostPosted: Tue Oct 10, 2017 2:27 pm
by Rene
That worked! Thank you very much for the sample. :D