Statemachine

I’ve managed to merge my sample state machine code into homegenie and have occupancy crudely working…

Just need to add a way of adding a module to a location… question is - does the location class hold a module list or should the module have a location field?

Hmm…

I want to trigger things when a module changes - I guess having it on the module saves enumerating the list each time? @Bounz?

Yes, I think that it’s better to have Location field in Module class.

1 Like

How is a persons presence sensed?

however you tell it to be, at the moment I have an enum containing statically defined triggers and use the module Helper to trigger it, but I feel we can do better yet, need to wrap my head around the Helper classes yet.

for reference - i was modeling this around what I want to achieve - needs more tweaking yet I think so that I can test it properly but I can export the statemachine in dot format which lets you display what I am thinking:

the dotgraph looks like:

digraph {
 UnOccupied -> Occupied [label="SensorActivity"];
 UnOccupied -> ChildOccupied [label="ChildOccupied"];
 UnOccupied -> UnOccupied [label="AlarmFullSet"];
 Occupied -> UnOccupied [label="AlarmFullSet"];
 Occupied -> Asleep [label="AlarmPartSet"];
 Occupied -> UnOccupied [label="OccupancyTimerExpires"];
 Occupied -> Occupied [label="SensorActivity"];
 ChildOccupied -> ChildOccupied [label="ChildOccupied"];
 ChildOccupied -> Occupied [label="SensorActivity"];
 Asleep -> Occupied [label="AlarmUnset"];
node [shape=box];
 UnOccupied -> "<CreateStateMachine>b__4_0" [label="On Entry" style=dotted];
 Occupied -> "<CreateStateMachine>b__4_1" [label="On Entry" style=dotted];
 Occupied -> "<CreateStateMachine>b__4_2" [label="On Exit" style=dotted];
 ChildOccupied -> "<CreateStateMachine>b__4_3" [label="On Entry" style=dotted];
 Asleep -> "<CreateStateMachine>b__4_4" [label="On Entry" style=dotted];
}

which can be visualised here:

http://www.webgraphviz.com/

I think I have got to the bottom of serialising the classes now - unfortunatley not as XML (binary) - I’m then going to see if I can make state persist reboots and software upgrades… Maybe…