Started on events and actions
authorArjen Baart <arjen@andromeda.nl>
Tue, 18 Feb 2020 08:38:27 +0000 (09:38 +0100)
committerArjen Baart <arjen@andromeda.nl>
Tue, 18 Feb 2020 08:38:27 +0000 (09:38 +0100)
doc/design.xml
doc/wakeup-classes.svg
src/action.h [new file with mode: 0644]
src/event.h [new file with mode: 0644]

index 0426b40..9aef045 100644 (file)
     <enumerate>
     <item>Set the date to dec 21, 23:00.</item>
     <item>Set a wakeup event at dec 22, 06:00</item>
+    <item>Start wakeup daemon</item>
+    <item>Verify lights on at 06:00</item>
+    <item>Verify lights off at sunrise</item>
     </enumerate>
   </item>
   <item>
@@ -338,10 +341,10 @@ depending on the times of sunrise and sunset.
 
 <para>
 The wakeup times are specified like calendar events, possibly with a recurrence pattern and an end date.
-Elements in a wakeup event are:
+Elements in an event are:
 <itemize>
    <item> Label</item>
-   <item> Light parameters</item>
+   <item> Action</item>
    <item> Start time</item>
    <item> Recurrence pattern</item>
    <item> Number of recurrences</item>
@@ -349,8 +352,23 @@ Elements in a wakeup event are:
 </itemize>
 A recurrence pattern can be specified with a number of days, weeks or months as well as a set of weekdays.
 A set of weekdays implies the recurrence will be weekly.
+The action for an event can be a light sequence or a curtain control.
 </para>
 
+<para>
+An event is read from an XML element or created dynamically, for example calculated from the time of sunrise.
+From any event, the next occurance is calculated, which is an event that happens after a certain time.
+When the next event does happen, meaning the time of the occurance is the current time, the sequence of actions is executed.
+Each action can for example be a change in lights or the opening or closing of curtains.
+Event methods:
+
+FromXML
+ToXML
+add_recurrance
+next_occurance
+add_action
+execute_actions
+</para>
     </section>
     </chapter>
 
index ee1ae88..950d04b 100644 (file)
      borderopacity="1.0"
      inkscape:pageopacity="0.0"
      inkscape:pageshadow="2"
-     inkscape:zoom="2"
-     inkscape:cx="286.177"
-     inkscape:cy="871.65698"
+     inkscape:zoom="0.86772068"
+     inkscape:cx="255.00379"
+     inkscape:cy="579.0815"
      inkscape:document-units="mm"
      inkscape:current-layer="layer1"
      showgrid="false"
-     inkscape:window-width="1920"
-     inkscape:window-height="1163"
-     inkscape:window-x="0"
-     inkscape:window-y="0"
-     inkscape:window-maximized="1" />
+     inkscape:window-width="1711"
+     inkscape:window-height="1023"
+     inkscape:window-x="51"
+     inkscape:window-y="42"
+     inkscape:window-maximized="0" />
   <metadata
      id="metadata4524">
     <rdf:RDF>
@@ -44,7 +44,7 @@
         <dc:format>image/svg+xml</dc:format>
         <dc:type
            rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
-        <dc:title></dc:title>
+        <dc:title />
       </cc:Work>
     </rdf:RDF>
   </metadata>
      inkscape:groupmode="layer"
      id="layer1">
     <rect
-       style="opacity:1;fill:none;fill-opacity:1;stroke:#000000;stroke-width:0.265;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
+       style="opacity:1;fill:none;fill-opacity:1;stroke:#000000;stroke-width:0.26499999;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
        id="rect5072"
        width="42.068748"
        height="55.033333"
-       x="59.266666"
+       x="36.777084"
        y="25.537498" />
     <rect
        style="opacity:1;fill:none;fill-opacity:1;stroke:#000000;stroke-width:0.26583725;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
        id="rect5074"
        width="42.068752"
        height="7.6729164"
