powerguru-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Powerguru-commit] [SCM] powerguru branch, master, updated. 6ce531439265


From: Rob Savoye
Subject: [Powerguru-commit] [SCM] powerguru branch, master, updated. 6ce531439265fdd504ca29b4511eea26e30a2a50
Date: Tue, 19 Feb 2019 14:52:47 -0500 (EST)

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "powerguru".

The branch, master has been updated
       via  6ce531439265fdd504ca29b4511eea26e30a2a50 (commit)
       via  3f731fef5d11923985f03b1181fc61f8cae3b695 (commit)
       via  b493a43662e1be9d58fe03d79a7584b868abb09a (commit)
      from  894b685aa8c34fdc4e18c0df36104c80613aa3ab (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://git.savannah.gnu.org/cgit/powerguru.git/commit/?id=6ce531439265fdd504ca29b4511eea26e30a2a50


commit 6ce531439265fdd504ca29b4511eea26e30a2a50
Author: Rob Savoye <address@hidden>
Date:   Tue Feb 19 12:52:32 2019 -0700

    Add comments for pydoc

diff --git a/python/ownet.py b/python/ownet.py
index 9aa20ad..f43360f 100755
--- a/python/ownet.py
+++ b/python/ownet.py
@@ -31,6 +31,8 @@ from postgresql import Postgresql
 
 
 def ownet_handler(sensors):
+    """Handler for the owserver protocol. This connects to a local
+    or remote owserver."""
     logging.debug("Start ownet...")
 
     options = CmdOptions()
diff --git a/python/postgresql.py b/python/postgresql.py
index 7d9dec9..d3ea6af 100755
--- a/python/postgresql.py
+++ b/python/postgresql.py
@@ -33,7 +33,7 @@ class Postgresql(object):
         self.result = ""
 
     def connect(self):
-        """Connect to a postgresql server"""
+        """Connect to a local or remote postgresql server"""
 
         # Supported parameters for connect are: 
         # *database*: the database name (only as keyword argument)
@@ -59,7 +59,7 @@ class Postgresql(object):
                 logging.info("Opened cursor in %r %r" % (database, 
self.dbcursor))
 
     def query(self, query):
-        """Query a postgresql database"""
+        """Query a local or remote postgresql database"""
 
         logging.debug("postgresql.query(" + query + ")")
         #epdb.set_trace()
@@ -88,12 +88,14 @@ class Postgresql(object):
         return self.result
 
     def isConnected(self):
+        """Test to see if there is a working database connection"""
         if self.dbshell.closed == 0:
             return True
         else:
             return False
 
     def dump(self):
+        """Display all internal data"""
         print("Dumping data from postgresql class")
         print("\tDB server: %r" % self.options.get('dbserver'))
         print("\tDatabase: %r" % self.options.get('database'))
diff --git a/python/rtl433.py b/python/rtl433.py
index d3a7a1d..c36ca14 100755
--- a/python/rtl433.py
+++ b/python/rtl433.py
@@ -34,6 +34,9 @@ from postgresql import Postgresql
 ON_POSIX = 'posix' in sys.builtin_module_names
 
 def rtl433_handler(sensors):
+    """This is a handler for sensors using wireless at 433Mhz,
+    commonly used by many wireless weather sensors. This requires
+    a working RTL-SDR radio dongle, and the rtl_433 utiity installed"""
     logging.debug("Start rtl_433...")
 
     options = CmdOptions()
@@ -48,7 +51,7 @@ def rtl433_handler(sensors):
         #out, err = ppp.communicate(timeout=0.5)
         #print("FIXME0: %r" % out)
         for line in out.splitlines():
-            mapper = map
+            #mapper = map
             #for line in ppp.readline():
             #print("FIXME: %r" % line)
             str = line.decode('utf8')

http://git.savannah.gnu.org/cgit/powerguru.git/commit/?id=3f731fef5d11923985f03b1181fc61f8cae3b695


commit 3f731fef5d11923985f03b1181fc61f8cae3b695
Author: Rob Savoye <address@hidden>
Date:   Tue Feb 19 12:51:23 2019 -0700

    New class for handling command line optionsoptions.py

diff --git a/python/options.py b/python/options.py
new file mode 100644
index 0000000..2a28bd7
--- /dev/null
+++ b/python/options.py
@@ -0,0 +1,131 @@
+#!/usr/bin/python3
+
+# 
+#   Copyright (C) 2019 Free Software Foundation, Inc.
+# 
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+# 
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+# 
+
+import epdb
+import logging
+import getopt
+import sys
+import os
+from proc.core import Process
+
+
+class CmdOptions(object):
+    """This class handles command line options between threads in
+    a thread-safe way by using the /proc filesystem read-only."""
+    def __init__(self):
+        """Read the command line option from /proc/PID/cmdline"""
+        proc = Process.from_path('/proc/self')
+        self.options = dict()
+        # Setup default command line options
+        self.options = dict()
+        self.options['interval'] = 300  # time interval to delay when polling 
for data
+        self.options['owserver'] = "localhost"  # hostname of the owserver
+        self.options['dbserver'] = "localhost"  # hostname of the database
+        self.options['scale'] = "F"             # The scale, 'C' or 'F'
+        self.options['database'] = "powerguru"  # The database name
+        self.options['verbosity'] = logging.ERROR
+        self.processArgs(proc.cmdline[2:])
+
+        # menu for --help
+    def usage(self):
+        """Display command line option usage"""
+        #print(argv[0] + ": self.options: ")
+        print("""\t--help(-h)   Help
+        \t--owserver(-o)    OW server [host[:port]], default '%s'
+        \t--dbserver(-p)    Database server [host]:port]], default '%s'
+        \t--database(-d)    Database name, default '%s'
+        \t--interval(-i)    Set the time interval for device polling, default 
'%s'
+        \t--verbose(-v)     Enable verbosity
+        \t--scale(-s)       Set the temperature scale, 'F' or 'C', default '%s'
+        """ % (self.options['owserver'],
+               self.options['dbserver'],
+               self.options['database'],
+               self.options['interval'],
+               self.options['scale']))
+        quit()
+
+    # Check command line arguments
+    def processArgs(self, args):
+        """Process the list of command line arguments into
+        internal data."""
+        logging.debug("options.processArgs: %r" % args)
+
+        #epdb.set_trace()
+        #if len(args) == 0:
+        #    self.usage()
+        
+        try:
+            (opts, val) = getopt.getopt(args, "h,o:,i:,p:,d:,s:,v,",
+                        ["help", "owserver", "dbserver", "database", "scale", 
"interval", "verbosity"])
+        except getopt.GetoptError as e:
+            logging.error('%r' % e)
+            self.usage()
+
+        # process command line arguments, will override the defaults
+        i = 0
+        while i < len(args):
+            opt = args[i]
+            try:
+                val = args[i + 1]
+            except:
+                val = ""
+            #print("%r: %r = %r" % (i, opt, val))
+            if opt == '--help' or opt == '-h':
+                self.usage()
+            elif opt == "--owserver" or opt == '-o':
+                self.options['owserver'] = val
+            elif opt == "--interval" or opt == '-i':
+                self.options['interval'] = int(val)
+            elif opt == "--dbserver" or opt == '-p':
+                self.options['dbserver'] = val
+            elif opt == "--database" or opt == '-d':
+                self.options['database'] = val
+            elif opt == "--verbose" or opt == '-v':
+                #print("VERBOSITY: %r %r" % (self.options['verbosity'], val))
+                #epdb.set_trace()
+                if self.options['verbosity'] is logging.ERROR:
+                    self.options['verbosity'] = logging.INFO
+                elif self.options['verbosity'] is logging.INFO:
+                    self.options['verbosity'] = logging.DEBUG
+                i = i + 1
+                continue
+            i = i + 2
+
+    def set(self, key, value=""):
+        """Set the value of a command line option."""
+        self.options[key] = value
+
+    def get(self, key):
+        """Get the value of a command line option."""
+        return self.options[key]
+
+    def dump(self):
+        """Display all the internal option data"""
+        for key,value in self.options.items():
+            if key == 'verbosity':
+                if value == logging.INFO:
+                    print("%r = logging.INFO" % (key.capitalize()))
+                elif value == logging.CRITICAL:
+                    print("%r = logging.CRITICAL" % (key.capitalize()))
+                elif value == logging.ERROR:
+                    print("%r = logging.ERROR" % (key.capitalize()))
+                elif value == logging.DEBUG:
+                    print("%r = logging.DEBUG" % (key.capitalize()))
+            else:
+                print("%r = %r" % (key.capitalize(), value))
diff --git a/python/triggers.py b/python/triggers.py
new file mode 100644
index 0000000..0d86b50
--- /dev/null
+++ b/python/triggers.py
@@ -0,0 +1,110 @@
+#!/usr/bin/python3
+
+# 
+#   Copyright (C) 2019 Free Software Foundation, Inc.
+# 
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+# 
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+# 
+
+import epdb
+import logging
+from lxml import etree
+from lxml.etree import tostring
+from enum import Enum
+from datetime import datetime
+import psycopg2
+
+
+# Types of events. These enums and their string values must match
+# the database schema's enum. See powerguru.sql for details.
+class triggerType(Enum):
+    FIRE_STARTED = 0
+    FIRE_OUT = 1
+    DOOR_OPEN = 2
+    DOOR_CLOSED = 3
+    WINDOW_OPEN = 4
+    WINDOW_CLOSED = 5
+    GENERIC = 6
+    DEVICE_ON = 7
+    DEVICE_OFF = 8
+triggerStrings = ('FIRE_STARTED', 'FIRE_OUT', 'DOOR_OPEN', 'DOOR_CLOSED', 
'WINDOW_OPEN', 'WINDOW_CLOSED', 'GENERIC', 'DEVICE_ON', 'DEVICE_OFF' )
+
+
+class Triggers(object):
+    """Handle events"""
+
+    def __init__(self):
+        self.data = dict()
+        self.data['id'] = ""
+        self.data['name'] = ""
+        self.data['trigger'] = triggerType.GENERIC
+        # Note tha this uses the timestamp from when this class
+        # is instantiated, and should letter be overwritten
+        # when the instantiated object is upated with a new event
+        self.data['timestamp'] = datetime.now()
+
+        dbname = ""
+        connect = ""
+        if options['dbserver'] is "localhost":
+            connect += " dbname='" + options['dbname'] + "'"
+        else:
+            connect += "host='" + options['dbserver'] + "'"
+            connect += " dbname='" + options['dbname'] + "'"
+            
+            logging.debug(connect)
+            shelf.dbshell = psycopg2.connect(connect)
+            if self.dbshell.closed != 0:
+                logging.error("Couldn't connect with %r" % connect)
+                quit();
+                
+                self.dbshell.autocommit = True
+                logging.info("Opened connection to %r" % options['dbserver'])
+
+                self.dbcursor = self.dbshell.cursor()
+                if self.dbcursor.closed != 0:
+                    logging.error("Couldn't get a cursor from %r" % 
options['dbname'])
+                    quit();
+
+                logging.info("Opened cursor in %r" % options['dbserver'])
+
+    def set(self, key, value=""):
+        self.data[key] = value
+
+    def get(self, key):
+        return self.data[key]
+
+    def writeSQL(self, sql=""):
+        if sql is None:
+            querying = self.makeSQL(sql)
+        logging.debug(query)
+        self.dbcursor.execute(query)
+
+    def makeSQL(self, sql=""):
+        timestamp = datetime.now()
+        sql = """INSERT INTO events VALUES (%r, %r, %r, %r)""" % 
(self.data['id'], self.data['name'], self.data['trigger'], 
self.data['timestamp'].strftime("%Y-%m-%d %H:%M:%S"))
+        return sql
+
+    def fromXML(self, xml):
+        logging.debug("fromXML: %r" % xml)
+        if len(xml) > 0:
+            logging.debug("Has chidren")
+            for child in xml:
+                self.data[child.tag.lower()] = child.text
+
+    def dump(self):
+        print("ID: %r" % self.data['id'])
+        print("Name: %r" % self.data['name'])
+        print("Trigger: %r" % self.data['trigger'])
+        print("Timestamp: %r" % self.data['timestamp'].strftime("%Y-%m-%d 
%H:%M:%S"))
+
diff --git a/python/weather.py b/python/weather.py
new file mode 100755
index 0000000..4eb8c92
--- /dev/null
+++ b/python/weather.py
@@ -0,0 +1,38 @@
+#!/usr/bin/python3
+
+# 
+#   Copyright (C) 2019 Free Software Foundation, Inc.
+# 
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+# 
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+# 
+
+# API documentation at: https://pyownet.readthedocs.io/en/latest/
+
+import sys
+import epdb
+import logging
+import psycopg2
+from datetime import datetime
+
+
+class Weather(object):
+    def __init__(self, argv=list()):
+        """A class to hold weather sensor data"""
+        self.id = 0
+        self.temperature = 0
+        self.temphigh = 0
+        self.templow = 0
+        self.humidity = 0
+        self.scale = 'C'
+        self.timestamp = 0

http://git.savannah.gnu.org/cgit/powerguru.git/commit/?id=b493a43662e1be9d58fe03d79a7584b868abb09a


commit b493a43662e1be9d58fe03d79a7584b868abb09a
Author: Rob Savoye <address@hidden>
Date:   Tue Feb 19 12:33:39 2019 -0700

    Generated using pipreqs

diff --git a/python/requirements.txt b/python/requirements.txt
index 16944e8..70d7a9f 100644
--- a/python/requirements.txt
+++ b/python/requirements.txt
@@ -1,7 +1,8 @@
-subprocess
-psycopg2
-logging
-glob
-pyownet
-pyowfs
-matplotlib
+matplotlib==2.2.2
+pyownet==0.10.0
+proc==0.17
+numpy==1.14.5
+pi_ina219==1.2.0
+psycopg2==2.7.5
+lxml==4.2.5
+epdb==0.15.1

-----------------------------------------------------------------------

Summary of changes:
 python/options.py                | 131 +++++++++++++++++++++++++++++++++++++++
 python/ownet.py                  |   2 +
 python/postgresql.py             |   6 +-
 python/requirements.txt          |  15 ++---
 python/rtl433.py                 |   5 +-
 python/triggers.py               | 110 ++++++++++++++++++++++++++++++++
 python/{rtlsdr.py => weather.py} |  27 ++++----
 7 files changed, 273 insertions(+), 23 deletions(-)
 create mode 100644 python/options.py
 create mode 100644 python/triggers.py
 copy python/{rtlsdr.py => weather.py} (70%)


hooks/post-receive
-- 
powerguru



reply via email to

[Prev in Thread] Current Thread [Next in Thread]