|
- <!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>
|