-       x="59.266666"
+       x="36.777084"
        y="25.537498" />
     <text
        xml:space="preserve"
        style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:3.52777767px;line-height:125%;font-family:sans-serif;-inkscape-font-specification:sans-serif;font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-feature-settings:normal;text-align:center;letter-spacing:0px;word-spacing:0px;writing-mode:lr-tb;text-anchor:middle;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.26458332px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
-       x="68.262497"
+       x="45.772915"
        y="29.770834"
        id="text5078"><tspan
          sodipodi:role="line"
          id="tspan5076"
-         x="68.262497"
+         x="45.772915"
          y="29.770834"
          style="stroke-width:0.26458332px">Event</tspan></text>
     <text
        xml:space="preserve"
        style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:3.52777767px;line-height:125%;font-family:sans-serif;-inkscape-font-specification:sans-serif;font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-feature-settings:normal;text-align:start;letter-spacing:0px;word-spacing:0px;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.26458332px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
-       x="60.491741"
+       x="38.002159"
        y="37.443748"
        id="text5082"><tspan
          sodipodi:role="line"
          id="tspan5080"
-         x="60.491741"
+         x="38.002159"
          y="37.443748"
          style="text-align:start;text-anchor:start;stroke-width:0.26458332px">label</tspan></text>
     <text
        xml:space="preserve"
        style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:3.52777767px;line-height:125%;font-family:sans-serif;-inkscape-font-specification:sans-serif;font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-feature-settings:normal;text-align:center;letter-spacing:0px;word-spacing:0px;writing-mode:lr-tb;text-anchor:middle;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.26458332px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
-       x="65.219788"
+       x="42.730206"
        y="41.941666"
        id="text5086"><tspan
          sodipodi:role="line"
          id="tspan5084"
-         x="65.219788"
+         x="42.730206"
          y="41.941666"
-         style="stroke-width:0.26458332px">lights</tspan></text>
+         style="stroke-width:0.26458332px">action</tspan></text>
     <text
        xml:space="preserve"
        style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:3.52777767px;line-height:125%;font-family:sans-serif;-inkscape-font-specification:sans-serif;font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-feature-settings:normal;text-align:center;letter-spacing:0px;word-spacing:0px;writing-mode:lr-tb;text-anchor:middle;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.26458332px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
-       x="69.188538"
+       x="46.698956"
        y="46.836456"
        id="text5090"><tspan
          sodipodi:role="line"
          id="tspan5088"
-         x="69.188538"
+         x="46.698956"
          y="46.836456"
          style="stroke-width:0.26458332px">start_time</tspan></text>
     <text
        xml:space="preserve"
        style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:3.52777767px;line-height:125%;font-family:sans-serif;-inkscape-font-specification:sans-serif;font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-feature-settings:normal;text-align:center;letter-spacing:0px;word-spacing:0px;writing-mode:lr-tb;text-anchor:middle;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.26458332px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
-       x="69.585411"
+       x="47.095829"
        y="51.06979"
        id="text5094"><tspan
          sodipodi:role="line"
          id="tspan5092"
-         x="69.585411"
+         x="47.095829"
          y="51.06979"
          style="stroke-width:0.26458332px">recurrence</tspan></text>
     <rect
-       y="25.802082"
-       x="113.77084"
+       y="199.66109"
+       x="82.724586"
        height="55.033333"
        width="42.068748"
        id="rect5096"
        style="opacity:1;fill:none;fill-opacity:1;stroke:#000000;stroke-width:0.26499999;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" />
     <rect
-       y="25.802082"
-       x="113.77084"
+       y="199.66109"
+       x="82.724586"
        height="7.6729164"
        width="42.068752"
        id="rect5098"
        style="opacity:1;fill:none;fill-opacity:1;stroke:#000000;stroke-width:0.26583725;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" />
     <text
        id="text5102"
