Python Library State Machine
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

index.html 28KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488
  1. <!DOCTYPE html>
  2. <html class="writer-html4" lang="en" >
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Welcome to state_machine’s documentation! &mdash; state_machine documentation</title>
  7. <link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
  8. <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
  9. <!--[if lt IE 9]>
  10. <script src="_static/js/html5shiv.min.js"></script>
  11. <![endif]-->
  12. <script type="text/javascript" id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></script>
  13. <script type="text/javascript" src="_static/jquery.js"></script>
  14. <script type="text/javascript" src="_static/underscore.js"></script>
  15. <script type="text/javascript" src="_static/doctools.js"></script>
  16. <script type="text/javascript" src="_static/language_data.js"></script>
  17. <script type="text/javascript" src="_static/js/theme.js"></script>
  18. <link rel="index" title="Index" href="genindex.html" />
  19. <link rel="search" title="Search" href="search.html" />
  20. </head>
  21. <body class="wy-body-for-nav">
  22. <div class="wy-grid-for-nav">
  23. <nav data-toggle="wy-nav-shift" class="wy-nav-side">
  24. <div class="wy-side-scroll">
  25. <div class="wy-side-nav-search" >
  26. <a href="#" class="icon icon-home" alt="Documentation Home"> state_machine
  27. </a>
  28. <div role="search">
  29. <form id="rtd-search-form" class="wy-form" action="search.html" method="get">
  30. <input type="text" name="q" placeholder="Search docs" />
  31. <input type="hidden" name="check_keywords" value="yes" />
  32. <input type="hidden" name="area" value="default" />
  33. </form>
  34. </div>
  35. </div>
  36. <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
  37. <!-- Local TOC -->
  38. <div class="local-toc"><ul>
  39. <li><a class="reference internal" href="#">Welcome to state_machine’s documentation!</a><ul>
  40. <li><a class="reference internal" href="#state-machine-state-machine">state_machine (State Machine)</a></li>
  41. </ul>
  42. </li>
  43. <li><a class="reference internal" href="#indices-and-tables">Indices and tables</a></li>
  44. </ul>
  45. </div>
  46. </div>
  47. </div>
  48. </nav>
  49. <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
  50. <nav class="wy-nav-top" aria-label="top navigation">
  51. <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
  52. <a href="#">state_machine</a>
  53. </nav>
  54. <div class="wy-nav-content">
  55. <div class="rst-content">
  56. <div role="navigation" aria-label="breadcrumbs navigation">
  57. <ul class="wy-breadcrumbs">
  58. <li><a href="#" class="icon icon-home"></a> &raquo;</li>
  59. <li>Welcome to state_machine’s documentation!</li>
  60. <li class="wy-breadcrumbs-aside">
  61. <a href="_sources/index.rst.txt" rel="nofollow"> View page source</a>
  62. </li>
  63. </ul>
  64. <hr/>
  65. </div>
  66. <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
  67. <div itemprop="articleBody">
  68. <div class="section" id="module-state_machine">
  69. <span id="welcome-to-state-machine-s-documentation"></span><h1>Welcome to state_machine’s documentation!<a class="headerlink" href="#module-state_machine" title="Permalink to this headline">¶</a></h1>
  70. <div class="section" id="state-machine-state-machine">
  71. <h2>state_machine (State Machine)<a class="headerlink" href="#state-machine-state-machine" title="Permalink to this headline">¶</a></h2>
  72. <p><strong>Author:</strong></p>
  73. <ul class="simple">
  74. <li>Dirk Alders &lt;<a class="reference external" href="mailto:sudo-dirk&#37;&#52;&#48;mount-mockery&#46;de">sudo-dirk<span>&#64;</span>mount-mockery<span>&#46;</span>de</a>&gt;</li>
  75. </ul>
  76. <p><strong>Description:</strong></p>
  77. <blockquote>
  78. <div>This Module helps implementing state machines.</div></blockquote>
  79. <p><strong>Submodules:</strong></p>
  80. <ul class="simple">
  81. <li><a class="reference internal" href="#state_machine.state_machine" title="state_machine.state_machine"><code class="xref py py-class docutils literal notranslate"><span class="pre">state_machine.state_machine</span></code></a></li>
  82. </ul>
  83. <p><strong>Unittest:</strong></p>
  84. <blockquote>
  85. <div>See also the <a class="reference download internal" download="" href="_downloads/e2fbca9180ad234c517493570f525e69/unittest.pdf"><code class="xref download docutils literal notranslate"><span class="pre">unittest</span></code></a> documentation.</div></blockquote>
  86. <p><strong>Module Documentation:</strong></p>
  87. <dl class="class">
  88. <dt id="state_machine.state_machine">
  89. <em class="property">class </em><code class="descclassname">state_machine.</code><code class="descname">state_machine</code><span class="sig-paren">(</span><em>default_state</em>, <em>log_lvl</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#state_machine.state_machine" title="Permalink to this definition">¶</a></dt>
  90. <dd><table class="docutils field-list" frame="void" rules="none">
  91. <col class="field-name" />
  92. <col class="field-body" />
  93. <tbody valign="top">
  94. <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
  95. <li><strong>default_state</strong> – The default state which is set on initialisation.</li>
  96. <li><strong>log_lvl</strong> – The log level, this Module logs to (see Loging-Levels of Module <code class="xref py py-mod docutils literal notranslate"><span class="pre">logging</span></code>)</li>
  97. </ul>
  98. </td>
  99. </tr>
  100. </tbody>
  101. </table>
  102. <div class="admonition note">
  103. <p class="first admonition-title">Note</p>
  104. <p class="last">Additional keyword parameters well be stored as varibles of the instance (e.g. to give variables or methods for transition condition calculation).</p>
  105. </div>
  106. <p>A state machine class can be created by deriving it from this class. The transitions are defined by overriding the variable <cite>TRANSITIONS</cite>.
  107. This Variable is a dictionary, where the key is the start-state and the content is a tuple or list of transitions. Each transition is a tuple or list
  108. including the following information: (condition-method (str), transition-time (number), target_state (str)).</p>
  109. <div class="admonition note">
  110. <p class="first admonition-title">Note</p>
  111. <p class="last">The condition-method needs to be implemented as part of the new class.</p>
  112. </div>
  113. <div class="admonition note">
  114. <p class="first admonition-title">Note</p>
  115. <p class="last">It is usefull to define the states as variables of this class.</p>
  116. </div>
  117. <p><strong>Example:</strong></p>
  118. <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="ch">#!/usr/bin/env python</span>
  119. <span class="c1"># -*- coding: UTF-8 -*-</span>
  120. <span class="kn">import</span> <span class="nn">sys</span>
  121. <span class="n">sys</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">&#39;../..&#39;</span><span class="p">)</span>
  122. <span class="kn">import</span> <span class="nn">logging</span>
  123. <span class="kn">import</span> <span class="nn">os</span>
  124. <span class="kn">import</span> <span class="nn">report</span>
  125. <span class="kn">import</span> <span class="nn">state_machine</span>
  126. <span class="n">logger</span> <span class="o">=</span> <span class="n">logging</span><span class="o">.</span><span class="n">getLogger</span><span class="p">(</span><span class="s1">&#39;root&#39;</span><span class="p">)</span>
  127. <span class="n">report</span><span class="o">.</span><span class="n">stdoutLoggingConfigure</span><span class="p">(</span><span class="n">log_name_lvl</span><span class="o">=</span><span class="p">[(</span><span class="s1">&#39;root&#39;</span><span class="p">,</span> <span class="s1">&#39;DEBUG&#39;</span><span class="p">),</span> <span class="p">])</span>
  128. <span class="k">class</span> <span class="nc">trafic_lights</span><span class="p">(</span><span class="n">state_machine</span><span class="o">.</span><span class="n">state_machine</span><span class="p">):</span>
  129. <span class="n">LOG_PREFIX</span> <span class="o">=</span> <span class="s1">&#39;TraficLights:&#39;</span>
  130. <span class="n">STATE_RED</span> <span class="o">=</span> <span class="s1">&#39;state_red&#39;</span>
  131. <span class="n">STATE_GREEN</span> <span class="o">=</span> <span class="s1">&#39;state_green&#39;</span>
  132. <span class="n">CONDITION_TRUE</span> <span class="o">=</span> <span class="s1">&#39;condition_true&#39;</span>
  133. <span class="n">CONDITION_PEDASTRIAN_REQUEST</span> <span class="o">=</span> <span class="s1">&#39;condition_pedastrian_request&#39;</span>
  134. <span class="n">TRANSITIONS</span> <span class="o">=</span> <span class="p">{</span>
  135. <span class="n">STATE_RED</span><span class="p">:</span> <span class="p">(</span>
  136. <span class="p">(</span><span class="n">CONDITION_PEDASTRIAN_REQUEST</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="n">STATE_GREEN</span><span class="p">),</span>
  137. <span class="p">),</span>
  138. <span class="n">STATE_GREEN</span><span class="p">:</span> <span class="p">(</span>
  139. <span class="p">(</span><span class="n">CONDITION_TRUE</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="n">STATE_RED</span><span class="p">),</span>
  140. <span class="p">)</span>
  141. <span class="p">}</span>
  142. <span class="k">def</span> <span class="nf">condition_true</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
  143. <span class="k">return</span> <span class="kc">True</span>
  144. <span class="k">def</span> <span class="nf">set_padestrian_request</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
  145. <span class="n">logger</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">__log_lvl__</span><span class="p">,</span> <span class="s1">&#39;</span><span class="si">%s</span><span class="s1"> Pedestrian gave state change request.&#39;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">LOG_PREFIX</span><span class="p">)</span>
  146. <span class="bp">self</span><span class="o">.</span><span class="n">pedastrian_request</span> <span class="o">=</span> <span class="kc">True</span>
  147. <span class="k">def</span> <span class="nf">condition_pedastrian_request</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
  148. <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">pedastrian_request</span>
  149. <span class="n">sm</span> <span class="o">=</span> <span class="n">trafic_lights</span><span class="p">(</span><span class="n">trafic_lights</span><span class="o">.</span><span class="n">STATE_RED</span><span class="p">,</span> <span class="n">logging</span><span class="o">.</span><span class="n">INFO</span><span class="p">,</span> <span class="n">pedastrian_request</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
  150. <span class="n">sm</span><span class="o">.</span><span class="n">register_state_change_callback</span><span class="p">(</span><span class="n">sm</span><span class="o">.</span><span class="n">STATE_GREEN</span><span class="p">,</span> <span class="n">sm</span><span class="o">.</span><span class="n">CONDITION_PEDASTRIAN_REQUEST</span><span class="p">,</span> <span class="n">logger</span><span class="o">.</span><span class="n">info</span><span class="p">,</span> <span class="s1">&#39;Callback information: Traffic light had been changed to green caused by pedastrian request&#39;</span><span class="p">)</span>
  151. <span class="k">while</span> <span class="ow">not</span> <span class="n">sm</span><span class="o">.</span><span class="n">previous_state_was</span><span class="p">(</span><span class="n">sm</span><span class="o">.</span><span class="n">STATE_GREEN</span><span class="p">):</span>
  152. <span class="k">if</span> <span class="n">sm</span><span class="o">.</span><span class="n">this_state_is</span><span class="p">(</span><span class="n">sm</span><span class="o">.</span><span class="n">STATE_RED</span><span class="p">)</span> <span class="ow">and</span> <span class="n">sm</span><span class="o">.</span><span class="n">this_state_duration</span><span class="p">()</span> <span class="o">&gt;</span> <span class="mf">0.2</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">sm</span><span class="o">.</span><span class="n">condition_pedastrian_request</span><span class="p">():</span>
  153. <span class="n">sm</span><span class="o">.</span><span class="n">set_padestrian_request</span><span class="p">()</span>
  154. <span class="n">sm</span><span class="o">.</span><span class="n">work</span><span class="p">()</span>
  155. </pre></div>
  156. </div>
  157. <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="mi">2021</span><span class="o">-</span><span class="mi">01</span><span class="o">-</span><span class="mi">07</span> <span class="mi">01</span><span class="p">:</span><span class="mi">36</span><span class="p">:</span><span class="mi">29</span><span class="p">,</span><span class="mi">619</span><span class="p">:</span> <span class="n">root</span><span class="o">.</span><span class="n">state_machine</span> <span class="o">-</span> <span class="n">INFO</span> <span class="o">-</span> <span class="n">TraficLights</span><span class="p">:</span> <span class="n">State</span> <span class="n">change</span> <span class="p">(</span><span class="s1">&#39;__init__&#39;</span><span class="p">):</span> <span class="kc">None</span> <span class="o">-&gt;</span> <span class="s1">&#39;state_red&#39;</span>
  158. <span class="mi">2021</span><span class="o">-</span><span class="mi">01</span><span class="o">-</span><span class="mi">07</span> <span class="mi">01</span><span class="p">:</span><span class="mi">36</span><span class="p">:</span><span class="mi">29</span><span class="p">,</span><span class="mi">819</span><span class="p">:</span> <span class="n">root</span> <span class="o">-</span> <span class="n">INFO</span> <span class="o">-</span> <span class="n">TraficLights</span><span class="p">:</span> <span class="n">Pedestrian</span> <span class="n">gave</span> <span class="n">state</span> <span class="n">change</span> <span class="n">request</span><span class="o">.</span>
  159. <span class="mi">2021</span><span class="o">-</span><span class="mi">01</span><span class="o">-</span><span class="mi">07</span> <span class="mi">01</span><span class="p">:</span><span class="mi">36</span><span class="p">:</span><span class="mi">30</span><span class="p">,</span><span class="mi">819</span><span class="p">:</span> <span class="n">root</span><span class="o">.</span><span class="n">state_machine</span> <span class="o">-</span> <span class="n">INFO</span> <span class="o">-</span> <span class="n">TraficLights</span><span class="p">:</span> <span class="n">State</span> <span class="n">change</span> <span class="p">(</span><span class="s1">&#39;condition_pedastrian_request&#39;</span><span class="p">):</span> <span class="s1">&#39;state_red&#39;</span> <span class="o">-&gt;</span> <span class="s1">&#39;state_green&#39;</span>
  160. <span class="mi">2021</span><span class="o">-</span><span class="mi">01</span><span class="o">-</span><span class="mi">07</span> <span class="mi">01</span><span class="p">:</span><span class="mi">36</span><span class="p">:</span><span class="mi">30</span><span class="p">,</span><span class="mi">819</span><span class="p">:</span> <span class="n">root</span><span class="o">.</span><span class="n">state_machine</span> <span class="o">-</span> <span class="n">DEBUG</span> <span class="o">-</span> <span class="n">Executing</span> <span class="n">callback</span> <span class="mi">0</span> <span class="o">-</span> <span class="n">logging</span><span class="o">.</span><span class="n">info</span>
  161. <span class="mi">2021</span><span class="o">-</span><span class="mi">01</span><span class="o">-</span><span class="mi">07</span> <span class="mi">01</span><span class="p">:</span><span class="mi">36</span><span class="p">:</span><span class="mi">30</span><span class="p">,</span><span class="mi">819</span><span class="p">:</span> <span class="n">root</span> <span class="o">-</span> <span class="n">INFO</span> <span class="o">-</span> <span class="n">Callback</span> <span class="n">information</span><span class="p">:</span> <span class="n">Traffic</span> <span class="n">light</span> <span class="n">had</span> <span class="n">been</span> <span class="n">changed</span> <span class="n">to</span> <span class="n">green</span> <span class="n">caused</span> <span class="n">by</span> <span class="n">pedastrian</span> <span class="n">request</span>
  162. <span class="mi">2021</span><span class="o">-</span><span class="mi">01</span><span class="o">-</span><span class="mi">07</span> <span class="mi">01</span><span class="p">:</span><span class="mi">36</span><span class="p">:</span><span class="mi">33</span><span class="p">,</span><span class="mi">819</span><span class="p">:</span> <span class="n">root</span><span class="o">.</span><span class="n">state_machine</span> <span class="o">-</span> <span class="n">INFO</span> <span class="o">-</span> <span class="n">TraficLights</span><span class="p">:</span> <span class="n">State</span> <span class="n">change</span> <span class="p">(</span><span class="s1">&#39;condition_true&#39;</span><span class="p">):</span> <span class="s1">&#39;state_green&#39;</span> <span class="o">-&gt;</span> <span class="s1">&#39;state_red&#39;</span>
  163. </pre></div>
  164. </div>
  165. <dl class="method">
  166. <dt id="state_machine.state_machine.last_transition_condition">
  167. <code class="descname">last_transition_condition</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#state_machine.state_machine.last_transition_condition" title="Permalink to this definition">¶</a></dt>
  168. <dd><table class="docutils field-list" frame="void" rules="none">
  169. <col class="field-name" />
  170. <col class="field-body" />
  171. <tbody valign="top">
  172. <tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">The last transition condition.</td>
  173. </tr>
  174. <tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body">str</td>
  175. </tr>
  176. </tbody>
  177. </table>
  178. <p>This method returns the last transition condition.</p>
  179. </dd></dl>
  180. <dl class="method">
  181. <dt id="state_machine.state_machine.last_transition_condition_was">
  182. <code class="descname">last_transition_condition_was</code><span class="sig-paren">(</span><em>condition</em><span class="sig-paren">)</span><a class="headerlink" href="#state_machine.state_machine.last_transition_condition_was" title="Permalink to this definition">¶</a></dt>
  183. <dd><table class="docutils field-list" frame="void" rules="none">
  184. <col class="field-name" />
  185. <col class="field-body" />
  186. <tbody valign="top">
  187. <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>condition</strong> (<em>str</em>) – The condition to be checked</td>
  188. </tr>
  189. <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">True if the given condition was the last transition condition, else False.</td>
  190. </tr>
  191. <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body">bool</td>
  192. </tr>
  193. </tbody>
  194. </table>
  195. <p>This methods returns the boolean information if the last transition condition is equivalent to the given condition.</p>
  196. </dd></dl>
  197. <dl class="method">
  198. <dt id="state_machine.state_machine.previous_state">
  199. <code class="descname">previous_state</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#state_machine.state_machine.previous_state" title="Permalink to this definition">¶</a></dt>
  200. <dd><table class="docutils field-list" frame="void" rules="none">
  201. <col class="field-name" />
  202. <col class="field-body" />
  203. <tbody valign="top">
  204. <tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">The previous state.</td>
  205. </tr>
  206. <tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body">str</td>
  207. </tr>
  208. </tbody>
  209. </table>
  210. <p>This method returns the previous state of the state machine.</p>
  211. </dd></dl>
  212. <dl class="method">
  213. <dt id="state_machine.state_machine.previous_state_duration">
  214. <code class="descname">previous_state_duration</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#state_machine.state_machine.previous_state_duration" title="Permalink to this definition">¶</a></dt>
  215. <dd><table class="docutils field-list" frame="void" rules="none">
  216. <col class="field-name" />
  217. <col class="field-body" />
  218. <tbody valign="top">
  219. <tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">The time how long the previous state was active.</td>
  220. </tr>
  221. <tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body">float</td>
  222. </tr>
  223. </tbody>
  224. </table>
  225. <p>This method returns the time how long the previous state was active.</p>
  226. </dd></dl>
  227. <dl class="method">
  228. <dt id="state_machine.state_machine.previous_state_was">
  229. <code class="descname">previous_state_was</code><span class="sig-paren">(</span><em>state</em><span class="sig-paren">)</span><a class="headerlink" href="#state_machine.state_machine.previous_state_was" title="Permalink to this definition">¶</a></dt>
  230. <dd><table class="docutils field-list" frame="void" rules="none">
  231. <col class="field-name" />
  232. <col class="field-body" />
  233. <tbody valign="top">
  234. <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>state</strong> (<em>str</em>) – The state to be checked</td>
  235. </tr>
  236. <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">True if the given state was previously active, else False.</td>
  237. </tr>
  238. <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body">bool</td>
  239. </tr>
  240. </tbody>
  241. </table>
  242. <p>This methods returns the boolean information if the state machine was previously in the given state.</p>
  243. </dd></dl>
  244. <dl class="method">
  245. <dt id="state_machine.state_machine.register_state_change_callback">
  246. <code class="descname">register_state_change_callback</code><span class="sig-paren">(</span><em>state</em>, <em>condition</em>, <em>callback</em>, <em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#state_machine.state_machine.register_state_change_callback" title="Permalink to this definition">¶</a></dt>
  247. <dd><table class="docutils field-list" frame="void" rules="none">
  248. <col class="field-name" />
  249. <col class="field-body" />
  250. <tbody valign="top">
  251. <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
  252. <li><strong>state</strong> (<em>str</em>) – The target state. The callback will be executed, if the state machine changes to this state. None means all states.</li>
  253. <li><strong>condition</strong> (<em>str</em>) – The transition condition. The callback will be executed, if this condition is responsible for the state change. None means all conditions.</li>
  254. <li><strong>callback</strong> – The callback to be executed.</li>
  255. </ul>
  256. </td>
  257. </tr>
  258. </tbody>
  259. </table>
  260. <div class="admonition note">
  261. <p class="first admonition-title">Note</p>
  262. <p class="last">Additional arguments and keyword parameters are supported. These arguments and parameters will be used as arguments and parameters for the callback execution.</p>
  263. </div>
  264. <p>This methods allows to register callbacks which will be executed on state changes.</p>
  265. </dd></dl>
  266. <dl class="method">
  267. <dt id="state_machine.state_machine.this_state">
  268. <code class="descname">this_state</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#state_machine.state_machine.this_state" title="Permalink to this definition">¶</a></dt>
  269. <dd><table class="docutils field-list" frame="void" rules="none">
  270. <col class="field-name" />
  271. <col class="field-body" />
  272. <tbody valign="top">
  273. <tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">The current state.</td>
  274. </tr>
  275. </tbody>
  276. </table>
  277. <p>This method returns the current state of the state machine.</p>
  278. </dd></dl>
  279. <dl class="method">
  280. <dt id="state_machine.state_machine.this_state_duration">
  281. <code class="descname">this_state_duration</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#state_machine.state_machine.this_state_duration" title="Permalink to this definition">¶</a></dt>
  282. <dd><table class="docutils field-list" frame="void" rules="none">
  283. <col class="field-name" />
  284. <col class="field-body" />
  285. <tbody valign="top">
  286. <tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">The time how long the current state is active.</td>
  287. </tr>
  288. <tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body">float</td>
  289. </tr>
  290. </tbody>
  291. </table>
  292. <p>This method returns the time how long the current state is active.</p>
  293. </dd></dl>
  294. <dl class="method">
  295. <dt id="state_machine.state_machine.this_state_is">
  296. <code class="descname">this_state_is</code><span class="sig-paren">(</span><em>state</em><span class="sig-paren">)</span><a class="headerlink" href="#state_machine.state_machine.this_state_is" title="Permalink to this definition">¶</a></dt>
  297. <dd><table class="docutils field-list" frame="void" rules="none">
  298. <col class="field-name" />
  299. <col class="field-body" />
  300. <tbody valign="top">
  301. <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>state</strong> (<em>str</em>) – The state to be checked</td>
  302. </tr>
  303. <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">True if the given state is currently active, else False.</td>
  304. </tr>
  305. <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body">bool</td>
  306. </tr>
  307. </tbody>
  308. </table>
  309. <p>This methods returns the boolean information if the state machine is currently in the given state.</p>
  310. </dd></dl>
  311. <dl class="method">
  312. <dt id="state_machine.state_machine.work">
  313. <code class="descname">work</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#state_machine.state_machine.work" title="Permalink to this definition">¶</a></dt>
  314. <dd><p>This Method needs to be executed cyclicly to enable the state machine.</p>
  315. </dd></dl>
  316. </dd></dl>
  317. </div>
  318. <div class="toctree-wrapper compound">
  319. </div>
  320. </div>
  321. <div class="section" id="indices-and-tables">
  322. <h1>Indices and tables<a class="headerlink" href="#indices-and-tables" title="Permalink to this headline">¶</a></h1>
  323. <ul class="simple">
  324. <li><a class="reference internal" href="genindex.html"><span class="std std-ref">Index</span></a></li>
  325. <li><a class="reference internal" href="py-modindex.html"><span class="std std-ref">Module Index</span></a></li>
  326. <li><a class="reference internal" href="search.html"><span class="std std-ref">Search Page</span></a></li>
  327. </ul>
  328. </div>
  329. </div>
  330. </div>
  331. <footer>
  332. <hr/>
  333. <div role="contentinfo">
  334. <p>
  335. &copy; Copyright 2021, Dirk Alders
  336. </p>
  337. </div>
  338. Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a
  339. <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a>
  340. provided by <a href="https://readthedocs.org">Read the Docs</a>.
  341. </footer>
  342. </div>
  343. </div>
  344. </section>
  345. </div>
  346. <script type="text/javascript">
  347. jQuery(function () {
  348. SphinxRtdTheme.Navigation.enable(true);
  349. });
  350. </script>
  351. </body>
  352. </html>