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.

785 lines
14 KiB

  1. pyad2 Package
  2. *************
  3. "ad2" Module
  4. ============
  5. Provides the full AD2USB class and factory.
  6. class class pyad2.ad2.Overseer(attached_event=None, detached_event=None)
  7. Bases: "object"
  8. Factory for creation of AD2USB devices as well as provides
  9. attach/detach events."
  10. on_attached
  11. Called when an AD2USB device has been detected.
  12. on_detached
  13. Called when an AD2USB device has been removed.
  14. classmethod find_all()
  15. Returns all AD2USB devices located on the system.
  16. Returns:
  17. list of devices found
  18. Raises :
  19. util.CommError
  20. classmethod devices()
  21. Returns a cached list of AD2USB devices located on the system.
  22. Returns:
  23. cached list of devices found.
  24. classmethod create(device=None)
  25. Factory method that returns the requested AD2USB device, or the
  26. first device.
  27. Parameters:
  28. **device** (*tuple*) -- Tuple describing the USB device to
  29. open, as returned by find_all().
  30. Returns:
  31. AD2USB object utilizing the specified device.
  32. Raises :
  33. util.NoDeviceError
  34. close()
  35. Clean up and shut down.
  36. start()
  37. Starts the detection thread, if not already running.
  38. stop()
  39. Stops the detection thread.
  40. get_device(device=None)
  41. Factory method that returns the requested AD2USB device, or the
  42. first device.
  43. Parameters:
  44. **device** (*tuple*) -- Tuple describing the USB device to
  45. open, as returned by find_all().
  46. class class DetectThread(overseer)
  47. Bases: "threading.Thread"
  48. Thread that handles detection of added/removed devices.
  49. stop()
  50. Stops the thread.
  51. run()
  52. The actual detection process.
  53. class class pyad2.ad2.AD2(device)
  54. Bases: "object"
  55. High-level wrapper around AD2USB/AD2SERIAL devices.
  56. on_arm
  57. Called when the panel is armed.
  58. on_disarm
  59. Called when the panel is disarmed.
  60. on_power_changed
  61. Called when panel power switches between AC and DC.
  62. on_alarm
  63. Called when the alarm is triggered.
  64. on_fire
  65. Called when a fire is detected.
  66. on_bypass
  67. Called when a zone is bypassed.
  68. on_boot
  69. Called when the device finishes bootings.
  70. on_config_received
  71. Called when the device receives its configuration.
  72. on_zone_fault
  73. Called when the device detects a zone fault.
  74. on_zone_restore
  75. Called when the device detects that a fault is restored.
  76. on_low_battery
  77. Called when the device detects a low battery.
  78. on_panic
  79. Called when the device detects a panic.
  80. on_relay_changed
  81. Called when a relay is opened or closed on an expander board.
  82. on_message
  83. Called when a message has been received from the device.
  84. on_lrr_message
  85. Called when an LRR message is received.
  86. on_rfx_message
  87. Called when an RFX message is received.
  88. on_open
  89. Called when the device has been opened.
  90. on_close
  91. Called when the device has been closed.
  92. on_read
  93. Called when a line has been read from the device.
  94. on_write
  95. Called when data has been written to the device.
  96. F1 = u'\x01\x01\x01'
  97. Represents panel function key #1
  98. F2 = u'\x02\x02\x02'
  99. Represents panel function key #2
  100. F3 = u'\x03\x03\x03'
  101. Represents panel function key #3
  102. F4 = u'\x04\x04\x04'
  103. Represents panel function key #4
  104. BATTERY_TIMEOUT = 30
  105. Timeout before the battery status reverts.
  106. FIRE_TIMEOUT = 30
  107. Timeout before the fire status reverts.
  108. id
  109. The ID of the AD2USB device.
  110. Returns:
  111. The identification string for the device.
  112. open(baudrate=None, no_reader_thread=False)
  113. Opens the device.
  114. Parameters:
  115. * **baudrate** (*int*) -- The baudrate used for the device.
  116. * **interface** (*varies depends on device type.. FIXME*)
  117. -- The interface used for the device.
  118. * **index** (*int*) -- Interface index.. can probably
  119. remove. FIXME
  120. * **no_reader_thread** (*bool*) -- Specifies whether or not
  121. the automatic reader thread should be started or not
  122. close()
  123. Closes the device.
  124. send(data)
  125. get_config()
  126. Retrieves the configuration from the device.
  127. save_config()
  128. Sets configuration entries on the device.
  129. reboot()
  130. Reboots the device.
  131. fault_zone(zone, simulate_wire_problem=False)
  132. Faults a zone if we are emulating a zone expander.
  133. Parameters:
  134. * **zone** (*int*) -- The zone to fault.
  135. * **simulate_wire_problem** (*bool*) -- Whether or not to
  136. simulate a wire fault.
  137. clear_zone(zone)
  138. Clears a zone if we are emulating a zone expander.
  139. Parameters:
  140. **zone** (*int*) -- The zone to clear.
  141. "devices" Module
  142. ================
  143. Contains different types of devices belonging to the AD2USB family.
  144. class class pyad2.devices.Device
  145. Bases: "object"
  146. Generic parent device to all AD2USB products.
  147. on_open
  148. Called when the device has been opened
  149. on_close
  150. Called when the device has been closed
  151. on_read
  152. Called when a line has been read from the device
  153. on_write
  154. Called when data has been written to the device
  155. id
  156. Retrieve the device ID.
  157. Returns:
  158. The identification string for the device.
  159. is_reader_alive()
  160. Indicates whether or not the reader thread is alive.
  161. Returns:
  162. Whether or not the reader thread is alive.
  163. stop_reader()
  164. Stops the reader thread.
  165. close()
  166. Closes the device.
  167. class class ReadThread(device)
  168. Bases: "threading.Thread"
  169. Reader thread which processes messages from the device.
  170. READ_TIMEOUT = 10
  171. Timeout for the reader thread.
  172. stop()
  173. Stops the running thread.
  174. run()
  175. The actual read process.
  176. class class pyad2.devices.USBDevice(interface=(None, 0))
  177. Bases: "pyad2.devices.Device"
  178. AD2USB device exposed with PyFTDI's interface.
  179. FTDI_VENDOR_ID = 1027
  180. Vendor ID used to recognize AD2USB devices.
  181. FTDI_PRODUCT_ID = 24577
  182. Product ID used to recognize AD2USB devices.
  183. BAUDRATE = 115200
  184. Default baudrate for AD2USB devices.
  185. static find_all()
  186. Returns all FTDI devices matching our vendor and product IDs.
  187. Returns:
  188. list of devices
  189. Raises :
  190. util.CommError
  191. interface
  192. Retrieves the interface used to connect to the device.
  193. Returns:
  194. the interface used to connect to the device.
  195. serial_number
  196. Retrieves the serial number of the device.
  197. Returns:
  198. The serial number of the device.
  199. description
  200. Retrieves the description of the device.
  201. Returns:
  202. The description of the device.
  203. open(baudrate=115200, no_reader_thread=False)
  204. Opens the device.
  205. Parameters:
  206. * **baudrate** (*int*) -- The baudrate to use.
  207. * **no_reader_thread** (*bool*) -- Whether or not to
  208. automatically start the reader thread.
  209. Raises :
  210. util.NoDeviceError
  211. close()
  212. Closes the device.
  213. write(data)
  214. Writes data to the device.
  215. Parameters:
  216. **data** (*str*) -- Data to write
  217. Raises :
  218. util.CommError
  219. read()
  220. Reads a single character from the device.
  221. Returns:
  222. The character read from the device.
  223. Raises :
  224. util.CommError
  225. read_line(timeout=0.0, purge_buffer=False)
  226. Reads a line from the device.
  227. Parameters:
  228. * **timeout** (*float*) -- Read timeout
  229. * **purge_buffer** (*bool*) -- Indicates whether to purge
  230. the buffer prior to reading.
  231. Returns:
  232. The line that was read.
  233. Raises :
  234. util.CommError, util.TimeoutError
  235. class class pyad2.devices.SerialDevice(interface=None)
  236. Bases: "pyad2.devices.Device"
  237. AD2USB or AD2SERIAL device exposed with the pyserial interface.
  238. BAUDRATE = 19200
  239. Default baudrate for Serial devices.
  240. static find_all(pattern=None)
  241. Returns all serial ports present.
  242. Parameters:
  243. **pattern** (*str*) -- Pattern to search for when retrieving
  244. serial ports.
  245. Returns:
  246. list of devices
  247. Raises :
  248. util.CommError
  249. interface
  250. Retrieves the interface used to connect to the device.
  251. Returns:
  252. the interface used to connect to the device.
  253. open(baudrate=19200, no_reader_thread=False)
  254. Opens the device.
  255. Parameters:
  256. * **baudrate** (*int*) -- The baudrate to use with the
  257. device.
  258. * **no_reader_thread** (*bool*) -- Whether or not to
  259. automatically start the reader thread.
  260. Raises :
  261. util.NoDeviceError
  262. close()
  263. Closes the device.
  264. write(data)
  265. Writes data to the device.
  266. Parameters:
  267. **data** (*str*) -- The data to write.
  268. Raises :
  269. util.CommError
  270. read()
  271. Reads a single character from the device.
  272. Returns:
  273. The character read from the device.
  274. Raises :
  275. util.CommError
  276. read_line(timeout=0.0, purge_buffer=False)
  277. Reads a line from the device.
  278. Parameters:
  279. * **timeout** (*float*) -- The read timeout.
  280. * **purge_buffer** (*bool*) -- Indicates whether to purge
  281. the buffer prior to reading.
  282. Returns:
  283. The line read.
  284. Raises :
  285. util.CommError, util.TimeoutError
  286. class class pyad2.devices.SocketDevice(interface=('localhost', 10000))
  287. Bases: "pyad2.devices.Device"
  288. Device that supports communication with an AD2USB that is exposed
  289. via ser2sock or another Serial to IP interface.
  290. interface
  291. Retrieves the interface used to connect to the device.
  292. Returns:
  293. the interface used to connect to the device.
  294. ssl
  295. Retrieves whether or not the device is using SSL.
  296. Returns:
  297. Whether or not the device is using SSL.
  298. ssl_certificate
  299. Retrieves the SSL client certificate path used for
  300. authentication.
  301. Returns:
  302. The certificate path
  303. ssl_key
  304. Retrieves the SSL client certificate key used for
  305. authentication.
  306. Returns:
  307. The key path
  308. ssl_ca
  309. Retrieves the SSL Certificate Authority certificate used for
  310. authentication.
  311. Returns:
  312. The CA path
  313. open(baudrate=None, no_reader_thread=False)
  314. Opens the device.
  315. Parameters:
  316. * **baudrate** (*int*) -- The baudrate to use
  317. * **no_reader_thread** (*bool*) -- Whether or not to
  318. automatically open the reader thread.
  319. Raises :
  320. util.NoDeviceError, util.CommError
  321. close()
  322. Closes the device.
  323. write(data)
  324. Writes data to the device.
  325. Parameters:
  326. **data** (*str*) -- The data to write.
  327. Returns:
  328. The number of bytes sent.
  329. Raises :
  330. util.CommError
  331. read()
  332. Reads a single character from the device.
  333. Returns:
  334. The character read from the device.
  335. Raises :
  336. util.CommError
  337. read_line(timeout=0.0, purge_buffer=False)
  338. Reads a line from the device.
  339. Parameters:
  340. * **timeout** (*float*) -- The read timeout.
  341. * **purge_buffer** (*bool*) -- Indicates whether to purge
  342. the buffer prior to reading.
  343. Returns:
  344. The line read from the device.
  345. Raises :
  346. util.CommError, util.TimeoutError
  347. "util" Module
  348. =============
  349. Provides utility classes for the AD2USB devices.
  350. exception exception pyad2.util.NoDeviceError
  351. Bases: "exceptions.Exception"
  352. No devices found.
  353. exception exception pyad2.util.CommError
  354. Bases: "exceptions.Exception"
  355. There was an error communicating with the device.
  356. exception exception pyad2.util.TimeoutError
  357. Bases: "exceptions.Exception"
  358. There was a timeout while trying to communicate with the device.
  359. exception exception pyad2.util.InvalidMessageError
  360. Bases: "exceptions.Exception"
  361. The format of the panel message was invalid.
  362. class class pyad2.util.Firmware
  363. Bases: "object"
  364. Represents firmware for the AD2USB/AD2SERIAL devices.
  365. STAGE_START = 0
  366. STAGE_WAITING = 1
  367. STAGE_BOOT = 2
  368. STAGE_LOAD = 3
  369. STAGE_UPLOADING = 4
  370. STAGE_DONE = 5
  371. static upload(dev, filename, progress_callback=None)
  372. Uploads firmware to an AD2USB/AD2SERIAL device.
  373. Parameters:
  374. * **filename** (*str*) -- The firmware filename
  375. * **progress_callback** (*function*) -- Callback function
  376. used to report progress.
  377. Raises :
  378. util.NoDeviceError, util.TimeoutError
  379. "zonetracking" Module
  380. =====================
  381. Provides zone tracking functionality for the AD2USB device family.
  382. class class pyad2.zonetracking.Zone(zone=0, name='', status=0)
  383. Bases: "object"
  384. Representation of a panel zone.
  385. CLEAR = 0
  386. Status indicating that the zone is cleared.
  387. FAULT = 1
  388. Status indicating that the zone is faulted.
  389. CHECK = 2
  390. Status indicating that there is a wiring issue with the zone.
  391. STATUS = {0: 'CLEAR', 1: 'FAULT', 2: 'CHECK'}
  392. class class pyad2.zonetracking.Zonetracker
  393. Bases: "object"
  394. Handles tracking of zone and their statuses.
  395. on_fault
  396. Called when the device detects a zone fault.
  397. on_restore
  398. Called when the device detects that a fault is restored.
  399. EXPIRE = 30
  400. Zone expiration timeout.
  401. update(message)
  402. Update zone statuses based on the current message.
  403. Parameters:
  404. **message** (*Message or ExpanderMessage*) -- Message to use
  405. to update the zone tracking.
  406. "panels" Module
  407. ===============
  408. Representations of Panels and their templates.
  409. "messages" Module
  410. =================
  411. Message representations received from the panel through the AD2USB.
  412. class class pyad2.messages.BaseMessage
  413. Bases: "object"
  414. Base class for messages.
  415. class class pyad2.messages.Message(data=None)
  416. Bases: "pyad2.messages.BaseMessage"
  417. Represents a message from the alarm panel.
  418. class class pyad2.messages.ExpanderMessage(data=None)
  419. Bases: "pyad2.messages.BaseMessage"
  420. Represents a message from a zone or relay expansion module.
  421. ZONE = 0
  422. RELAY = 1
  423. class class pyad2.messages.RFMessage(data=None)
  424. Bases: "pyad2.messages.BaseMessage"
  425. Represents a message from an RF receiver.
  426. class class pyad2.messages.LRRMessage(data=None)
  427. Bases: "pyad2.messages.BaseMessage"
  428. Represent a message from a Long Range Radio.
  429. Subpackages
  430. ===========
  431. * event Package
  432. * "event" Package
  433. * "event" Module