-       y="30.564585"
-       x="131.6302"
+       y="204.42358"
+       x="100.58395"
        style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:3.52777767px;line-height:125%;font-family:sans-serif;-inkscape-font-specification:sans-serif;font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-feature-settings:normal;text-align:center;letter-spacing:0px;word-spacing:0px;writing-mode:lr-tb;text-anchor:middle;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.26458332px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
        xml:space="preserve"><tspan
          style="stroke-width:0.26458332px"
-         y="30.564585"
-         x="131.6302"
-         id="tspan5100"
-         sodipodi:role="line">Lightsequence</tspan></text>
+         y="204.42358"
+         x="100.58395"
+         sodipodi:role="line"
+         id="tspan4510">Lightstep</tspan></text>
     <text
        id="text5106"
-       y="37.708332"
-       x="114.99591"
+       y="211.56734"
+       x="83.949654"
        style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:3.52777767px;line-height:125%;font-family:sans-serif;-inkscape-font-specification:sans-serif;font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-feature-settings:normal;text-align:start;letter-spacing:0px;word-spacing:0px;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.26458332px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
        xml:space="preserve"><tspan
          style="text-align:start;text-anchor:start;stroke-width:0.26458332px"
-         y="37.708332"
-         x="114.99591"
+         y="211.56734"
+         x="83.949654"
          id="tspan5104"
          sodipodi:role="line">lightlevel</tspan></text>
     <text
        id="text5110"
-       y="42.470833"
-       x="123.03124"
+       y="216.32983"
+       x="91.984985"
        style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:3.52777767px;line-height:125%;font-family:sans-serif;-inkscape-font-specification:sans-serif;font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-feature-settings:normal;text-align:center;letter-spacing:0px;word-spacing:0px;writing-mode:lr-tb;text-anchor:middle;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.26458332px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
        xml:space="preserve"><tspan
          style="stroke-width:0.26458332px"
-         y="42.470833"
-         x="123.03124"
+         y="216.32983"
+         x="91.984985"
          id="tspan5108"
          sodipodi:role="line">fadetime</tspan></text>
     <rect
        id="rect5120"
        width="42.068748"
        height="55.033333"
-       x="60.060429"
-       y="91.286461" />
+       x="131.0829"
+       y="25.459591" />
     <rect
        style="opacity:1;fill:none;fill-opacity:1;stroke:#000000;stroke-width:0.26583725;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
        id="rect5122"
        width="42.068752"
        height="7.6729164"
-       x="60.060429"
-       y="91.286461" />
+       x="131.0829"
+       y="25.459591" />
     <text
        xml:space="preserve"
        style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:3.52777767px;line-height:125%;font-family:sans-serif;-inkscape-font-specification:sans-serif;font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-feature-settings:normal;text-align:center;letter-spacing:0px;word-spacing:0px;writing-mode:lr-tb;text-anchor:middle;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.26458332px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
-       x="79.63958"
-       y="96.048958"
+       x="150.66206"
+       y="30.22208"
        id="text5126"><tspan
          sodipodi:role="line"
          id="tspan5124"
-         x="79.63958"
-         y="96.048958"
+         x="150.66206"
+         y="30.22208"
          style="stroke-width:0.26458332px">Event_Recurrence</tspan></text>
     <text
        xml:space="preserve"
        style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:3.52777767px;line-height:125%;font-family:sans-serif;-inkscape-font-specification:sans-serif;font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-feature-settings:normal;text-align:start;letter-spacing:0px;word-spacing:0px;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.26458332px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
-       x="61.285496"
-       y="103.19271"
+       x="132.30797"
+       y="37.365841"
        id="text5130"><tspan
          sodipodi:role="line"
          id="tspan5128"
-         x="61.285496"
-         y="103.19271"
+         x="132.30797"
+         y="37.365841"
          style="text-align:start;text-anchor:start;stroke-width:0.26458332px">number</tspan></text>
     <text
        xml:space="preserve"
        style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:3.52777767px;line-height:125%;font-family:sans-serif;-inkscape-font-specification:sans-serif;font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-feature-settings:normal;text-align:center;letter-spacing:0px;word-spacing:0px;writing-mode:lr-tb;text-anchor:middle;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.26458332px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
