[Automated-testing] [PATCH] RPS control changes for HW abstraction and a cli

Benjamin Esquivel benjamin.esquivel at linux.intel.com
Tue Jun 21 13:11:52 PDT 2016


changes included in this commit are:

- remote power switch class definition
- rpscli.py for the RPS module exercising
  the rpscontrol.py command line program will serve as the manual way
  to execute the RPS module. It can be also used for testing.
- rpscli reads an ini file for getting defaults, the ini file is added
- RPSControl class definition has a module
- RPS hardware abstraction layer draft
  the rps generic module is defined here and should provide the base
  class for the np0801dt hardware controlling module.

Signed-off-by: Benjamin Esquivel <benjamin.esquivel at linux.intel.com>
---
 devauto/rps/hw/__init__.py |  6 ++++++
 devauto/rps/hw/np0801dt.py | 13 +++++++++++++
 devauto/rps/hw/rpsgen.py   | 23 +++++++++++++++++++++++
 devauto/rps/rpscli.ini     |  3 +++
 devauto/rps/rpscli.py      | 40 ++++++++++++++++++++++++++++++++++++++++
 devauto/rps/rpscontrol.py  |  6 ++++++
 6 files changed, 91 insertions(+)
 create mode 100644 devauto/rps/hw/__init__.py
 create mode 100644 devauto/rps/hw/np0801dt.py
 create mode 100644 devauto/rps/hw/rpsgen.py
 create mode 100644 devauto/rps/rpscli.ini
 create mode 100755 devauto/rps/rpscli.py
 create mode 100644 devauto/rps/rpscontrol.py

diff --git a/devauto/rps/hw/__init__.py b/devauto/rps/hw/__init__.py
new file mode 100644
index 0000000..bc48067
--- /dev/null
+++ b/devauto/rps/hw/__init__.py
@@ -0,0 +1,6 @@
+"""Remote power switch hardware abstraction layer.
+
+Provides a hardware reference library for controlling the supported remote
+power switches.
+"""
+
diff --git a/devauto/rps/hw/np0801dt.py b/devauto/rps/hw/np0801dt.py
new file mode 100644
index 0000000..b1a456d
--- /dev/null
+++ b/devauto/rps/hw/np0801dt.py
@@ -0,0 +1,13 @@
+"""
+np0801dt Remote power switch control implementation
+
+At the time of the implementation, the reference website is:
+
+http://www.synaccess-net.com/np-0801dt/
+"""
+from rpsgen import RPSGen
+
+class np0801dt(RPSGen):
+    outlet_count=8
+    def __init__(self):
+        super(outlet_count)
diff --git a/devauto/rps/hw/rpsgen.py b/devauto/rps/hw/rpsgen.py
new file mode 100644
index 0000000..dea0119
--- /dev/null
+++ b/devauto/rps/hw/rpsgen.py
@@ -0,0 +1,23 @@
+"""
+Remote power switch hardware module for generalities.
+"""
+
+
+class RPSGen:
+    """
+    Remote power switch controller base class.
+
+    Defines the standard methods for coupling the main module to
+    the hardware.
+    """
+    def __init__(self, outlet_count):
+        self.outlet_count = outlet_count
+
+    def turn_all_on():
+        pass
+    def turn_all_off():
+        pass
+    def turn_on_by_id(outlet_id):
+        pass
+    def turn_off_by_id(outlet_id):
+        pass
diff --git a/devauto/rps/rpscli.ini b/devauto/rps/rpscli.ini
new file mode 100644
index 0000000..b30f5c0
--- /dev/null
+++ b/devauto/rps/rpscli.ini
@@ -0,0 +1,3 @@
+[rps_models]
+default=rpstest
+supported=np0801d,rpstest
diff --git a/devauto/rps/rpscli.py b/devauto/rps/rpscli.py
new file mode 100755
index 0000000..f433bb5
--- /dev/null
+++ b/devauto/rps/rpscli.py
@@ -0,0 +1,40 @@
+#!/usr/bin/env python3
+
+import sys
+
+if __name__ == "__main__":
+
+    import argparse
+
+    this_file_name = sys.argv[0].strip("./")
+    defaults_file = "".join([this_file_name.split('.')[-2], ".ini"])
+
+    parser_description="Remote power switch command line control interface"
+    parser_epilog="The file " + defaults_file \
+                    + " can be used to specify defaults"
+
+    parser = argparse.ArgumentParser(
+            description=parser_description,epilog=parser_epilog)
+
+    parser.add_argument('--all-on', action='store_true',
+                        help='turn all the outlets off')
+    parser.add_argument('--all-off', action='store_true',
+                        help='turn all the outlets on')
+    parser.add_argument('-o', '--on', action='store', dest='outlet_on',
+                        help='turn the specified outlet on')
+    parser.add_argument('-f', '--off', action='store', dest='outlet_off',
+                        help='turn the specified outlet off')
+    parser.add_argument('-r', '--read', action='store', dest='outlet_read',
+                        help='read the specified outlet status')
+    parser.add_argument('--all-read', action='store_true',
+                        help='read all the outlet status')
+    parser.add_argument('-m', '--model', dest='rps_model',
+                        help='specify the power switch model to use.\
+                        Overrides defaults from '+ defaults_file)
+    parser.add_argument('--models', action='store_true',
+                        help='list power switch supported models')
+
+    args = parser.parse_args()
+
+    # Debug comments
+    # print (args)
diff --git a/devauto/rps/rpscontrol.py b/devauto/rps/rpscontrol.py
new file mode 100644
index 0000000..aebd177
--- /dev/null
+++ b/devauto/rps/rpscontrol.py
@@ -0,0 +1,6 @@
+class RPSControl:
+    """
+    Remote power switch control class.
+    """
+    def __init__(self):
+        pass
-- 
2.5.5



More information about the automated-testing mailing list