A clone of: https://github.com/nutechsoftware/alarmdecoder This is requires as they dropped support for older firmware releases w/o building in backward compatibility code, and they had previously hardcoded pyserial to a python2 only version.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

93 lines
3.4 KiB

  1. from unittest import TestCase
  2. from alarmdecoder.messages import Message, ExpanderMessage, RFMessage, LRRMessage
  3. from alarmdecoder.messages.lrr import LRR_EVENT_TYPE, LRR_CID_EVENT, LRR_EVENT_STATUS
  4. from alarmdecoder.util import InvalidMessageError
  5. from alarmdecoder.panels import ADEMCO
  6. class TestMessages(TestCase):
  7. def setUp(self):
  8. pass
  9. def tearDown(self):
  10. pass
  11. ### Tests
  12. def test_message_parse(self):
  13. msg = Message('[00000000000000000A--],001,[f707000600e5800c0c020000],"FAULT 1 "')
  14. self.assertFalse(msg.ready)
  15. self.assertFalse(msg.armed_away)
  16. self.assertFalse(msg.armed_home)
  17. self.assertFalse(msg.backlight_on)
  18. self.assertFalse(msg.programming_mode)
  19. self.assertEqual(msg.beeps, 0)
  20. self.assertFalse(msg.zone_bypassed)
  21. self.assertFalse(msg.ac_power)
  22. self.assertFalse(msg.chime_on)
  23. self.assertFalse(msg.alarm_event_occurred)
  24. self.assertFalse(msg.alarm_sounding)
  25. self.assertFalse(msg.battery_low)
  26. self.assertFalse(msg.entry_delay_off)
  27. self.assertFalse(msg.fire_alarm)
  28. self.assertFalse(msg.check_zone)
  29. self.assertFalse(msg.perimeter_only)
  30. self.assertFalse(msg.system_fault)
  31. self.assertFalse(msg.panel_type, ADEMCO)
  32. self.assertEqual(msg.numeric_code, '001')
  33. self.assertEqual(msg.mask, int('07000600', 16))
  34. self.assertEqual(msg.cursor_location, -1)
  35. self.assertEqual(msg.text, 'FAULT 1 ')
  36. def test_message_parse_fail(self):
  37. with self.assertRaises(InvalidMessageError):
  38. msg = Message('')
  39. def test_expander_message_parse(self):
  40. msg = ExpanderMessage('!EXP:07,01,01')
  41. self.assertEqual(msg.address, 7)
  42. self.assertEqual(msg.channel, 1)
  43. self.assertEqual(msg.value, 1)
  44. def test_expander_message_parse_fail(self):
  45. with self.assertRaises(InvalidMessageError):
  46. msg = ExpanderMessage('')
  47. def test_rf_message_parse(self):
  48. msg = RFMessage('!RFX:0180036,80')
  49. self.assertEqual(msg.serial_number, '0180036')
  50. self.assertEqual(msg.value, int('80', 16))
  51. def test_rf_message_parse_fail(self):
  52. with self.assertRaises(InvalidMessageError):
  53. msg = RFMessage('')
  54. def test_lrr_message_parse_v1(self):
  55. msg = LRRMessage('!LRR:012,1,ARM_STAY')
  56. self.assertEqual(msg.event_data, '012')
  57. self.assertEqual(msg.partition, '1')
  58. self.assertEqual(msg.event_type, 'ARM_STAY')
  59. def test_lrr_message_parse_v2(self):
  60. msg = LRRMessage('!LRR:001,1,CID_3401,ff')
  61. self.assertIsInstance(msg, LRRMessage)
  62. self.assertEquals(msg.event_data, '001')
  63. self.assertEquals(msg.partition, '1')
  64. self.assertEquals(msg.event_prefix, 'CID')
  65. self.assertEquals(msg.event_source, LRR_EVENT_TYPE.CID)
  66. self.assertEquals(msg.event_status, LRR_EVENT_STATUS.RESTORE)
  67. self.assertEquals(msg.event_code, LRR_CID_EVENT.OPENCLOSE_BY_USER)
  68. self.assertEquals(msg.report_code, 'ff')
  69. def test_lrr_event_code_override(self):
  70. msg = LRRMessage('!LRR:001,1,CID_3400,01')
  71. self.assertEquals(msg.event_code, LRR_CID_EVENT.OPENCLOSE_BY_USER) # 400 -> 401
  72. def test_lrr_message_parse_fail(self):
  73. with self.assertRaises(InvalidMessageError):
  74. msg = LRRMessage('')