-       x="69.453117"
-       y="107.55833"
+       x="140.4756"
+       y="41.731457"
        id="text5134"><tspan
          sodipodi:role="line"
          id="tspan5132"
-         x="69.453117"
-         y="107.55833"
+         x="140.4756"
+         y="41.731457"
          style="stroke-width:0.26458332px">end_time</tspan></text>
+    <text
+       xml:space="preserve"
+       style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:3.52777767px;line-height:125%;font-family:sans-serif;-inkscape-font-specification:sans-serif;font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-feature-settings:normal;text-align:center;letter-spacing:0px;word-spacing:0px;writing-mode:lr-tb;text-anchor:middle;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.26458332px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
+       x="138.75581"
+       y="48.34605"
+       id="text4516"><tspan
+         sodipodi:role="line"
+         id="tspan4514"
+         x="138.75581"
+         y="48.34605"
+         style="stroke-width:0.26458332px">pattern</tspan></text>
+    <rect
+       style="opacity:1;fill:none;fill-opacity:1;stroke:#000000;stroke-width:0.26499999;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
+       id="rect4512"
+       width="42.068748"
+       height="55.033333"
+       x="35.338211"
+       y="96.064644" />
+    <rect
+       style="opacity:1;fill:none;fill-opacity:1;stroke:#000000;stroke-width:0.26583725;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
+       id="rect4514"
+       width="42.068752"
+       height="7.6729164"
+       x="35.338211"
+       y="96.064644" />
+    <text
+       xml:space="preserve"
+       style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:3.52777767px;line-height:125%;font-family:sans-serif;-inkscape-font-specification:sans-serif;font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-feature-settings:normal;text-align:center;letter-spacing:0px;word-spacing:0px;writing-mode:lr-tb;text-anchor:middle;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.26458332px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
+       x="53.197571"
+       y="100.82714"
+       id="text4518"><tspan
+         id="tspan4516"
+         sodipodi:role="line"
+         x="53.197571"
+         y="100.82714"
+         style="stroke-width:0.26458332px">Action</tspan></text>
+    <path
+       style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:0.26458332px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
+       d="m 79.991057,173.88707 4.959014,-5.17462 4.096578,5.17462 z"
+       id="path4528"
+       inkscape:connector-curvature="0" />
+    <path
+       style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:0.26458332px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
+       d="m 72.604193,151.09798 11.135499,18.87747"
+       id="path4530"
+       inkscape:connector-type="polyline"
+       inkscape:connector-curvature="0"
+       inkscape:connection-start="#rect4512"
+       inkscape:connection-end="#path4528" />
+    <path
+       style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:0.26458332px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
+       d="m 86.067029,173.88707 15.399691,25.77402"
+       id="path4532"
+       inkscape:connector-type="polyline"
+       inkscape:connector-curvature="0"
+       inkscape:connection-start="#path4528"
+       inkscape:connection-end="#rect5098" />
   </g>
 </svg>
diff --git a/src/action.h b/src/action.h
new file mode 100644 (file)
index 0000000..8f29894
--- /dev/null
@@ -0,0 +1,16 @@
+#include <list>
+#include <xml.h>
+#include <date.h>
+
+class Action
+{
+public:
+
+virtual void execute() = 0;
+
+}
+
+class Lightstep : Action
+{
+}
+
diff --git a/src/event.h b/src/event.h
new file mode 100644 (file)
index 0000000..ab1214e
--- /dev/null
@@ -0,0 +1,19 @@
+
+
+#include "action.h"
+
+class Event
+{
+   String            label;
+   date              start_time;
+   std::list<Action> sequence;
+
+public:
+
+   Event(String lbl)
+   {
+      label = lbl;
+   }
+
+   void FromXML(xmlnode x);
+}