summaryrefslogtreecommitdiff
path: root/plugins/operating_states.py
diff options
context:
space:
mode:
authorLoic Guegan <manzerbredes@mailbox.org>2022-06-14 17:13:46 +0200
committerLoic Guegan <manzerbredes@mailbox.org>2022-06-14 17:13:46 +0200
commit7f13c95e16a802d0706e9f5a6d5d845d7fd67631 (patch)
tree65cb3c0faec397cb1b06894645d060514f6b242d /plugins/operating_states.py
parentb6877cb81e56c3991d0dbcf9fa579f627a4c2a29 (diff)
Major refactoring:
- Create pip package - Reorganized source code
Diffstat (limited to 'plugins/operating_states.py')
-rw-r--r--plugins/operating_states.py66
1 files changed, 0 insertions, 66 deletions
diff --git a/plugins/operating_states.py b/plugins/operating_states.py
deleted file mode 100644
index 400aa1b..0000000
--- a/plugins/operating_states.py
+++ /dev/null
@@ -1,66 +0,0 @@
-#!/usr/bin/env python
-
-from plugins.node_plugin import *
-
-######################
-# _ ____ ___ #
-# / \ | _ \_ _| #
-# / _ \ | |_) | | #
-# / ___ \| __/| | #
-# /_/ \_\_| |___| #
-# #
-######################
-
-# import plugins.operating_states as op
-# # Load the directional transition graph from graph.txt starting at the "vertex1" state
-# opstate=op.OperatingStates(api,"graph.txt","vertex1")
-# Format of the graph.txt file consists in one edge per line
-# that consists on the source vertex and destination vertex sperated by a space
-# As an example:
-# vertex1 vertex2
-# vertex1 vertex3
-# vertex3 vertex2
-# vertex2 vertex1
-#
-# opstate.register_callback(boom)
-# # On each state transition boom will be called as boom(src_state,dst_state)
-# # This way the boom callback can contains power_state transitions for examples
-# opstate.goto("vertex2") # works
-# opstate.goto("vertex3") # wont work
-# opstate.goto("vertex1") # work since we are on vertex2
-
-class OperatingStates(NodePlugin):
- """
- OperatingStates plugin
- """
- def __init__(self,api, state_file, initial_state):
- self.transitions=list()
- self.callbacks=list()
- self.state=initial_state
- with open(state_file) as fp:
- for i, line in enumerate(fp):
- self.transitions.append(line)
- super().__init__("OperatingStates",api)
-
- def goto(self,state):
- if (self.state+" "+state) in self.transitions:
- old_state=self.state
- self.state=state
- for c in self.callbacks:
- c(old_state,state)
- else:
- self.log("Invalid transition "+self.state+" => "+state)
-
- def get_state(self):
- return(self.state)
-
- def register_callback(self,callback):
- """
- The callback will be called on each state transition
- Callback takes two arguments which are:
- - The source state
- - The destination state
- """
- self.callbacks.append(callback)
-
-