@@ -48,7 +48,9 @@ | |||
<ul><li><a href="pyad2usb/ad2usb.html">pyad2usb.ad2usb</a></li> | |||
<li><a href="pyad2usb/devices.html">pyad2usb.devices</a></li> | |||
<li><a href="pyad2usb/event/event.html">pyad2usb.event.event</a></li> | |||
<li><a href="pyad2usb/messages.html">pyad2usb.messages</a></li> | |||
<li><a href="pyad2usb/util.html">pyad2usb.util</a></li> | |||
<li><a href="pyad2usb/zonetracking.html">pyad2usb.zonetracking</a></li> | |||
</ul> | |||
</div> | |||
@@ -0,0 +1,289 @@ | |||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" | |||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |||
<html xmlns="http://www.w3.org/1999/xhtml"> | |||
<head> | |||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | |||
<title>pyad2usb.messages — pyad2usb documentation</title> | |||
<link rel="stylesheet" href="../../_static/default.css" type="text/css" /> | |||
<link rel="stylesheet" href="../../_static/pygments.css" type="text/css" /> | |||
<script type="text/javascript"> | |||
var DOCUMENTATION_OPTIONS = { | |||
URL_ROOT: '../../', | |||
VERSION: '', | |||
COLLAPSE_INDEX: false, | |||
FILE_SUFFIX: '.html', | |||
HAS_SOURCE: true | |||
}; | |||
</script> | |||
<script type="text/javascript" src="../../_static/jquery.js"></script> | |||
<script type="text/javascript" src="../../_static/underscore.js"></script> | |||
<script type="text/javascript" src="../../_static/doctools.js"></script> | |||
<link rel="top" title="pyad2usb documentation" href="../../index.html" /> | |||
<link rel="up" title="Module code" href="../index.html" /> | |||
</head> | |||
<body> | |||
<div class="related"> | |||
<h3>Navigation</h3> | |||
<ul> | |||
<li class="right" style="margin-right: 10px"> | |||
<a href="../../genindex.html" title="General Index" | |||
accesskey="I">index</a></li> | |||
<li class="right" > | |||
<a href="../../py-modindex.html" title="Python Module Index" | |||
>modules</a> |</li> | |||
<li><a href="../../index.html">pyad2usb documentation</a> »</li> | |||
<li><a href="../index.html" accesskey="U">Module code</a> »</li> | |||
</ul> | |||
</div> | |||
<div class="document"> | |||
<div class="documentwrapper"> | |||
<div class="bodywrapper"> | |||
<div class="body"> | |||
<h1>Source code for pyad2usb.messages</h1><div class="highlight"><pre> | |||
<span class="sd">"""</span> | |||
<span class="sd">Message representations received from the panel through the AD2USB.</span> | |||
<span class="sd">"""</span> | |||
<span class="kn">import</span> <span class="nn">re</span> | |||
<div class="viewcode-block" id="Message"><a class="viewcode-back" href="../../pyad2usb.html#pyad2usb.messages.Message">[docs]</a><span class="k">class</span> <span class="nc">Message</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span> | |||
<span class="sd">"""</span> | |||
<span class="sd"> Represents a message from the alarm panel.</span> | |||
<span class="sd"> """</span> | |||
<span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span> | |||
<span class="sd">"""</span> | |||
<span class="sd"> Constructor</span> | |||
<span class="sd"> """</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">ready</span> <span class="o">=</span> <span class="bp">False</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">armed_away</span> <span class="o">=</span> <span class="bp">False</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">armed_home</span> <span class="o">=</span> <span class="bp">False</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">backlight_on</span> <span class="o">=</span> <span class="bp">False</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">programming_mode</span> <span class="o">=</span> <span class="bp">False</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">beeps</span> <span class="o">=</span> <span class="o">-</span><span class="mi">1</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">zone_bypassed</span> <span class="o">=</span> <span class="bp">False</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">ac_power</span> <span class="o">=</span> <span class="bp">False</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">chime_on</span> <span class="o">=</span> <span class="bp">False</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">alarm_event_occurred</span> <span class="o">=</span> <span class="bp">False</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">alarm_sounding</span> <span class="o">=</span> <span class="bp">False</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">battery_low</span> <span class="o">=</span> <span class="bp">False</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">entry_delay_off</span> <span class="o">=</span> <span class="bp">False</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">fire_alarm</span> <span class="o">=</span> <span class="bp">False</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">check_zone</span> <span class="o">=</span> <span class="bp">False</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">perimeter_only</span> <span class="o">=</span> <span class="bp">False</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">numeric_code</span> <span class="o">=</span> <span class="s">""</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">text</span> <span class="o">=</span> <span class="s">""</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">cursor_location</span> <span class="o">=</span> <span class="o">-</span><span class="mi">1</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">data</span> <span class="o">=</span> <span class="s">""</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">mask</span> <span class="o">=</span> <span class="s">""</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">bitfield</span> <span class="o">=</span> <span class="s">""</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">panel_data</span> <span class="o">=</span> <span class="s">""</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">_regex</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">compile</span><span class="p">(</span><span class="s">'("(?:[^"]|"")*"|[^,]*),("(?:[^"]|"")*"|[^,]*),("(?:[^"]|"")*"|[^,]*),("(?:[^"]|"")*"|[^,]*)'</span><span class="p">)</span> | |||
<span class="k">if</span> <span class="n">data</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">_parse_message</span><span class="p">(</span><span class="n">data</span><span class="p">)</span> | |||
<span class="k">def</span> <span class="nf">_parse_message</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">):</span> | |||
<span class="sd">"""</span> | |||
<span class="sd"> Parse the message from the device.</span> | |||
<span class="sd"> """</span> | |||
<span class="n">m</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_regex</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">data</span><span class="p">)</span> | |||
<span class="k">if</span> <span class="n">m</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span> | |||
<span class="k">raise</span> <span class="n">util</span><span class="o">.</span><span class="n">InvalidMessageError</span><span class="p">(</span><span class="s">'Received invalid message: {0}'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">data</span><span class="p">))</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">bitfield</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">numeric_code</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">panel_data</span><span class="p">,</span> <span class="n">alpha</span> <span class="o">=</span> <span class="n">m</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">)</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">mask</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">panel_data</span><span class="p">[</span><span class="mi">3</span><span class="p">:</span><span class="mi">3</span><span class="o">+</span><span class="mi">8</span><span class="p">],</span> <span class="mi">16</span><span class="p">)</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">data</span> <span class="o">=</span> <span class="n">data</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">ready</span> <span class="o">=</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">bitfield</span><span class="p">[</span><span class="mi">1</span><span class="p">:</span><span class="mi">2</span><span class="p">]</span> <span class="o">==</span> <span class="s">"0"</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">armed_away</span> <span class="o">=</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">bitfield</span><span class="p">[</span><span class="mi">2</span><span class="p">:</span><span class="mi">3</span><span class="p">]</span> <span class="o">==</span> <span class="s">"0"</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">armed_home</span> <span class="o">=</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">bitfield</span><span class="p">[</span><span class="mi">3</span><span class="p">:</span><span class="mi">4</span><span class="p">]</span> <span class="o">==</span> <span class="s">"0"</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">backlight_on</span> <span class="o">=</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">bitfield</span><span class="p">[</span><span class="mi">4</span><span class="p">:</span><span class="mi">5</span><span class="p">]</span> <span class="o">==</span> <span class="s">"0"</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">programming_mode</span> <span class="o">=</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">bitfield</span><span class="p">[</span><span class="mi">5</span><span class="p">:</span><span class="mi">6</span><span class="p">]</span> <span class="o">==</span> <span class="s">"0"</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">beeps</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">bitfield</span><span class="p">[</span><span class="mi">6</span><span class="p">:</span><span class="mi">7</span><span class="p">],</span> <span class="mi">16</span><span class="p">)</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">zone_bypassed</span> <span class="o">=</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">bitfield</span><span class="p">[</span><span class="mi">7</span><span class="p">:</span><span class="mi">8</span><span class="p">]</span> <span class="o">==</span> <span class="s">"0"</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">ac_power</span> <span class="o">=</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">bitfield</span><span class="p">[</span><span class="mi">8</span><span class="p">:</span><span class="mi">9</span><span class="p">]</span> <span class="o">==</span> <span class="s">"0"</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">chime_on</span> <span class="o">=</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">bitfield</span><span class="p">[</span><span class="mi">9</span><span class="p">:</span><span class="mi">10</span><span class="p">]</span> <span class="o">==</span> <span class="s">"0"</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">alarm_event_occurred</span> <span class="o">=</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">bitfield</span><span class="p">[</span><span class="mi">10</span><span class="p">:</span><span class="mi">11</span><span class="p">]</span> <span class="o">==</span> <span class="s">"0"</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">alarm_sounding</span> <span class="o">=</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">bitfield</span><span class="p">[</span><span class="mi">11</span><span class="p">:</span><span class="mi">12</span><span class="p">]</span> <span class="o">==</span> <span class="s">"0"</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">battery_low</span> <span class="o">=</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">bitfield</span><span class="p">[</span><span class="mi">12</span><span class="p">:</span><span class="mi">13</span><span class="p">]</span> <span class="o">==</span> <span class="s">"0"</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">entry_delay_off</span> <span class="o">=</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">bitfield</span><span class="p">[</span><span class="mi">13</span><span class="p">:</span><span class="mi">14</span><span class="p">]</span> <span class="o">==</span> <span class="s">"0"</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">fire_alarm</span> <span class="o">=</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">bitfield</span><span class="p">[</span><span class="mi">14</span><span class="p">:</span><span class="mi">15</span><span class="p">]</span> <span class="o">==</span> <span class="s">"0"</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">check_zone</span> <span class="o">=</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">bitfield</span><span class="p">[</span><span class="mi">15</span><span class="p">:</span><span class="mi">16</span><span class="p">]</span> <span class="o">==</span> <span class="s">"0"</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">perimeter_only</span> <span class="o">=</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">bitfield</span><span class="p">[</span><span class="mi">16</span><span class="p">:</span><span class="mi">17</span><span class="p">]</span> <span class="o">==</span> <span class="s">"0"</span> | |||
<span class="c"># bits 17-20 unused.</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">text</span> <span class="o">=</span> <span class="n">alpha</span><span class="o">.</span><span class="n">strip</span><span class="p">(</span><span class="s">'"'</span><span class="p">)</span> | |||
<span class="k">if</span> <span class="nb">int</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">panel_data</span><span class="p">[</span><span class="mi">19</span><span class="p">:</span><span class="mi">21</span><span class="p">],</span> <span class="mi">16</span><span class="p">)</span> <span class="o">&</span> <span class="mh">0x01</span> <span class="o">></span> <span class="mi">0</span><span class="p">:</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">cursor_location</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">bitfield</span><span class="p">[</span><span class="mi">21</span><span class="p">:</span><span class="mi">23</span><span class="p">],</span> <span class="mi">16</span><span class="p">)</span> <span class="c"># Alpha character index that the cursor is on.</span> | |||
<span class="k">def</span> <span class="nf">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> | |||
<span class="sd">"""</span> | |||
<span class="sd"> String conversion operator.</span> | |||
<span class="sd"> """</span> | |||
<span class="k">return</span> <span class="s">'msg > {0:0<9} [{1}{2}{3}] -- ({4}) {5}'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">hex</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">mask</span><span class="p">),</span> <span class="mi">1</span> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">ready</span> <span class="k">else</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">armed_away</span> <span class="k">else</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">armed_home</span> <span class="k">else</span> <span class="mi">0</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">numeric_code</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">text</span><span class="p">)</span> | |||
</div> | |||
<div class="viewcode-block" id="ExpanderMessage"><a class="viewcode-back" href="../../pyad2usb.html#pyad2usb.messages.ExpanderMessage">[docs]</a><span class="k">class</span> <span class="nc">ExpanderMessage</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span> | |||
<span class="sd">"""</span> | |||
<span class="sd"> Represents a message from a zone or relay expansion module.</span> | |||
<span class="sd"> """</span> | |||
<span class="n">ZONE</span> <span class="o">=</span> <span class="mi">0</span> | |||
<span class="n">RELAY</span> <span class="o">=</span> <span class="mi">1</span> | |||
<span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span> | |||
<span class="sd">"""</span> | |||
<span class="sd"> Constructor</span> | |||
<span class="sd"> """</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">type</span> <span class="o">=</span> <span class="bp">None</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">address</span> <span class="o">=</span> <span class="bp">None</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">channel</span> <span class="o">=</span> <span class="bp">None</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">value</span> <span class="o">=</span> <span class="bp">None</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">raw</span> <span class="o">=</span> <span class="bp">None</span> | |||
<span class="k">if</span> <span class="n">data</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">_parse_message</span><span class="p">(</span><span class="n">data</span><span class="p">)</span> | |||
<span class="k">def</span> <span class="nf">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> | |||
<span class="sd">"""</span> | |||
<span class="sd"> String conversion operator.</span> | |||
<span class="sd"> """</span> | |||
<span class="n">expander_type</span> <span class="o">=</span> <span class="s">'UNKWN'</span> | |||
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">type</span> <span class="o">==</span> <span class="n">ExpanderMessage</span><span class="o">.</span><span class="n">ZONE</span><span class="p">:</span> | |||
<span class="n">expander_type</span> <span class="o">=</span> <span class="s">'ZONE'</span> | |||
<span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">type</span> <span class="o">==</span> <span class="n">ExpanderMessage</span><span class="o">.</span><span class="n">RELAY</span><span class="p">:</span> | |||
<span class="n">expander_type</span> <span class="o">=</span> <span class="s">'RELAY'</span> | |||
<span class="k">return</span> <span class="s">'exp > [{0: <5}] {1}/{2} -- {3}'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">expander_type</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">address</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">channel</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">value</span><span class="p">)</span> | |||
<span class="k">def</span> <span class="nf">_parse_message</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">):</span> | |||
<span class="sd">"""</span> | |||
<span class="sd"> Parse the raw message from the device.</span> | |||
<span class="sd"> """</span> | |||
<span class="n">header</span><span class="p">,</span> <span class="n">values</span> <span class="o">=</span> <span class="n">data</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">':'</span><span class="p">)</span> | |||
<span class="n">address</span><span class="p">,</span> <span class="n">channel</span><span class="p">,</span> <span class="n">value</span> <span class="o">=</span> <span class="n">values</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">','</span><span class="p">)</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">raw</span> <span class="o">=</span> <span class="n">data</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">address</span> <span class="o">=</span> <span class="n">address</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">channel</span> <span class="o">=</span> <span class="n">channel</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">value</span> <span class="o">=</span> <span class="n">value</span> | |||
<span class="k">if</span> <span class="n">header</span> <span class="o">==</span> <span class="s">'!EXP'</span><span class="p">:</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">type</span> <span class="o">=</span> <span class="n">ExpanderMessage</span><span class="o">.</span><span class="n">ZONE</span> | |||
<span class="k">elif</span> <span class="n">header</span> <span class="o">==</span> <span class="s">'!REL'</span><span class="p">:</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">type</span> <span class="o">=</span> <span class="n">ExpanderMessage</span><span class="o">.</span><span class="n">RELAY</span> | |||
</div> | |||
<div class="viewcode-block" id="RFMessage"><a class="viewcode-back" href="../../pyad2usb.html#pyad2usb.messages.RFMessage">[docs]</a><span class="k">class</span> <span class="nc">RFMessage</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span> | |||
<span class="sd">"""</span> | |||
<span class="sd"> Represents a message from an RF receiver.</span> | |||
<span class="sd"> """</span> | |||
<span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span> | |||
<span class="sd">"""</span> | |||
<span class="sd"> Constructor</span> | |||
<span class="sd"> """</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">raw</span> <span class="o">=</span> <span class="bp">None</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">serial_number</span> <span class="o">=</span> <span class="bp">None</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">value</span> <span class="o">=</span> <span class="bp">None</span> | |||
<span class="k">if</span> <span class="n">data</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">_parse_message</span><span class="p">(</span><span class="n">data</span><span class="p">)</span> | |||
<span class="k">def</span> <span class="nf">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> | |||
<span class="sd">"""</span> | |||
<span class="sd"> String conversion operator.</span> | |||
<span class="sd"> """</span> | |||
<span class="k">return</span> <span class="s">'rf > {0}: {1}'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">serial_number</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">value</span><span class="p">)</span> | |||
<span class="k">def</span> <span class="nf">_parse_message</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">):</span> | |||
<span class="sd">"""</span> | |||
<span class="sd"> Parses the raw message from the device.</span> | |||
<span class="sd"> """</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">raw</span> <span class="o">=</span> <span class="n">data</span> | |||
<span class="n">_</span><span class="p">,</span> <span class="n">values</span> <span class="o">=</span> <span class="n">data</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">':'</span><span class="p">)</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">serial_number</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">value</span> <span class="o">=</span> <span class="n">values</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">','</span><span class="p">)</span> | |||
</div> | |||
<div class="viewcode-block" id="LRRMessage"><a class="viewcode-back" href="../../pyad2usb.html#pyad2usb.messages.LRRMessage">[docs]</a><span class="k">class</span> <span class="nc">LRRMessage</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span> | |||
<span class="sd">"""</span> | |||
<span class="sd"> Represent a message from a Long Range Radio.</span> | |||
<span class="sd"> """</span> | |||
<span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span> | |||
<span class="sd">"""</span> | |||
<span class="sd"> Constructor</span> | |||
<span class="sd"> """</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">raw</span> <span class="o">=</span> <span class="bp">None</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">_event_data</span> <span class="o">=</span> <span class="bp">None</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">_partition</span> <span class="o">=</span> <span class="bp">None</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">_event_type</span> <span class="o">=</span> <span class="bp">None</span> | |||
<span class="k">if</span> <span class="n">data</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">_parse_message</span><span class="p">(</span><span class="n">data</span><span class="p">)</span> | |||
<span class="k">def</span> <span class="nf">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> | |||
<span class="sd">"""</span> | |||
<span class="sd"> String conversion operator.</span> | |||
<span class="sd"> """</span> | |||
<span class="k">return</span> <span class="s">'lrr > {0} @ {1} -- {2}'</span><span class="o">.</span><span class="n">format</span><span class="p">()</span> | |||
<span class="k">def</span> <span class="nf">_parse_message</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">):</span> | |||
<span class="sd">"""</span> | |||
<span class="sd"> Parses the raw message from the device.</span> | |||
<span class="sd"> """</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">raw</span> <span class="o">=</span> <span class="n">data</span> | |||
<span class="n">_</span><span class="p">,</span> <span class="n">values</span> <span class="o">=</span> <span class="n">data</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">':'</span><span class="p">)</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">_event_data</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_partition</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_event_type</span> <span class="o">=</span> <span class="n">values</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">','</span><span class="p">)</span></div> | |||
</pre></div> | |||
</div> | |||
</div> | |||
</div> | |||
<div class="sphinxsidebar"> | |||
<div class="sphinxsidebarwrapper"> | |||
<div id="searchbox" style="display: none"> | |||
<h3>Quick search</h3> | |||
<form class="search" action="../../search.html" method="get"> | |||
<input type="text" name="q" /> | |||
<input type="submit" value="Go" /> | |||
<input type="hidden" name="check_keywords" value="yes" /> | |||
<input type="hidden" name="area" value="default" /> | |||
</form> | |||
<p class="searchtip" style="font-size: 90%"> | |||
Enter search terms or a module, class or function name. | |||
</p> | |||
</div> | |||
<script type="text/javascript">$('#searchbox').show(0);</script> | |||
</div> | |||
</div> | |||
<div class="clearer"></div> | |||
</div> | |||
<div class="related"> | |||
<h3>Navigation</h3> | |||
<ul> | |||
<li class="right" style="margin-right: 10px"> | |||
<a href="../../genindex.html" title="General Index" | |||
>index</a></li> | |||
<li class="right" > | |||
<a href="../../py-modindex.html" title="Python Module Index" | |||
>modules</a> |</li> | |||
<li><a href="../../index.html">pyad2usb documentation</a> »</li> | |||
<li><a href="../index.html" >Module code</a> »</li> | |||
</ul> | |||
</div> | |||
<div class="footer"> | |||
© Copyright 2013, Author. | |||
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.2b1. | |||
</div> | |||
</body> | |||
</html> |
@@ -0,0 +1,368 @@ | |||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" | |||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |||
<html xmlns="http://www.w3.org/1999/xhtml"> | |||
<head> | |||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | |||
<title>pyad2usb.zonetracking — pyad2usb documentation</title> | |||
<link rel="stylesheet" href="../../_static/default.css" type="text/css" /> | |||
<link rel="stylesheet" href="../../_static/pygments.css" type="text/css" /> | |||
<script type="text/javascript"> | |||
var DOCUMENTATION_OPTIONS = { | |||
URL_ROOT: '../../', | |||
VERSION: '', | |||
COLLAPSE_INDEX: false, | |||
FILE_SUFFIX: '.html', | |||
HAS_SOURCE: true | |||
}; | |||
</script> | |||
<script type="text/javascript" src="../../_static/jquery.js"></script> | |||
<script type="text/javascript" src="../../_static/underscore.js"></script> | |||
<script type="text/javascript" src="../../_static/doctools.js"></script> | |||
<link rel="top" title="pyad2usb documentation" href="../../index.html" /> | |||
<link rel="up" title="Module code" href="../index.html" /> | |||
</head> | |||
<body> | |||
<div class="related"> | |||
<h3>Navigation</h3> | |||
<ul> | |||
<li class="right" style="margin-right: 10px"> | |||
<a href="../../genindex.html" title="General Index" | |||
accesskey="I">index</a></li> | |||
<li class="right" > | |||
<a href="../../py-modindex.html" title="Python Module Index" | |||
>modules</a> |</li> | |||
<li><a href="../../index.html">pyad2usb documentation</a> »</li> | |||
<li><a href="../index.html" accesskey="U">Module code</a> »</li> | |||
</ul> | |||
</div> | |||
<div class="document"> | |||
<div class="documentwrapper"> | |||
<div class="bodywrapper"> | |||
<div class="body"> | |||
<h1>Source code for pyad2usb.zonetracking</h1><div class="highlight"><pre> | |||
<span class="sd">"""</span> | |||
<span class="sd">Provides zone tracking functionality for the AD2USB device family.</span> | |||
<span class="sd">"""</span> | |||
<span class="kn">import</span> <span class="nn">time</span> | |||
<span class="kn">from</span> <span class="nn">.event</span> <span class="kn">import</span> <span class="n">event</span> | |||
<span class="kn">from</span> <span class="nn">.</span> <span class="kn">import</span> <span class="n">messages</span> | |||
<div class="viewcode-block" id="Zone"><a class="viewcode-back" href="../../pyad2usb.html#pyad2usb.zonetracking.Zone">[docs]</a><span class="k">class</span> <span class="nc">Zone</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span> | |||
<span class="sd">"""</span> | |||
<span class="sd"> Representation of a panel zone.</span> | |||
<span class="sd"> """</span> | |||
<span class="n">CLEAR</span> <span class="o">=</span> <span class="mi">0</span> | |||
<span class="sd">"""Status indicating that the zone is cleared."""</span> | |||
<span class="n">FAULT</span> <span class="o">=</span> <span class="mi">1</span> | |||
<span class="sd">"""Status indicating that the zone is faulted."""</span> | |||
<span class="n">CHECK</span> <span class="o">=</span> <span class="mi">2</span> <span class="c"># Wire fault</span> | |||
<span class="sd">"""Status indicating that there is a wiring issue with the zone."""</span> | |||
<span class="n">STATUS</span> <span class="o">=</span> <span class="p">{</span> <span class="n">CLEAR</span><span class="p">:</span> <span class="s">'CLEAR'</span><span class="p">,</span> <span class="n">FAULT</span><span class="p">:</span> <span class="s">'FAULT'</span><span class="p">,</span> <span class="n">CHECK</span><span class="p">:</span> <span class="s">'CHECK'</span> <span class="p">}</span> | |||
<span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">zone</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="s">''</span><span class="p">,</span> <span class="n">status</span><span class="o">=</span><span class="n">CLEAR</span><span class="p">):</span> | |||
<span class="sd">"""</span> | |||
<span class="sd"> Constructor</span> | |||
<span class="sd"> :param zone: The zone number.</span> | |||
<span class="sd"> :type zone: int</span> | |||
<span class="sd"> :param name: Human readable zone name.</span> | |||
<span class="sd"> :type name: str</span> | |||
<span class="sd"> :param status: Initial zone state.</span> | |||
<span class="sd"> :type status: int</span> | |||
<span class="sd"> """</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">zone</span> <span class="o">=</span> <span class="n">zone</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="n">name</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">status</span> <span class="o">=</span> <span class="n">status</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">timestamp</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span> | |||
<span class="k">def</span> <span class="nf">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> | |||
<span class="sd">"""</span> | |||
<span class="sd"> String conversion operator.</span> | |||
<span class="sd"> """</span> | |||
<span class="k">return</span> <span class="s">'Zone {0} {1}'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">zone</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">)</span> | |||
<span class="k">def</span> <span class="nf">__repr__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> | |||
<span class="sd">"""</span> | |||
<span class="sd"> Human readable representation operator.</span> | |||
<span class="sd"> """</span> | |||
<span class="k">return</span> <span class="s">'Zone({0}, {1}, ts {2})'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">zone</span><span class="p">,</span> <span class="n">Zone</span><span class="o">.</span><span class="n">STATUS</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">status</span><span class="p">],</span> <span class="bp">self</span><span class="o">.</span><span class="n">timestamp</span><span class="p">)</span> | |||
</div> | |||
<div class="viewcode-block" id="Zonetracker"><a class="viewcode-back" href="../../pyad2usb.html#pyad2usb.zonetracking.Zonetracker">[docs]</a><span class="k">class</span> <span class="nc">Zonetracker</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span> | |||
<span class="sd">"""</span> | |||
<span class="sd"> Handles tracking of zone and their statuses.</span> | |||
<span class="sd"> """</span> | |||
<span class="n">on_fault</span> <span class="o">=</span> <span class="n">event</span><span class="o">.</span><span class="n">Event</span><span class="p">(</span><span class="s">'Called when the device detects a zone fault.'</span><span class="p">)</span> | |||
<span class="n">on_restore</span> <span class="o">=</span> <span class="n">event</span><span class="o">.</span><span class="n">Event</span><span class="p">(</span><span class="s">'Called when the device detects that a fault is restored.'</span><span class="p">)</span> | |||
<span class="n">EXPIRE</span> <span class="o">=</span> <span class="mi">30</span> | |||
<span class="sd">"""Zone expiration timeout."""</span> | |||
<span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> | |||
<span class="sd">"""</span> | |||
<span class="sd"> Constructor</span> | |||
<span class="sd"> """</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">_zones</span> <span class="o">=</span> <span class="p">{}</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">_zones_faulted</span> <span class="o">=</span> <span class="p">[]</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">_last_zone_fault</span> <span class="o">=</span> <span class="mi">0</span> | |||
<div class="viewcode-block" id="Zonetracker.update"><a class="viewcode-back" href="../../pyad2usb.html#pyad2usb.zonetracking.Zonetracker.update">[docs]</a> <span class="k">def</span> <span class="nf">update</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">message</span><span class="p">):</span> | |||
<span class="sd">"""</span> | |||
<span class="sd"> Update zone statuses based on the current message.</span> | |||
<span class="sd"> :param message: Message to use to update the zone tracking.</span> | |||
<span class="sd"> :type message: Message or ExpanderMessage</span> | |||
<span class="sd"> """</span> | |||
<span class="n">zone</span> <span class="o">=</span> <span class="o">-</span><span class="mi">1</span> | |||
<span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">message</span><span class="p">,</span> <span class="n">messages</span><span class="o">.</span><span class="n">ExpanderMessage</span><span class="p">):</span> | |||
<span class="k">if</span> <span class="n">message</span><span class="o">.</span><span class="n">type</span> <span class="o">==</span> <span class="n">messages</span><span class="o">.</span><span class="n">ExpanderMessage</span><span class="o">.</span><span class="n">ZONE</span><span class="p">:</span> | |||
<span class="n">zone</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_expander_to_zone</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">message</span><span class="o">.</span><span class="n">address</span><span class="p">),</span> <span class="nb">int</span><span class="p">(</span><span class="n">message</span><span class="o">.</span><span class="n">channel</span><span class="p">))</span> | |||
<span class="n">status</span> <span class="o">=</span> <span class="n">Zone</span><span class="o">.</span><span class="n">CLEAR</span> | |||
<span class="k">if</span> <span class="nb">int</span><span class="p">(</span><span class="n">message</span><span class="o">.</span><span class="n">value</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span> | |||
<span class="n">status</span> <span class="o">=</span> <span class="n">Zone</span><span class="o">.</span><span class="n">FAULT</span> | |||
<span class="k">elif</span> <span class="nb">int</span><span class="p">(</span><span class="n">message</span><span class="o">.</span><span class="n">value</span><span class="p">)</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span> | |||
<span class="n">status</span> <span class="o">=</span> <span class="n">Zone</span><span class="o">.</span><span class="n">CHECK</span> | |||
<span class="k">try</span><span class="p">:</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">_update_zone</span><span class="p">(</span><span class="n">zone</span><span class="p">,</span> <span class="n">status</span><span class="o">=</span><span class="n">status</span><span class="p">)</span> | |||
<span class="k">except</span> <span class="ne">IndexError</span><span class="p">:</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">_add_zone</span><span class="p">(</span><span class="n">zone</span><span class="p">,</span> <span class="n">status</span><span class="o">=</span><span class="n">status</span><span class="p">)</span> | |||
<span class="k">else</span><span class="p">:</span> | |||
<span class="c"># Panel is ready, restore all zones.</span> | |||
<span class="k">if</span> <span class="n">message</span><span class="o">.</span><span class="n">ready</span><span class="p">:</span> | |||
<span class="k">for</span> <span class="n">idx</span><span class="p">,</span> <span class="n">z</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_zones_faulted</span><span class="p">):</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">_update_zone</span><span class="p">(</span><span class="n">z</span><span class="p">,</span> <span class="n">Zone</span><span class="o">.</span><span class="n">CLEAR</span><span class="p">)</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">_last_zone_fault</span> <span class="o">=</span> <span class="mi">0</span> | |||
<span class="c"># Process fault</span> | |||
<span class="k">elif</span> <span class="s">"FAULT"</span> <span class="ow">in</span> <span class="n">message</span><span class="o">.</span><span class="n">text</span> <span class="ow">or</span> <span class="n">message</span><span class="o">.</span><span class="n">check_zone</span><span class="p">:</span> | |||
<span class="c"># Apparently this representation can be both base 10</span> | |||
<span class="c"># or base 16, depending on where the message came</span> | |||
<span class="c"># from.</span> | |||
<span class="k">try</span><span class="p">:</span> | |||
<span class="n">zone</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">message</span><span class="o">.</span><span class="n">numeric_code</span><span class="p">)</span> | |||
<span class="k">except</span> <span class="ne">ValueError</span><span class="p">:</span> | |||
<span class="n">zone</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">message</span><span class="o">.</span><span class="n">numeric_code</span><span class="p">,</span> <span class="mi">16</span><span class="p">)</span> | |||
<span class="c"># Add new zones and clear expired ones.</span> | |||
<span class="k">if</span> <span class="n">zone</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_zones_faulted</span><span class="p">:</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">_update_zone</span><span class="p">(</span><span class="n">zone</span><span class="p">)</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">_clear_zones</span><span class="p">(</span><span class="n">zone</span><span class="p">)</span> | |||
<span class="k">else</span><span class="p">:</span> | |||
<span class="n">status</span> <span class="o">=</span> <span class="n">Zone</span><span class="o">.</span><span class="n">FAULT</span> | |||
<span class="k">if</span> <span class="n">message</span><span class="o">.</span><span class="n">check_zone</span><span class="p">:</span> | |||
<span class="n">status</span> <span class="o">=</span> <span class="n">Zone</span><span class="o">.</span><span class="n">CHECK</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">_add_zone</span><span class="p">(</span><span class="n">zone</span><span class="p">,</span> <span class="n">status</span><span class="o">=</span><span class="n">status</span><span class="p">)</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">_zones_faulted</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">zone</span><span class="p">)</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">_zones_faulted</span><span class="o">.</span><span class="n">sort</span><span class="p">()</span> | |||
<span class="c"># Save our spot for the next message.</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">_last_zone_fault</span> <span class="o">=</span> <span class="n">zone</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">_clear_expired_zones</span><span class="p">()</span> | |||
</div> | |||
<span class="k">def</span> <span class="nf">_clear_zones</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">zone</span><span class="p">):</span> | |||
<span class="sd">"""</span> | |||
<span class="sd"> Clear all expired zones from our status list.</span> | |||
<span class="sd"> :param zone: current zone being processed.</span> | |||
<span class="sd"> :type zone: int</span> | |||
<span class="sd"> """</span> | |||
<span class="n">cleared_zones</span> <span class="o">=</span> <span class="p">[]</span> | |||
<span class="n">found_last</span> <span class="o">=</span> <span class="n">found_new</span> <span class="o">=</span> <span class="n">at_end</span> <span class="o">=</span> <span class="bp">False</span> | |||
<span class="c"># First pass: Find our start spot.</span> | |||
<span class="n">it</span> <span class="o">=</span> <span class="nb">iter</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_zones_faulted</span><span class="p">)</span> | |||
<span class="k">try</span><span class="p">:</span> | |||
<span class="k">while</span> <span class="ow">not</span> <span class="n">found_last</span><span class="p">:</span> | |||
<span class="n">z</span> <span class="o">=</span> <span class="n">it</span><span class="o">.</span><span class="n">next</span><span class="p">()</span> | |||
<span class="k">if</span> <span class="n">z</span> <span class="o">==</span> <span class="bp">self</span><span class="o">.</span><span class="n">_last_zone_fault</span><span class="p">:</span> | |||
<span class="n">found_last</span> <span class="o">=</span> <span class="bp">True</span> | |||
<span class="k">break</span> | |||
<span class="k">except</span> <span class="ne">StopIteration</span><span class="p">:</span> | |||
<span class="n">at_end</span> <span class="o">=</span> <span class="bp">True</span> | |||
<span class="c"># Continue until we find our end point and add zones in</span> | |||
<span class="c"># between to our clear list.</span> | |||
<span class="k">try</span><span class="p">:</span> | |||
<span class="k">while</span> <span class="ow">not</span> <span class="n">at_end</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">found_new</span><span class="p">:</span> | |||
<span class="n">z</span> <span class="o">=</span> <span class="n">it</span><span class="o">.</span><span class="n">next</span><span class="p">()</span> | |||
<span class="k">if</span> <span class="n">z</span> <span class="o">==</span> <span class="n">zone</span><span class="p">:</span> | |||
<span class="n">found_new</span> <span class="o">=</span> <span class="bp">True</span> | |||
<span class="k">break</span> | |||
<span class="k">else</span><span class="p">:</span> | |||
<span class="n">cleared_zones</span> <span class="o">+=</span> <span class="p">[</span><span class="n">z</span><span class="p">]</span> | |||
<span class="k">except</span> <span class="ne">StopIteration</span><span class="p">:</span> | |||
<span class="k">pass</span> | |||
<span class="c"># Second pass: roll through the list again if we didn't find</span> | |||
<span class="c"># our end point and remove everything until we do.</span> | |||
<span class="k">if</span> <span class="ow">not</span> <span class="n">found_new</span><span class="p">:</span> | |||
<span class="n">it</span> <span class="o">=</span> <span class="nb">iter</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_zones_faulted</span><span class="p">)</span> | |||
<span class="k">try</span><span class="p">:</span> | |||
<span class="k">while</span> <span class="ow">not</span> <span class="n">found_new</span><span class="p">:</span> | |||
<span class="n">z</span> <span class="o">=</span> <span class="n">it</span><span class="o">.</span><span class="n">next</span><span class="p">()</span> | |||
<span class="k">if</span> <span class="n">z</span> <span class="o">==</span> <span class="n">zone</span><span class="p">:</span> | |||
<span class="n">found_new</span> <span class="o">=</span> <span class="bp">True</span> | |||
<span class="k">break</span> | |||
<span class="k">else</span><span class="p">:</span> | |||
<span class="n">cleared_zones</span> <span class="o">+=</span> <span class="p">[</span><span class="n">z</span><span class="p">]</span> | |||
<span class="k">except</span> <span class="ne">StopIteration</span><span class="p">:</span> | |||
<span class="k">pass</span> | |||
<span class="c"># Actually remove the zones and trigger the restores.</span> | |||
<span class="k">for</span> <span class="n">idx</span><span class="p">,</span> <span class="n">z</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">cleared_zones</span><span class="p">):</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">_update_zone</span><span class="p">(</span><span class="n">z</span><span class="p">,</span> <span class="n">Zone</span><span class="o">.</span><span class="n">CLEAR</span><span class="p">)</span> | |||
<span class="k">def</span> <span class="nf">_clear_expired_zones</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> | |||
<span class="sd">"""</span> | |||
<span class="sd"> Update zone status for all expired zones.</span> | |||
<span class="sd"> """</span> | |||
<span class="n">zones</span> <span class="o">=</span> <span class="p">[]</span> | |||
<span class="k">for</span> <span class="n">z</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_zones</span><span class="o">.</span><span class="n">keys</span><span class="p">():</span> | |||
<span class="n">zones</span> <span class="o">+=</span> <span class="p">[</span><span class="n">z</span><span class="p">]</span> | |||
<span class="k">for</span> <span class="n">z</span> <span class="ow">in</span> <span class="n">zones</span><span class="p">:</span> | |||
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_zones</span><span class="p">[</span><span class="n">z</span><span class="p">]</span><span class="o">.</span><span class="n">status</span> <span class="o">!=</span> <span class="n">Zone</span><span class="o">.</span><span class="n">CLEAR</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">_zone_expired</span><span class="p">(</span><span class="n">z</span><span class="p">):</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">_update_zone</span><span class="p">(</span><span class="n">z</span><span class="p">,</span> <span class="n">Zone</span><span class="o">.</span><span class="n">CLEAR</span><span class="p">)</span> | |||
<span class="k">def</span> <span class="nf">_add_zone</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">zone</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="s">''</span><span class="p">,</span> <span class="n">status</span><span class="o">=</span><span class="n">Zone</span><span class="o">.</span><span class="n">CLEAR</span><span class="p">):</span> | |||
<span class="sd">"""</span> | |||
<span class="sd"> Adds a zone to the internal zone list.</span> | |||
<span class="sd"> :param zone: The zone number.</span> | |||
<span class="sd"> :type zone: int</span> | |||
<span class="sd"> :param name: Human readable zone name.</span> | |||
<span class="sd"> :type name: str</span> | |||
<span class="sd"> :param status: The zone status.</span> | |||
<span class="sd"> :type status: int</span> | |||
<span class="sd"> """</span> | |||
<span class="k">if</span> <span class="ow">not</span> <span class="n">zone</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_zones</span><span class="p">:</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">_zones</span><span class="p">[</span><span class="n">zone</span><span class="p">]</span> <span class="o">=</span> <span class="n">Zone</span><span class="p">(</span><span class="n">zone</span><span class="o">=</span><span class="n">zone</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="n">name</span><span class="p">,</span> <span class="n">status</span><span class="o">=</span><span class="n">status</span><span class="p">)</span> | |||
<span class="k">if</span> <span class="n">status</span> <span class="o">!=</span> <span class="n">Zone</span><span class="o">.</span><span class="n">CLEAR</span><span class="p">:</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">on_fault</span><span class="p">(</span><span class="n">zone</span><span class="p">)</span> | |||
<span class="k">def</span> <span class="nf">_update_zone</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">zone</span><span class="p">,</span> <span class="n">status</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span> | |||
<span class="sd">"""</span> | |||
<span class="sd"> Updates a zones status.</span> | |||
<span class="sd"> :param zone: The zone number.</span> | |||
<span class="sd"> :type zone: int</span> | |||
<span class="sd"> :param status: The zone status.</span> | |||
<span class="sd"> :type status: int</span> | |||
<span class="sd"> :raises: IndexError</span> | |||
<span class="sd"> """</span> | |||
<span class="k">if</span> <span class="ow">not</span> <span class="n">zone</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_zones</span><span class="p">:</span> | |||
<span class="k">raise</span> <span class="ne">IndexError</span><span class="p">(</span><span class="s">'Zone does not exist and cannot be updated: </span><span class="si">%d</span><span class="s">'</span><span class="p">,</span> <span class="n">zone</span><span class="p">)</span> | |||
<span class="k">if</span> <span class="n">status</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">_zones</span><span class="p">[</span><span class="n">zone</span><span class="p">]</span><span class="o">.</span><span class="n">status</span> <span class="o">=</span> <span class="n">status</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">_zones</span><span class="p">[</span><span class="n">zone</span><span class="p">]</span><span class="o">.</span><span class="n">timestamp</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span> | |||
<span class="k">if</span> <span class="n">status</span> <span class="o">==</span> <span class="n">Zone</span><span class="o">.</span><span class="n">CLEAR</span><span class="p">:</span> | |||
<span class="k">if</span> <span class="n">zone</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_zones_faulted</span><span class="p">:</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">_zones_faulted</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="n">zone</span><span class="p">)</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">on_restore</span><span class="p">(</span><span class="n">zone</span><span class="p">)</span> | |||
<span class="k">def</span> <span class="nf">_zone_expired</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">zone</span><span class="p">):</span> | |||
<span class="sd">"""</span> | |||
<span class="sd"> Determine if a zone is expired or not.</span> | |||
<span class="sd"> :param zone: The zone number.</span> | |||
<span class="sd"> :type zone: int</span> | |||
<span class="sd"> :returns: Whether or not the zone is expired.</span> | |||
<span class="sd"> """</span> | |||
<span class="k">if</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span> <span class="o">></span> <span class="bp">self</span><span class="o">.</span><span class="n">_zones</span><span class="p">[</span><span class="n">zone</span><span class="p">]</span><span class="o">.</span><span class="n">timestamp</span> <span class="o">+</span> <span class="n">Zonetracker</span><span class="o">.</span><span class="n">EXPIRE</span><span class="p">:</span> | |||
<span class="k">return</span> <span class="bp">True</span> | |||
<span class="k">return</span> <span class="bp">False</span> | |||
<span class="k">def</span> <span class="nf">_expander_to_zone</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">address</span><span class="p">,</span> <span class="n">channel</span><span class="p">):</span> | |||
<span class="sd">"""</span> | |||
<span class="sd"> Convert an address and channel into a zone number.</span> | |||
<span class="sd"> :param address: The expander address</span> | |||
<span class="sd"> :type address: int</span> | |||
<span class="sd"> :param channel: The channel</span> | |||
<span class="sd"> :type channel: int</span> | |||
<span class="sd"> :returns: The zone number associated with an address and channel.</span> | |||
<span class="sd"> """</span> | |||
<span class="c"># TODO: This is going to need to be reworked to support the larger</span> | |||
<span class="c"># panels without fixed addressing on the expanders.</span> | |||
<span class="n">idx</span> <span class="o">=</span> <span class="n">address</span> <span class="o">-</span> <span class="mi">7</span> <span class="c"># Expanders start at address 7.</span> | |||
<span class="k">return</span> <span class="n">address</span> <span class="o">+</span> <span class="n">channel</span> <span class="o">+</span> <span class="p">(</span><span class="n">idx</span> <span class="o">*</span> <span class="mi">7</span><span class="p">)</span> <span class="o">+</span> <span class="mi">1</span></div> | |||
</pre></div> | |||
</div> | |||
</div> | |||
</div> | |||
<div class="sphinxsidebar"> | |||
<div class="sphinxsidebarwrapper"> | |||
<div id="searchbox" style="display: none"> | |||
<h3>Quick search</h3> | |||
<form class="search" action="../../search.html" method="get"> | |||
<input type="text" name="q" /> | |||
<input type="submit" value="Go" /> | |||
<input type="hidden" name="check_keywords" value="yes" /> | |||
<input type="hidden" name="area" value="default" /> | |||
</form> | |||
<p class="searchtip" style="font-size: 90%"> | |||
Enter search terms or a module, class or function name. | |||
</p> | |||
</div> | |||
<script type="text/javascript">$('#searchbox').show(0);</script> | |||
</div> | |||
</div> | |||
<div class="clearer"></div> | |||
</div> | |||
<div class="related"> | |||
<h3>Navigation</h3> | |||
<ul> | |||
<li class="right" style="margin-right: 10px"> | |||
<a href="../../genindex.html" title="General Index" | |||
>index</a></li> | |||
<li class="right" > | |||
<a href="../../py-modindex.html" title="Python Module Index" | |||
>modules</a> |</li> | |||
<li><a href="../../index.html">pyad2usb documentation</a> »</li> | |||
<li><a href="../index.html" >Module code</a> »</li> | |||
</ul> | |||
</div> | |||
<div class="footer"> | |||
© Copyright 2013, Author. | |||
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.2b1. | |||
</div> | |||
</body> | |||
</html> |
@@ -1,14 +1,6 @@ | |||
pyad2usb Package | |||
================ | |||
:mod:`pyad2usb` Package | |||
----------------------- | |||
.. automodule:: pyad2usb.__init__ | |||
:members: | |||
:undoc-members: | |||
:show-inheritance: | |||
:mod:`ad2usb` Module | |||
-------------------- | |||
@@ -33,6 +25,30 @@ pyad2usb Package | |||
:undoc-members: | |||
:show-inheritance: | |||
:mod:`zonetracking` Module | |||
-------------------------- | |||
.. automodule:: pyad2usb.zonetracking | |||
:members: | |||
:undoc-members: | |||
:show-inheritance: | |||
:mod:`panels` Module | |||
-------------------- | |||
.. automodule:: pyad2usb.panels | |||
:members: | |||
:undoc-members: | |||
:show-inheritance: | |||
:mod:`messages` Module | |||
---------------------- | |||
.. automodule:: pyad2usb.messages | |||
:members: | |||
:undoc-members: | |||
:show-inheritance: | |||
Subpackages | |||
----------- | |||
@@ -90,6 +90,12 @@ | |||
<table style="width: 100%" class="indextable genindextable"><tr> | |||
<td style="width: 33%" valign="top"><dl> | |||
<dt><a href="pyad2usb.html#pyad2usb.ad2usb.AD2USB.BATTERY_TIMEOUT">BATTERY_TIMEOUT (pyad2usb.ad2usb.AD2USB attribute)</a> | |||
</dt> | |||
</dl></td> | |||
<td style="width: 33%" valign="top"><dl> | |||
<dt><a href="pyad2usb.html#pyad2usb.devices.SerialDevice.BAUDRATE">BAUDRATE (pyad2usb.devices.SerialDevice attribute)</a> | |||
</dt> | |||
@@ -106,6 +112,20 @@ | |||
<table style="width: 100%" class="indextable genindextable"><tr> | |||
<td style="width: 33%" valign="top"><dl> | |||
<dt><a href="pyad2usb.html#pyad2usb.zonetracking.Zone.CHECK">CHECK (pyad2usb.zonetracking.Zone attribute)</a> | |||
</dt> | |||
<dt><a href="pyad2usb.html#pyad2usb.zonetracking.Zone.CLEAR">CLEAR (pyad2usb.zonetracking.Zone attribute)</a> | |||
</dt> | |||
<dt><a href="pyad2usb.html#pyad2usb.ad2usb.AD2USB.clear_zone">clear_zone() (pyad2usb.ad2usb.AD2USB method)</a> | |||
</dt> | |||
</dl></td> | |||
<td style="width: 33%" valign="top"><dl> | |||
<dt><a href="pyad2usb.html#pyad2usb.ad2usb.AD2USB.close">close() (pyad2usb.ad2usb.AD2USB method)</a> | |||
</dt> | |||
@@ -131,8 +151,6 @@ | |||
<dt><a href="pyad2usb.html#pyad2usb.util.CommError">CommError</a> | |||
</dt> | |||
</dl></td> | |||
<td style="width: 33%" valign="top"><dl> | |||
<dt><a href="pyad2usb.html#pyad2usb.ad2usb.Overseer.create">create() (pyad2usb.ad2usb.Overseer class method)</a> | |||
</dt> | |||
@@ -174,7 +192,11 @@ | |||
</dl></td> | |||
<td style="width: 33%" valign="top"><dl> | |||
<dt><a href="pyad2usb.html#pyad2usb.ad2usb.ExpanderMessage">ExpanderMessage (class in pyad2usb.ad2usb)</a> | |||
<dt><a href="pyad2usb.html#pyad2usb.messages.ExpanderMessage">ExpanderMessage (class in pyad2usb.messages)</a> | |||
</dt> | |||
<dt><a href="pyad2usb.html#pyad2usb.zonetracking.Zonetracker.EXPIRE">EXPIRE (pyad2usb.zonetracking.Zonetracker attribute)</a> | |||
</dt> | |||
</dl></td> | |||
@@ -200,6 +222,16 @@ | |||
</dt> | |||
<dt><a href="pyad2usb.html#pyad2usb.zonetracking.Zone.FAULT">FAULT (pyad2usb.zonetracking.Zone attribute)</a> | |||
</dt> | |||
<dt><a href="pyad2usb.html#pyad2usb.ad2usb.AD2USB.fault_zone">fault_zone() (pyad2usb.ad2usb.AD2USB method)</a> | |||
</dt> | |||
</dl></td> | |||
<td style="width: 33%" valign="top"><dl> | |||
<dt><a href="pyad2usb.html#pyad2usb.ad2usb.Overseer.find_all">find_all() (pyad2usb.ad2usb.Overseer class method)</a> | |||
</dt> | |||
@@ -213,13 +245,15 @@ | |||
</dt> | |||
</dl></dd> | |||
</dl></td> | |||
<td style="width: 33%" valign="top"><dl> | |||
<dt><a href="pyad2usb.event.html#pyad2usb.event.event.EventHandler.fire">fire() (pyad2usb.event.event.EventHandler method)</a> | |||
</dt> | |||
<dt><a href="pyad2usb.html#pyad2usb.ad2usb.AD2USB.FIRE_TIMEOUT">FIRE_TIMEOUT (pyad2usb.ad2usb.AD2USB attribute)</a> | |||
</dt> | |||
<dt><a href="pyad2usb.html#pyad2usb.util.Firmware">Firmware (class in pyad2usb.util)</a> | |||
</dt> | |||
@@ -280,7 +314,7 @@ | |||
<table style="width: 100%" class="indextable genindextable"><tr> | |||
<td style="width: 33%" valign="top"><dl> | |||
<dt><a href="pyad2usb.html#pyad2usb.ad2usb.LRRMessage">LRRMessage (class in pyad2usb.ad2usb)</a> | |||
<dt><a href="pyad2usb.html#pyad2usb.messages.LRRMessage">LRRMessage (class in pyad2usb.messages)</a> | |||
</dt> | |||
</dl></td> | |||
@@ -290,7 +324,7 @@ | |||
<table style="width: 100%" class="indextable genindextable"><tr> | |||
<td style="width: 33%" valign="top"><dl> | |||
<dt><a href="pyad2usb.html#pyad2usb.ad2usb.Message">Message (class in pyad2usb.ad2usb)</a> | |||
<dt><a href="pyad2usb.html#pyad2usb.messages.Message">Message (class in pyad2usb.messages)</a> | |||
</dt> | |||
</dl></td> | |||
@@ -314,6 +348,10 @@ | |||
</dt> | |||
<dt><a href="pyad2usb.html#pyad2usb.ad2usb.AD2USB.on_arm">on_arm (pyad2usb.ad2usb.AD2USB attribute)</a> | |||
</dt> | |||
<dt><a href="pyad2usb.html#pyad2usb.ad2usb.Overseer.on_attached">on_attached (pyad2usb.ad2usb.Overseer attribute)</a> | |||
</dt> | |||
@@ -344,12 +382,32 @@ | |||
</dt> | |||
<dt><a href="pyad2usb.html#pyad2usb.ad2usb.AD2USB.on_message">on_message (pyad2usb.ad2usb.AD2USB attribute)</a> | |||
<dt><a href="pyad2usb.html#pyad2usb.ad2usb.AD2USB.on_disarm">on_disarm (pyad2usb.ad2usb.AD2USB attribute)</a> | |||
</dt> | |||
<dt><a href="pyad2usb.html#pyad2usb.zonetracking.Zonetracker.on_fault">on_fault (pyad2usb.zonetracking.Zonetracker attribute)</a> | |||
</dt> | |||
<dt><a href="pyad2usb.html#pyad2usb.ad2usb.AD2USB.on_fire">on_fire (pyad2usb.ad2usb.AD2USB attribute)</a> | |||
</dt> | |||
<dt><a href="pyad2usb.html#pyad2usb.ad2usb.AD2USB.on_low_battery">on_low_battery (pyad2usb.ad2usb.AD2USB attribute)</a> | |||
</dt> | |||
<dt><a href="pyad2usb.html#pyad2usb.ad2usb.AD2USB.on_lrr_message">on_lrr_message (pyad2usb.ad2usb.AD2USB attribute)</a> | |||
</dt> | |||
</dl></td> | |||
<td style="width: 33%" valign="top"><dl> | |||
<dt><a href="pyad2usb.html#pyad2usb.ad2usb.AD2USB.on_message">on_message (pyad2usb.ad2usb.AD2USB attribute)</a> | |||
</dt> | |||
<dt><a href="pyad2usb.html#pyad2usb.ad2usb.AD2USB.on_open">on_open (pyad2usb.ad2usb.AD2USB attribute)</a> | |||
</dt> | |||
@@ -360,6 +418,10 @@ | |||
</dl></dd> | |||
<dt><a href="pyad2usb.html#pyad2usb.ad2usb.AD2USB.on_panic">on_panic (pyad2usb.ad2usb.AD2USB attribute)</a> | |||
</dt> | |||
<dt><a href="pyad2usb.html#pyad2usb.ad2usb.AD2USB.on_power_changed">on_power_changed (pyad2usb.ad2usb.AD2USB attribute)</a> | |||
</dt> | |||
@@ -374,7 +436,7 @@ | |||
</dl></dd> | |||
<dt><a href="pyad2usb.html#pyad2usb.ad2usb.AD2USB.on_status_changed">on_status_changed (pyad2usb.ad2usb.AD2USB attribute)</a> | |||
<dt><a href="pyad2usb.html#pyad2usb.zonetracking.Zonetracker.on_restore">on_restore (pyad2usb.zonetracking.Zonetracker attribute)</a> | |||
</dt> | |||
@@ -388,6 +450,14 @@ | |||
</dl></dd> | |||
<dt><a href="pyad2usb.html#pyad2usb.ad2usb.AD2USB.on_zone_fault">on_zone_fault (pyad2usb.ad2usb.AD2USB attribute)</a> | |||
</dt> | |||
<dt><a href="pyad2usb.html#pyad2usb.ad2usb.AD2USB.on_zone_restore">on_zone_restore (pyad2usb.ad2usb.AD2USB attribute)</a> | |||
</dt> | |||
<dt><a href="pyad2usb.html#pyad2usb.ad2usb.AD2USB.open">open() (pyad2usb.ad2usb.AD2USB method)</a> | |||
</dt> | |||
@@ -420,31 +490,39 @@ | |||
<table style="width: 100%" class="indextable genindextable"><tr> | |||
<td style="width: 33%" valign="top"><dl> | |||
<dt><a href="pyad2usb.html#module-pyad2usb.__init__">pyad2usb.__init__ (module)</a> | |||
<dt><a href="pyad2usb.html#module-pyad2usb.ad2usb">pyad2usb.ad2usb (module)</a> | |||
</dt> | |||
<dt><a href="pyad2usb.html#module-pyad2usb.ad2usb">pyad2usb.ad2usb (module)</a> | |||
<dt><a href="pyad2usb.html#module-pyad2usb.devices">pyad2usb.devices (module)</a> | |||
</dt> | |||
<dt><a href="pyad2usb.html#module-pyad2usb.devices">pyad2usb.devices (module)</a> | |||
<dt><a href="pyad2usb.event.html#module-pyad2usb.event">pyad2usb.event (module)</a> | |||
</dt> | |||
<dt><a href="pyad2usb.event.html#module-pyad2usb.event.event">pyad2usb.event.event (module)</a> | |||
</dt> | |||
</dl></td> | |||
<td style="width: 33%" valign="top"><dl> | |||
<dt><a href="pyad2usb.event.html#module-pyad2usb.event">pyad2usb.event (module)</a> | |||
<dt><a href="pyad2usb.html#module-pyad2usb.messages">pyad2usb.messages (module)</a> | |||
</dt> | |||
<dt><a href="pyad2usb.event.html#module-pyad2usb.event.event">pyad2usb.event.event (module)</a> | |||
<dt><a href="pyad2usb.html#module-pyad2usb.panels">pyad2usb.panels (module)</a> | |||
</dt> | |||
<dt><a href="pyad2usb.html#module-pyad2usb.util">pyad2usb.util (module)</a> | |||
</dt> | |||
<dt><a href="pyad2usb.html#module-pyad2usb.zonetracking">pyad2usb.zonetracking (module)</a> | |||
</dt> | |||
</dl></td> | |||
</tr></table> | |||
@@ -490,7 +568,7 @@ | |||
</dl></td> | |||
<td style="width: 33%" valign="top"><dl> | |||
<dt><a href="pyad2usb.html#pyad2usb.ad2usb.ExpanderMessage.RELAY">RELAY (pyad2usb.ad2usb.ExpanderMessage attribute)</a> | |||
<dt><a href="pyad2usb.html#pyad2usb.messages.ExpanderMessage.RELAY">RELAY (pyad2usb.messages.ExpanderMessage attribute)</a> | |||
</dt> | |||
@@ -498,7 +576,7 @@ | |||
</dt> | |||
<dt><a href="pyad2usb.html#pyad2usb.ad2usb.RFMessage">RFMessage (class in pyad2usb.ad2usb)</a> | |||
<dt><a href="pyad2usb.html#pyad2usb.messages.RFMessage">RFMessage (class in pyad2usb.messages)</a> | |||
</dt> | |||
@@ -518,11 +596,11 @@ | |||
<table style="width: 100%" class="indextable genindextable"><tr> | |||
<td style="width: 33%" valign="top"><dl> | |||
<dt><a href="pyad2usb.html#pyad2usb.devices.SerialDevice">SerialDevice (class in pyad2usb.devices)</a> | |||
<dt><a href="pyad2usb.html#pyad2usb.ad2usb.AD2USB.save_config">save_config() (pyad2usb.ad2usb.AD2USB method)</a> | |||
</dt> | |||
<dt><a href="pyad2usb.html#pyad2usb.ad2usb.AD2USB.set_config">set_config() (pyad2usb.ad2usb.AD2USB method)</a> | |||
<dt><a href="pyad2usb.html#pyad2usb.devices.SerialDevice">SerialDevice (class in pyad2usb.devices)</a> | |||
</dt> | |||
@@ -541,12 +619,12 @@ | |||
<dt><a href="pyad2usb.html#pyad2usb.util.Firmware.STAGE_LOAD">STAGE_LOAD (pyad2usb.util.Firmware attribute)</a> | |||
</dt> | |||
</dl></td> | |||
<td style="width: 33%" valign="top"><dl> | |||
<dt><a href="pyad2usb.html#pyad2usb.util.Firmware.STAGE_START">STAGE_START (pyad2usb.util.Firmware attribute)</a> | |||
</dt> | |||
</dl></td> | |||
<td style="width: 33%" valign="top"><dl> | |||
<dt><a href="pyad2usb.html#pyad2usb.util.Firmware.STAGE_UPLOADING">STAGE_UPLOADING (pyad2usb.util.Firmware attribute)</a> | |||
</dt> | |||
@@ -560,6 +638,10 @@ | |||
</dt> | |||
<dt><a href="pyad2usb.html#pyad2usb.zonetracking.Zone.STATUS">STATUS (pyad2usb.zonetracking.Zone attribute)</a> | |||
</dt> | |||
<dt><a href="pyad2usb.html#pyad2usb.ad2usb.Overseer.stop">stop() (pyad2usb.ad2usb.Overseer method)</a> | |||
</dt> | |||
@@ -594,6 +676,10 @@ | |||
<table style="width: 100%" class="indextable genindextable"><tr> | |||
<td style="width: 33%" valign="top"><dl> | |||
<dt><a href="pyad2usb.html#pyad2usb.zonetracking.Zonetracker.update">update() (pyad2usb.zonetracking.Zonetracker method)</a> | |||
</dt> | |||
<dt><a href="pyad2usb.html#pyad2usb.util.Firmware.upload">upload() (pyad2usb.util.Firmware static method)</a> | |||
</dt> | |||
@@ -630,7 +716,17 @@ | |||
<table style="width: 100%" class="indextable genindextable"><tr> | |||
<td style="width: 33%" valign="top"><dl> | |||
<dt><a href="pyad2usb.html#pyad2usb.ad2usb.ExpanderMessage.ZONE">ZONE (pyad2usb.ad2usb.ExpanderMessage attribute)</a> | |||
<dt><a href="pyad2usb.html#pyad2usb.zonetracking.Zone">Zone (class in pyad2usb.zonetracking)</a> | |||
</dt> | |||
<dt><a href="pyad2usb.html#pyad2usb.messages.ExpanderMessage.ZONE">ZONE (pyad2usb.messages.ExpanderMessage attribute)</a> | |||
</dt> | |||
</dl></td> | |||
<td style="width: 33%" valign="top"><dl> | |||
<dt><a href="pyad2usb.html#pyad2usb.zonetracking.Zonetracker">Zonetracker (class in pyad2usb.zonetracking)</a> | |||
</dt> | |||
</dl></td> | |||
@@ -54,10 +54,12 @@ | |||
<div class="toctree-wrapper compound"> | |||
<ul> | |||
<li class="toctree-l1"><a class="reference internal" href="pyad2usb.html">pyad2usb Package</a><ul> | |||
<li class="toctree-l2"><a class="reference internal" href="pyad2usb.html#id1"><tt class="docutils literal"><span class="pre">pyad2usb</span></tt> Package</a></li> | |||
<li class="toctree-l2"><a class="reference internal" href="pyad2usb.html#module-pyad2usb.ad2usb"><tt class="docutils literal"><span class="pre">ad2usb</span></tt> Module</a></li> | |||
<li class="toctree-l2"><a class="reference internal" href="pyad2usb.html#module-pyad2usb.devices"><tt class="docutils literal"><span class="pre">devices</span></tt> Module</a></li> | |||
<li class="toctree-l2"><a class="reference internal" href="pyad2usb.html#module-pyad2usb.util"><tt class="docutils literal"><span class="pre">util</span></tt> Module</a></li> | |||
<li class="toctree-l2"><a class="reference internal" href="pyad2usb.html#module-pyad2usb.zonetracking"><tt class="docutils literal"><span class="pre">zonetracking</span></tt> Module</a></li> | |||
<li class="toctree-l2"><a class="reference internal" href="pyad2usb.html#module-pyad2usb.panels"><tt class="docutils literal"><span class="pre">panels</span></tt> Module</a></li> | |||
<li class="toctree-l2"><a class="reference internal" href="pyad2usb.html#module-pyad2usb.messages"><tt class="docutils literal"><span class="pre">messages</span></tt> Module</a></li> | |||
<li class="toctree-l2"><a class="reference internal" href="pyad2usb.html#subpackages">Subpackages</a><ul> | |||
<li class="toctree-l3"><a class="reference internal" href="pyad2usb.event.html">event Package</a><ul> | |||
<li class="toctree-l4"><a class="reference internal" href="pyad2usb.event.html#id1"><tt class="docutils literal"><span class="pre">event</span></tt> Package</a></li> | |||
@@ -49,10 +49,12 @@ | |||
<div class="toctree-wrapper compound"> | |||
<ul> | |||
<li class="toctree-l1"><a class="reference internal" href="pyad2usb.html">pyad2usb Package</a><ul> | |||
<li class="toctree-l2"><a class="reference internal" href="pyad2usb.html#id1"><tt class="docutils literal"><span class="pre">pyad2usb</span></tt> Package</a></li> | |||
<li class="toctree-l2"><a class="reference internal" href="pyad2usb.html#module-pyad2usb.ad2usb"><tt class="docutils literal"><span class="pre">ad2usb</span></tt> Module</a></li> | |||
<li class="toctree-l2"><a class="reference internal" href="pyad2usb.html#module-pyad2usb.devices"><tt class="docutils literal"><span class="pre">devices</span></tt> Module</a></li> | |||
<li class="toctree-l2"><a class="reference internal" href="pyad2usb.html#module-pyad2usb.util"><tt class="docutils literal"><span class="pre">util</span></tt> Module</a></li> | |||
<li class="toctree-l2"><a class="reference internal" href="pyad2usb.html#module-pyad2usb.zonetracking"><tt class="docutils literal"><span class="pre">zonetracking</span></tt> Module</a></li> | |||
<li class="toctree-l2"><a class="reference internal" href="pyad2usb.html#module-pyad2usb.panels"><tt class="docutils literal"><span class="pre">panels</span></tt> Module</a></li> | |||
<li class="toctree-l2"><a class="reference internal" href="pyad2usb.html#module-pyad2usb.messages"><tt class="docutils literal"><span class="pre">messages</span></tt> Module</a></li> | |||
<li class="toctree-l2"><a class="reference internal" href="pyad2usb.html#subpackages">Subpackages</a><ul> | |||
<li class="toctree-l3"><a class="reference internal" href="pyad2usb.event.html">event Package</a><ul> | |||
<li class="toctree-l4"><a class="reference internal" href="pyad2usb.event.html#id1"><tt class="docutils literal"><span class="pre">event</span></tt> Package</a></li> | |||
@@ -64,11 +64,6 @@ | |||
<td> | |||
<tt class="xref">pyad2usb</tt></td><td> | |||
<em></em></td></tr> | |||
<tr class="cg-1"> | |||
<td></td> | |||
<td> | |||
<a href="pyad2usb.html#module-pyad2usb.__init__"><tt class="xref">pyad2usb.__init__</tt></a></td><td> | |||
<em></em></td></tr> | |||
<tr class="cg-1"> | |||
<td></td> | |||
<td> | |||
@@ -89,11 +84,26 @@ | |||
<td> | |||
<a href="pyad2usb.event.html#module-pyad2usb.event.event"><tt class="xref">pyad2usb.event.event</tt></a></td><td> | |||
<em></em></td></tr> | |||
<tr class="cg-1"> | |||
<td></td> | |||
<td> | |||
<a href="pyad2usb.html#module-pyad2usb.messages"><tt class="xref">pyad2usb.messages</tt></a></td><td> | |||
<em></em></td></tr> | |||
<tr class="cg-1"> | |||
<td></td> | |||
<td> | |||
<a href="pyad2usb.html#module-pyad2usb.panels"><tt class="xref">pyad2usb.panels</tt></a></td><td> | |||
<em></em></td></tr> | |||
<tr class="cg-1"> | |||
<td></td> | |||
<td> | |||
<a href="pyad2usb.html#module-pyad2usb.util"><tt class="xref">pyad2usb.util</tt></a></td><td> | |||
<em></em></td></tr> | |||
<tr class="cg-1"> | |||
<td></td> | |||
<td> | |||
<a href="pyad2usb.html#module-pyad2usb.zonetracking"><tt class="xref">pyad2usb.zonetracking</tt></a></td><td> | |||
<em></em></td></tr> | |||
</table> | |||
@@ -75,6 +75,13 @@ | |||
You can add handler also by using ‘+=’ operator.</p> | |||
</dd></dl> | |||
<dl class="method"> | |||
<dt id="pyad2usb.event.event.EventHandler.remove"> | |||
<tt class="descname">remove</tt><big>(</big><em>func</em><big>)</big><a class="reference internal" href="_modules/pyad2usb/event/event.html#EventHandler.remove"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyad2usb.event.event.EventHandler.remove" title="Permalink to this definition">¶</a></dt> | |||
<dd><p>Remove existing event handler function.</p> | |||
<p>You can remove handler also by using ‘-=’ operator.</p> | |||
</dd></dl> | |||
<dl class="method"> | |||
<dt id="pyad2usb.event.event.EventHandler.fire"> | |||
<tt class="descname">fire</tt><big>(</big><em>earg=None</em><big>)</big><a class="reference internal" href="_modules/pyad2usb/event/event.html#EventHandler.fire"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyad2usb.event.event.EventHandler.fire" title="Permalink to this definition">¶</a></dt> | |||
@@ -83,13 +90,6 @@ You can add handler also by using ‘+=’ operator.</p> | |||
e.fire(earg).</p> | |||
</dd></dl> | |||
<dl class="method"> | |||
<dt id="pyad2usb.event.event.EventHandler.remove"> | |||
<tt class="descname">remove</tt><big>(</big><em>func</em><big>)</big><a class="reference internal" href="_modules/pyad2usb/event/event.html#EventHandler.remove"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pyad2usb.event.event.EventHandler.remove" title="Permalink to this definition">¶</a></dt> | |||
<dd><p>Remove existing event handler function.</p> | |||
<p>You can remove handler also by using ‘-=’ operator.</p> | |||
</dd></dl> | |||
</dd></dl> | |||
</div> | |||
@@ -304,3 +304,5 @@ epub_copyright = u'2013, Author' | |||
# If false, no index is generated. | |||
#epub_use_index = True | |||
autodoc_member_order = 'bysource' |
@@ -1,14 +1,6 @@ | |||
pyad2usb Package | |||
================ | |||
:mod:`pyad2usb` Package | |||
----------------------- | |||
.. automodule:: pyad2usb.__init__ | |||
:members: | |||
:undoc-members: | |||
:show-inheritance: | |||
:mod:`ad2usb` Module | |||
-------------------- | |||
@@ -33,6 +25,30 @@ pyad2usb Package | |||
:undoc-members: | |||
:show-inheritance: | |||
:mod:`zonetracking` Module | |||
-------------------------- | |||
.. automodule:: pyad2usb.zonetracking | |||
:members: | |||
:undoc-members: | |||
:show-inheritance: | |||
:mod:`panels` Module | |||
-------------------- | |||
.. automodule:: pyad2usb.panels | |||
:members: | |||
:undoc-members: | |||
:show-inheritance: | |||
:mod:`messages` Module | |||
---------------------- | |||
.. automodule:: pyad2usb.messages | |||
:members: | |||
:undoc-members: | |||
:show-inheritance: | |||
Subpackages | |||
----------- | |||
@@ -1,5 +1 @@ | |||
""" | |||
The PyAD2USB module. | |||
""" | |||
__all__ = ['ad2usb', 'devices', 'util'] |
@@ -1,5 +1,9 @@ | |||
""" | |||
Provides the full AD2USB class and factory. | |||
.. moduleauthor:: Scott Petersen <scott@nutech.com> | |||
""" | |||
import time | |||
@@ -28,6 +32,9 @@ class Overseer(object): | |||
def find_all(cls): | |||
""" | |||
Returns all AD2USB devices located on the system. | |||
:returns: list of devices found | |||
:raises: util.CommError | |||
""" | |||
cls.__devices = devices.USBDevice.find_all() | |||
@@ -37,6 +44,8 @@ class Overseer(object): | |||
def devices(cls): | |||
""" | |||
Returns a cached list of AD2USB devices located on the system. | |||
:returns: cached list of devices found. | |||
""" | |||
return cls.__devices | |||
@@ -44,6 +53,12 @@ class Overseer(object): | |||
def create(cls, device=None): | |||
""" | |||
Factory method that returns the requested AD2USB device, or the first device. | |||
:param device: Tuple describing the USB device to open, as returned by find_all(). | |||
:type device: tuple | |||
:returns: AD2USB object utilizing the specified device. | |||
:raises: util.NoDeviceError | |||
""" | |||
cls.find_all() | |||
@@ -61,6 +76,11 @@ class Overseer(object): | |||
def __init__(self, attached_event=None, detached_event=None): | |||
""" | |||
Constructor | |||
:param attached_event: Event to trigger when a device is attached. | |||
:type attached_event: function | |||
:param detached_event: Event to trigger when a device is detached. | |||
:type detached_event: function | |||
""" | |||
self._detect_thread = Overseer.DetectThread(self) | |||
@@ -96,6 +116,9 @@ class Overseer(object): | |||
def get_device(self, device=None): | |||
""" | |||
Factory method that returns the requested AD2USB device, or the first device. | |||
:param device: Tuple describing the USB device to open, as returned by find_all(). | |||
:type device: tuple | |||
""" | |||
return Overseer.create(device) | |||
@@ -106,6 +129,9 @@ class Overseer(object): | |||
def __init__(self, overseer): | |||
""" | |||
Constructor | |||
:param overseer: Overseer object to use with the thread. | |||
:type overseer: Overseer | |||
""" | |||
threading.Thread.__init__(self) | |||
@@ -178,16 +204,25 @@ class AD2USB(object): | |||
# Constants | |||
F1 = unichr(1) + unichr(1) + unichr(1) | |||
"""Represents panel function key #1""" | |||
F2 = unichr(2) + unichr(2) + unichr(2) | |||
"""Represents panel function key #2""" | |||
F3 = unichr(3) + unichr(3) + unichr(3) | |||
"""Represents panel function key #3""" | |||
F4 = unichr(4) + unichr(4) + unichr(4) | |||
"""Represents panel function key #4""" | |||
BATTERY_TIMEOUT = 30 | |||
"""Timeout before the battery status reverts.""" | |||
FIRE_TIMEOUT = 30 | |||
"""Timeout before the fire status reverts.""" | |||
def __init__(self, device): | |||
""" | |||
Constructor | |||
:param device: The low-level device used for this AD2USB interface. | |||
:type device: devices.Device | |||
""" | |||
self._device = device | |||
self._zonetracker = zonetracking.Zonetracker() | |||
@@ -212,12 +247,23 @@ class AD2USB(object): | |||
def id(self): | |||
""" | |||
The ID of the AD2USB device. | |||
:returns: The identification string for the device. | |||
""" | |||
return self._device.id | |||
def open(self, baudrate=None, interface=None, index=None, no_reader_thread=False): | |||
""" | |||
Opens the device. | |||
:param baudrate: The baudrate used for the device. | |||
:type baudrate: int | |||
:param interface: The interface used for the device. | |||
:type interface: varies depends on device type.. FIXME | |||
:param index: Interface index.. can probably remove. FIXME | |||
:type index: int | |||
:param no_reader_thread: Specifies whether or not the automatic reader thread should be started or not | |||
:type no_reader_thread: bool | |||
""" | |||
self._wire_events() | |||
self._device.open(baudrate=baudrate, interface=interface, index=index, no_reader_thread=no_reader_thread) | |||
@@ -274,6 +320,11 @@ class AD2USB(object): | |||
def fault_zone(self, zone, simulate_wire_problem=False): | |||
""" | |||
Faults a zone if we are emulating a zone expander. | |||
:param zone: The zone to fault. | |||
:type zone: int | |||
:param simulate_wire_problem: Whether or not to simulate a wire fault. | |||
:type simulate_wire_problem: bool | |||
""" | |||
# Allow ourselves to also be passed an address/channel combination | |||
# for zone expanders. | |||
@@ -289,6 +340,9 @@ class AD2USB(object): | |||
def clear_zone(self, zone): | |||
""" | |||
Clears a zone if we are emulating a zone expander. | |||
:param zone: The zone to clear. | |||
:type zone: int | |||
""" | |||
self._device.write("L{0:02}0\r".format(zone)) | |||
@@ -306,6 +360,11 @@ class AD2USB(object): | |||
def _handle_message(self, data): | |||
""" | |||
Parses messages from the panel. | |||
:param data: Panel data to parse. | |||
:type data: str | |||
:returns: An object representing the message. | |||
""" | |||
if data is None: | |||
return None | |||
@@ -338,6 +397,11 @@ class AD2USB(object): | |||
def _handle_lrr(self, data): | |||
""" | |||
Handle Long Range Radio messages. | |||
:param data: LRR message to parse. | |||
:type data: str | |||
:returns: An object representing the LRR message. | |||
""" | |||
msg = messages.LRRMessage(data) | |||
@@ -358,6 +422,9 @@ class AD2USB(object): | |||
def _handle_config(self, data): | |||
""" | |||
Handles received configuration data. | |||
:param data: Configuration string to parse. | |||
:type data: str | |||
""" | |||
_, config_string = data.split('>') | |||
for setting in config_string.split('&'): | |||
@@ -385,6 +452,9 @@ class AD2USB(object): | |||
def _update_internal_states(self, message): | |||
""" | |||
Updates internal device states. | |||
:param message: Message to update internal states with. | |||
:type message: Message, ExpanderMessage, LRRMessage, or RFMessage | |||
""" | |||
if isinstance(message, messages.Message): | |||
if message.ac_power != self._power_status: | |||
@@ -447,6 +517,9 @@ class AD2USB(object): | |||
def _update_zone_tracker(self, message): | |||
""" | |||
Trigger an update of the zonetracker. | |||
:param message: The message to update the zonetracker with. | |||
:type message: Message, ExpanderMessage, LRRMessage, or RFMessage | |||
""" | |||
# Retrieve a list of faults. | |||
@@ -1,5 +1,7 @@ | |||
""" | |||
Contains different types of devices belonging to the AD2USB family. | |||
.. moduleauthor:: Scott Petersen <scott@nutech.com> | |||
""" | |||
import usb.core | |||
@@ -40,6 +42,8 @@ class Device(object): | |||
def id(self): | |||
""" | |||
Retrieve the device ID. | |||
:returns: The identification string for the device. | |||
""" | |||
return self._id | |||
@@ -47,12 +51,17 @@ class Device(object): | |||
def id(self, value): | |||
""" | |||
Sets the device ID. | |||
:param value: The device identification. | |||
:type value: str | |||
""" | |||
self._id = value | |||
def is_reader_alive(self): | |||
""" | |||
Indicates whether or not the reader thread is alive. | |||
:returns: Whether or not the reader thread is alive. | |||
""" | |||
return self._read_thread.is_alive() | |||
@@ -68,10 +77,14 @@ class Device(object): | |||
""" | |||
READ_TIMEOUT = 10 | |||
"""Timeout for the reader thread.""" | |||
def __init__(self, device): | |||
""" | |||
Constructor | |||
:param device: The device used by the reader thread. | |||
:type device: devices.Device | |||
""" | |||
threading.Thread.__init__(self) | |||
self._device = device | |||
@@ -105,13 +118,19 @@ class USBDevice(Device): | |||
# Constants | |||
FTDI_VENDOR_ID = 0x0403 | |||
"""Vendor ID used to recognize AD2USB devices.""" | |||
FTDI_PRODUCT_ID = 0x6001 | |||
"""Product ID used to recognize AD2USB devices.""" | |||
BAUDRATE = 115200 | |||
"""Default baudrate for AD2USB devices.""" | |||
@staticmethod | |||
def find_all(): | |||
""" | |||
Returns all FTDI devices matching our vendor and product IDs. | |||
:returns: list of devices | |||
:raises: util.CommError | |||
""" | |||
devices = [] | |||
@@ -126,6 +145,17 @@ class USBDevice(Device): | |||
def __init__(self, vid=FTDI_VENDOR_ID, pid=FTDI_PRODUCT_ID, serial=None, description=None, interface=0): | |||
""" | |||
Constructor | |||
:param vid: Vendor ID | |||
:type vid: int | |||
:param pid: Product ID | |||
:type pid: int | |||
:param serial: The serial number | |||
:type serial: str | |||
:param description: Description of the device. | |||
:type description: str | |||
:param interface: The interface to use | |||
:type interface: int | |||
""" | |||
Device.__init__(self) | |||
@@ -139,6 +169,15 @@ class USBDevice(Device): | |||
def open(self, baudrate=BAUDRATE, interface=None, index=0, no_reader_thread=False): | |||
""" | |||
Opens the device. | |||
:param baudrate: The baudrate to use. | |||
:type baudrate: int | |||
:param interface: The interface to use. | |||
:type interface: int | |||
:param no_reader_thread: Whether or not to automatically start the reader thread. | |||
:type no_reader_thread: bool | |||
:raises: util.NoDeviceError | |||
""" | |||
# Set up defaults | |||
if baudrate is None: | |||
@@ -197,6 +236,11 @@ class USBDevice(Device): | |||
def write(self, data): | |||
""" | |||
Writes data to the device. | |||
:param data: Data to write | |||
:type data: str | |||
:raises: util.CommError | |||
""" | |||
try: | |||
self._device.write_data(data) | |||
@@ -208,6 +252,9 @@ class USBDevice(Device): | |||
def read(self): | |||
""" | |||
Reads a single character from the device. | |||
:returns: The character read from the device. | |||
:raises: util.CommError | |||
""" | |||
ret = None | |||
@@ -222,6 +269,14 @@ class USBDevice(Device): | |||
def read_line(self, timeout=0.0, purge_buffer=False): | |||
""" | |||
Reads a line from the device. | |||
:param timeout: Read timeout | |||
:type timeout: float | |||
:param purge_buffer: Indicates whether to purge the buffer prior to reading. | |||
:type purge_buffer: bool | |||
:returns: The line that was read. | |||
:raises: util.CommError, util.TimeoutError | |||
""" | |||
if purge_buffer: | |||
@@ -287,11 +342,18 @@ class SerialDevice(Device): | |||
# Constants | |||
BAUDRATE = 19200 | |||
"""Default baudrate for Serial devices.""" | |||
@staticmethod | |||
def find_all(pattern=None): | |||
""" | |||
Returns all serial ports present. | |||
:param pattern: Pattern to search for when retrieving serial ports. | |||
:type pattern: str | |||
:returns: list of devices | |||
:raises: util.CommError | |||
""" | |||
devices = [] | |||
@@ -309,6 +371,9 @@ class SerialDevice(Device): | |||
def __init__(self, interface=None): | |||
""" | |||
Constructor | |||
:param interface: The device to open. | |||
:type interface: str | |||
""" | |||
Device.__init__(self) | |||
@@ -319,6 +384,17 @@ class SerialDevice(Device): | |||
def open(self, baudrate=BAUDRATE, interface=None, index=None, no_reader_thread=False): | |||
""" | |||
Opens the device. | |||
:param baudrate: The baudrate to use with the device. | |||
:type baudrate: int | |||
:param interface: The device to open. | |||
:type interface: str | |||
:param index: Unused. | |||
:type index: int | |||
:param no_reader_thread: Whether or not to automatically start the reader thread. | |||
:type no_reader_thread: bool | |||
:raises: util.NoDeviceError | |||
""" | |||
# Set up the defaults | |||
if baudrate is None: | |||
@@ -370,6 +446,11 @@ class SerialDevice(Device): | |||
def write(self, data): | |||
""" | |||
Writes data to the device. | |||
:param data: The data to write. | |||
:type data: str | |||
:raises: util.CommError | |||
""" | |||
try: | |||
self._device.write(data) | |||
@@ -386,6 +467,9 @@ class SerialDevice(Device): | |||
def read(self): | |||
""" | |||
Reads a single character from the device. | |||
:returns: The character read from the device. | |||
:raises: util.CommError | |||
""" | |||
ret = None | |||
@@ -400,6 +484,14 @@ class SerialDevice(Device): | |||
def read_line(self, timeout=0.0, purge_buffer=False): | |||
""" | |||
Reads a line from the device. | |||
:param timeout: The read timeout. | |||
:type timeout: float | |||
:param purge_buffer: Indicates whether to purge the buffer prior to reading. | |||
:type purge_buffer: bool | |||
:returns: The line read. | |||
:raises: util.CommError, util.TimeoutError | |||
""" | |||
def timeout_event(): | |||
timeout_event.reading = False | |||
@@ -471,6 +563,17 @@ class SocketDevice(Device): | |||
def open(self, baudrate=None, interface=None, index=0, no_reader_thread=False): | |||
""" | |||
Opens the device. | |||
:param baudrate: The baudrate to use | |||
:type baudrate: int | |||
:param interface: The hostname and port to connect to. | |||
:type interface: tuple | |||
:param index: Unused | |||
:type index: int | |||
:param no_reader_thread: Whether or not to automatically open the reader thread. | |||
:type no_reader_thread: bool | |||
:raises: util.NoDeviceError | |||
""" | |||
if interface is not None: | |||
self._interface = interface | |||
@@ -512,6 +615,12 @@ class SocketDevice(Device): | |||
def write(self, data): | |||
""" | |||
Writes data to the device. | |||
:param data: The data to write. | |||
:type data: str | |||
:returns: The number of bytes sent. | |||
:raises: util.CommError | |||
""" | |||
data_sent = None | |||
@@ -531,6 +640,9 @@ class SocketDevice(Device): | |||
def read(self): | |||
""" | |||
Reads a single character from the device. | |||
:returns: The character read from the device. | |||
:raises: util.CommError | |||
""" | |||
data = None | |||
@@ -545,6 +657,14 @@ class SocketDevice(Device): | |||
def read_line(self, timeout=0.0, purge_buffer=False): | |||
""" | |||
Reads a line from the device. | |||
:param timeout: The read timeout. | |||
:type timeout: float | |||
:param purge_buffer: Indicates whether to purge the buffer prior to reading. | |||
:type purge_buffer: bool | |||
:returns: The line read from the device. | |||
:raises: util.CommError, util.TimeoutError | |||
""" | |||
if purge_buffer: | |||
@@ -12,6 +12,9 @@ class Message(object): | |||
def __init__(self, data=None): | |||
""" | |||
Constructor | |||
:param data: Message data to parse. | |||
:type data: str | |||
""" | |||
self.ready = False | |||
self.armed_away = False | |||
@@ -45,6 +48,11 @@ class Message(object): | |||
def _parse_message(self, data): | |||
""" | |||
Parse the message from the device. | |||
:param data: The message data. | |||
:type data: str | |||
:raises: util.InvalidMessageError | |||
""" | |||
m = self._regex.match(data) | |||
@@ -94,6 +102,9 @@ class ExpanderMessage(object): | |||
def __init__(self, data=None): | |||
""" | |||
Constructor | |||
:param data: The message data to parse. | |||
:type data: str | |||
""" | |||
self.type = None | |||
self.address = None | |||
@@ -119,6 +130,9 @@ class ExpanderMessage(object): | |||
def _parse_message(self, data): | |||
""" | |||
Parse the raw message from the device. | |||
:param data: The message data | |||
:type data: str | |||
""" | |||
header, values = data.split(':') | |||
address, channel, value = values.split(',') | |||
@@ -141,6 +155,9 @@ class RFMessage(object): | |||
def __init__(self, data=None): | |||
""" | |||
Constructor | |||
:param data: The message data to parse | |||
:type data: str | |||
""" | |||
self.raw = None | |||
self.serial_number = None | |||
@@ -158,6 +175,9 @@ class RFMessage(object): | |||
def _parse_message(self, data): | |||
""" | |||
Parses the raw message from the device. | |||
:param data: The message data. | |||
:type data: str | |||
""" | |||
self.raw = data | |||
@@ -172,6 +192,9 @@ class LRRMessage(object): | |||
def __init__(self, data=None): | |||
""" | |||
Constructor | |||
:param data: The message data to parse. | |||
:type data: str | |||
""" | |||
self.raw = None | |||
self._event_data = None | |||
@@ -190,6 +213,9 @@ class LRRMessage(object): | |||
def _parse_message(self, data): | |||
""" | |||
Parses the raw message from the device. | |||
:param data: The message data. | |||
:type data: str | |||
""" | |||
self.raw = data | |||
@@ -48,6 +48,13 @@ class Firmware(object): | |||
def upload(dev, filename, progress_callback=None): | |||
""" | |||
Uploads firmware to an AD2USB/AD2SERIAL device. | |||
:param filename: The firmware filename | |||
:type filename: str | |||
:param progress_callback: Callback function used to report progress. | |||
:type progress_callback: function | |||
:raises: util.NoDeviceError, util.TimeoutError | |||
""" | |||
def do_upload(): | |||
@@ -12,21 +12,40 @@ class Zone(object): | |||
""" | |||
CLEAR = 0 | |||
"""Status indicating that the zone is cleared.""" | |||
FAULT = 1 | |||
"""Status indicating that the zone is faulted.""" | |||
CHECK = 2 # Wire fault | |||
"""Status indicating that there is a wiring issue with the zone.""" | |||
STATUS = { CLEAR: 'CLEAR', FAULT: 'FAULT', CHECK: 'CHECK' } | |||
def __init__(self, zone=0, name='', status=CLEAR): | |||
""" | |||
Constructor | |||
:param zone: The zone number. | |||
:type zone: int | |||
:param name: Human readable zone name. | |||
:type name: str | |||
:param status: Initial zone state. | |||
:type status: int | |||
""" | |||
self.zone = zone | |||
self.name = name | |||
self.status = status | |||
self.timestamp = time.time() | |||
def __str__(self): | |||
""" | |||
String conversion operator. | |||
""" | |||
return 'Zone {0} {1}'.format(self.zone, self.name) | |||
def __repr__(self): | |||
""" | |||
Human readable representation operator. | |||
""" | |||
return 'Zone({0}, {1}, ts {2})'.format(self.zone, Zone.STATUS[self.status], self.timestamp) | |||
class Zonetracker(object): | |||
@@ -38,6 +57,7 @@ class Zonetracker(object): | |||
on_restore = event.Event('Called when the device detects that a fault is restored.') | |||
EXPIRE = 30 | |||
"""Zone expiration timeout.""" | |||
def __init__(self): | |||
""" | |||
@@ -50,6 +70,9 @@ class Zonetracker(object): | |||
def update(self, message): | |||
""" | |||
Update zone statuses based on the current message. | |||
:param message: Message to use to update the zone tracking. | |||
:type message: Message or ExpanderMessage | |||
""" | |||
zone = -1 | |||
@@ -107,6 +130,9 @@ class Zonetracker(object): | |||
def _clear_zones(self, zone): | |||
""" | |||
Clear all expired zones from our status list. | |||
:param zone: current zone being processed. | |||
:type zone: int | |||
""" | |||
cleared_zones = [] | |||
found_last = found_new = at_end = False | |||
@@ -177,6 +203,13 @@ class Zonetracker(object): | |||
def _add_zone(self, zone, name='', status=Zone.CLEAR): | |||
""" | |||
Adds a zone to the internal zone list. | |||
:param zone: The zone number. | |||
:type zone: int | |||
:param name: Human readable zone name. | |||
:type name: str | |||
:param status: The zone status. | |||
:type status: int | |||
""" | |||
if not zone in self._zones: | |||
self._zones[zone] = Zone(zone=zone, name=name, status=status) | |||
@@ -187,6 +220,13 @@ class Zonetracker(object): | |||
def _update_zone(self, zone, status=None): | |||
""" | |||
Updates a zones status. | |||
:param zone: The zone number. | |||
:type zone: int | |||
:param status: The zone status. | |||
:type status: int | |||
:raises: IndexError | |||
""" | |||
if not zone in self._zones: | |||
raise IndexError('Zone does not exist and cannot be updated: %d', zone) | |||
@@ -205,6 +245,11 @@ class Zonetracker(object): | |||
def _zone_expired(self, zone): | |||
""" | |||
Determine if a zone is expired or not. | |||
:param zone: The zone number. | |||
:type zone: int | |||
:returns: Whether or not the zone is expired. | |||
""" | |||
if time.time() > self._zones[zone].timestamp + Zonetracker.EXPIRE: | |||
return True | |||
@@ -214,6 +259,13 @@ class Zonetracker(object): | |||
def _expander_to_zone(self, address, channel): | |||
""" | |||
Convert an address and channel into a zone number. | |||
:param address: The expander address | |||
:type address: int | |||
:param channel: The channel | |||
:type channel: int | |||
:returns: The zone number associated with an address and channel. | |||
""" | |||
# TODO: This is going to need to be reworked to support the larger | |||