summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--driver.py67
-rw-r--r--drivers/__init__.py (renamed from driver/__init__.py)0
-rw-r--r--drivers/optiups.py (renamed from driver/optiups.py)5
-rw-r--r--main.py2
4 files changed, 73 insertions, 1 deletions
diff --git a/driver.py b/driver.py
new file mode 100644
index 0000000..357c959
--- /dev/null
+++ b/driver.py
@@ -0,0 +1,67 @@
+#!/usr/bin/python
+
+""" oopsd example driver """
+
+class DriverError(IOError):
+ """ All driver-specific errors subclass this exception """
+ pass
+
+class ConnectionError(DriverError):
+ """ Raised when connection to the UPS fails """
+ pass
+
+class DataError(DriverError):
+ """ Raised when the received data is in a wrong format """
+ pass
+
+class Driver:
+ def __init__(self, globalconf, drvconf):
+ """ Do lowlevel initialisation here. Read port from globalconf, etc.
+ """
+ raise NotImplementedError
+
+ def initups(self):
+ """ Initialize the UPS connection, raise ConnectionError if UPS hasn't
+ been found
+ """
+ raise NotImplementedError
+
+ def poll(self):
+ """ Get the newest data from the UPS and save it internally somewhere.
+ """
+ raise NotImplementedError
+
+ def getdata(self):
+ """ Return a dictionary which must look like this, based on previously
+ latched data:
+
+ {
+ 'data': {
+ 'input' {
+ 'voltage': 230, # volt
+ 'frequency': 50 # hertz
+ },
+ 'output' {
+ 'voltage': 230, # volt
+ 'frequency': 50 # hertz
+ }
+ },
+ 'flags': {
+ 'OL': True,
+ 'OB': False,
+ 'LB': False,
+ 'RB': False,
+ 'CHRG': True,
+ 'DISCHRG': False,
+ 'BYPASS': False,
+ 'CAL': False,
+ 'OFF': False,
+ 'OVER': False,
+ 'TRIM': False,
+ 'BOOST': False
+ }
+ }
+
+ You can add more information as needed, or remove values the given UPS
+ does not support. """
+ raise NotImplementedError
diff --git a/driver/__init__.py b/drivers/__init__.py
index e69de29..e69de29 100644
--- a/driver/__init__.py
+++ b/drivers/__init__.py
diff --git a/driver/optiups.py b/drivers/optiups.py
index d90bc9b..5bb7125 100644
--- a/driver/optiups.py
+++ b/drivers/optiups.py
@@ -16,3 +16,8 @@
# You should have received a copy of the GNU General Public License
# along with oopsd. If not, see <http://www.gnu.org/licenses/>.
+import driver
+
+class Driver(driver.Driver):
+ def __init__(self, globalconf, drvconf):
+ print("Ohai")
diff --git a/main.py b/main.py
index 62d856e..62bd50b 100644
--- a/main.py
+++ b/main.py
@@ -22,7 +22,7 @@ def main():
loaddriver('optiups')
def loaddriver(name):
- __import__('.'.join(['driver', name]))
+ __import__('.'.join(['drivers', name]))
if __name__ == '__main__':
sys.exit(main())