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. 04166c62ae74


From: Rob Savoye
Subject: [Powerguru-commit] [SCM] powerguru branch, master, updated. 04166c62ae74d24349df87008b20a3c3d7a72dd2
Date: Thu, 21 Feb 2019 22:52:05 -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  04166c62ae74d24349df87008b20a3c3d7a72dd2 (commit)
       via  9e8883d000c3948c343e092a32544bfb754d0542 (commit)
       via  21035dd687d1bc17334bb0fcb23f7403b3e69718 (commit)
       via  4923591f4fd2000a688c16304c7b5028e23b5940 (commit)
       via  b5d520820c7907ecb474c8f7d82a36b0323cbe1a (commit)
       via  8d439b00e0765ca360c89cdfb6b7b60e0c7b531f (commit)
       via  037dbc8325b922b419a1a5af0cfcd74e93b6c111 (commit)
       via  973009ea239b5d8f306cd604e9a80b7885acc015 (commit)
      from  6ce531439265fdd504ca29b4511eea26e30a2a50 (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=04166c62ae74d24349df87008b20a3c3d7a72dd2


commit 04166c62ae74d24349df87008b20a3c3d7a72dd2
Author: Rob Savoye <address@hidden>
Date:   Thu Feb 21 20:51:49 2019 -0700

    Use pydoc style comments for GPLD block

diff --git a/python/postgresql.py b/python/postgresql.py
index d3ea6af..abc6dfb 100755
--- a/python/postgresql.py
+++ b/python/postgresql.py
@@ -1,21 +1,21 @@
 #!/usr/bin/python3
 
-# 
-#   Copyright (C) 2017, 2018, 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
-# 
+"""
+   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 glob
@@ -27,6 +27,14 @@ from options import CmdOptions
 
 class Postgresql(object):
     """A class to work with a postgresql database"""
+
+    def rowcount(self):
+        return self.dbcursor.rowcount
+
+    def fetchResult(self):
+        #return self.dbcursor.fetchall()
+        return self.result
+
     def __init__(self):
         self.options = CmdOptions()
         self.connect()
@@ -67,6 +75,7 @@ class Postgresql(object):
             logging.error("Database %r is not connected!" % 
self.options.get('database'))
             return self.result
 
+        self.result = list()
         self.dbcursor.execute(query)
         try:
             self.result = self.dbcursor.fetchall()
@@ -74,6 +83,7 @@ class Postgresql(object):
             if e.pgcode != None:
                 logging.error("Query failed to fetch! %r" % e.pgcode)
 
+        #epdb.set_trace()
         #logging.debug("Returned %r rows from query: %r" % 
(self.dbcursor.rowcount, self.dbcursor.statusmessage))
         #if self.dbcursor.rowcount is None:
         parsed = query.split(' ')

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


commit 9e8883d000c3948c343e092a32544bfb754d0542
Author: Rob Savoye <address@hidden>
Date:   Thu Feb 21 20:51:39 2019 -0700

    Use pydoc style comments for GPLD block

diff --git a/python/i2c.py b/python/i2c.py
index 588b28b..9409453 100644
--- a/python/i2c.py
+++ b/python/i2c.py
@@ -1,24 +1,23 @@
 #!/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
+"""
+   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 psycopg2
 from ina219 import INA219, DeviceRangeError
diff --git a/python/options.py b/python/options.py
index 2a28bd7..dcea4e0 100644
--- a/python/options.py
+++ b/python/options.py
@@ -1,21 +1,21 @@
 #!/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
-# 
+"""
+   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
@@ -28,12 +28,21 @@ 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."""
+
+    # Setup default command line options
+    options = dict()
+    helper = """\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'
+        """
+
     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
@@ -41,23 +50,24 @@ class CmdOptions(object):
         self.options['database'] = "powerguru"  # The database name
         self.options['verbosity'] = logging.ERROR
         self.processArgs(proc.cmdline[2:])
+        self.options['exec'] = os.path.basename(proc.cmdline[1])
 
-        # menu for --help
-    def usage(self):
+    def usage(self, more=""):
         """Display command line option usage"""
+        epdb.set_trace()
         #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']))
+        #    query += """\tStarttime: %s
+        #    \tEndtime: %s""" % (self.options['starttime'], 
self.options['endtime'])
+        foo = self.helper % (self.options['owserver'],
+        self.options['dbserver'],
+        self.options['database'],
+        self.options['interval'],
+        self.options['scale'])
+        if len(more) > 0:
+            print(foo.rstrip() + more)
+        else:
+            print(foo)
+        #print(self.help.rstrip() + more)
         quit()
 
     # Check command line arguments
@@ -66,13 +76,11 @@ class CmdOptions(object):
         internal data."""
         logging.debug("options.processArgs: %r" % args)
 
-        #epdb.set_trace()
-        #if len(args) == 0:
-        #    self.usage()
-        
+        # this is the full set of supported options by all the
+        # utility programs, pgd.py, chart.py. mergedb.py.
         try:
-            (opts, val) = getopt.getopt(args, "h,o:,i:,p:,d:,s:,v,",
-                        ["help", "owserver", "dbserver", "database", "scale", 
"interval", "verbosity"])
+            (opts, val) = getopt.getopt(args, "h,o:,i:,p:,d:,s:,v,t:,e:",
+                        ["help", "owserver", "dbserver", "database", "scale", 
"interval", "verbosity" "starttime", "endtime"])
         except getopt.GetoptError as e:
             logging.error('%r' % e)
             self.usage()
@@ -88,6 +96,10 @@ class CmdOptions(object):
             #print("%r: %r = %r" % (i, opt, val))
             if opt == '--help' or opt == '-h':
                 self.usage()
+            elif opt == "--starttime" or opt == '-t':
+                self.options['endtime'] = val
+            elif opt == "--endtime" or opt == '-e':
+                self.options['starttime'] = val
             elif opt == "--owserver" or opt == '-o':
                 self.options['owserver'] = val
             elif opt == "--interval" or opt == '-i':
diff --git a/python/pgd.py b/python/pgd.py
index 9978d68..3ec2925 100755
--- a/python/pgd.py
+++ b/python/pgd.py
@@ -1,22 +1,21 @@
 #!/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
-# 
-
+"""
+   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
diff --git a/python/weather.py b/python/weather.py
index 4eb8c92..1344258 100755
--- a/python/weather.py
+++ b/python/weather.py
@@ -1,23 +1,21 @@
 #!/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
-# 
+"""
+   Copyright (C) 2019 Free Software Foundation, Inc.
 
-# API documentation at: https://pyownet.readthedocs.io/en/latest/
+  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 sys
 import epdb

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


commit 21035dd687d1bc17334bb0fcb23f7403b3e69718
Author: Rob Savoye <address@hidden>
Date:   Thu Feb 21 20:51:04 2019 -0700

    Use pydoc style comments for GPLD block

diff --git a/python/gpio433.py b/python/gpio433.py
index a59dd28..1960afa 100755
--- a/python/gpio433.py
+++ b/python/gpio433.py
@@ -1,23 +1,21 @@
 #!/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/
+"""
+   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 sys
 import epdb
diff --git a/python/mergedb.py b/python/mergedb.py
index 2c0bbde..3643d5c 100755
--- a/python/mergedb.py
+++ b/python/mergedb.py
@@ -1,27 +1,21 @@
 #!/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/
-
-## \file mergedb.py
-# Simple script to merge logged data from a remote database to
-# local one.
+"""
+   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
diff --git a/python/triggers.py b/python/triggers.py
index 0d86b50..1b0545e 100644
--- a/python/triggers.py
+++ b/python/triggers.py
@@ -1,21 +1,21 @@
 #!/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
-# 
+"""
+   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
@@ -38,7 +38,10 @@ class triggerType(Enum):
     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' )
+    HOME_LEAVE = 9
+    HOME_ARRIVE = 10
+    ADD_FIREWOOD = 11
+triggerStrings = ('FIRE_STARTED', 'FIRE_OUT', 'DOOR_OPEN', 'DOOR_CLOSED', 
'WINDOW_OPEN', 'WINDOW_CLOSED', 'GENERIC', 'DEVICE_ON', 'DEVICE_OFF', 
'HOME_LEAVE', 'HOME_ARRIVE', 'ADD_FIREWOOD' )
 
 
 class Triggers(object):

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


commit 4923591f4fd2000a688c16304c7b5028e23b5940
Author: Rob Savoye <address@hidden>
Date:   Thu Feb 21 20:50:09 2019 -0700

    Use pydoc style comments for GPLD block

diff --git a/python/onewire.py b/python/onewire.py
index e5c26ee..ca8f4b6 100755
--- a/python/onewire.py
+++ b/python/onewire.py
@@ -1,21 +1,21 @@
 #!/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
-# 
+"""
+   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
diff --git a/python/ownet.py b/python/ownet.py
index f43360f..4f7168a 100755
--- a/python/ownet.py
+++ b/python/ownet.py
@@ -1,23 +1,23 @@
 #!/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
-# 
+"""
+   Copyright (C) 2019 Free Software Foundation, Inc.
 
-# API documentation at: https://pyownet.readthedocs.io/en/latest/
+  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 epdb
 import logging
diff --git a/python/remote.py b/python/remote.py
index c3d6c29..a3c139e 100644
--- a/python/remote.py
+++ b/python/remote.py
@@ -1,22 +1,21 @@
 #!/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
-# 
+"""
+   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
diff --git a/python/rtl433.py b/python/rtl433.py
index c36ca14..7b0a8ab 100755
--- a/python/rtl433.py
+++ b/python/rtl433.py
@@ -1,23 +1,21 @@
 #!/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
-# 
+"""
+   Copyright (C) 2019 Free Software Foundation, Inc.
 
-# API documentation at: https://pyownet.readthedocs.io/en/latest/
+  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 sys
 from subprocess import PIPE, Popen, STDOUT
diff --git a/python/rtlsdr.py b/python/rtlsdr.py
index 23d8946..259ce21 100755
--- a/python/rtlsdr.py
+++ b/python/rtlsdr.py
@@ -1,23 +1,21 @@
 #!/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
-# 
+"""
+   Copyright (C) 2019 Free Software Foundation, Inc.
 
-# API documentation at: https://pyownet.readthedocs.io/en/latest/
+  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

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


commit b5d520820c7907ecb474c8f7d82a36b0323cbe1a
Author: Rob Savoye <address@hidden>
Date:   Thu Feb 21 20:40:13 2019 -0700

    Use new postgresql and optionsclassed, make chart plotting  class

diff --git a/python/chart.py b/python/chart.py
index bbfa195..d28f00f 100755
--- a/python/chart.py
+++ b/python/chart.py
@@ -1,23 +1,21 @@
 #!/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
-# 
+"""
+   Copyright (C) 2019 Free Software Foundation, Inc.
 
-# API documentation at: https://pyownet.readthedocs.io/en/latest/
+  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
@@ -36,41 +34,10 @@ import getopt
 import sys
 from sys import argv
 import sensor
-
-# http://initd.org/psycopg/docs/
-
-options = dict()
-options['dbserver'] = "localhost"  # hostname of the database
-options['dbname'] = "powerguru"  # hostname of the database
-options['interval'] = 100        # interval in seconds between data updates
-options['starttime'] = ""
-options['endtime'] = ""
-
-#import matplotlib
-#matplotlib.use('agg')
-
-# menu for --help
-def usage(argv):
-    print(argv[0] + ": options: ")
-    print("""\t--help(-h)   Help
-    \t--dbserver(-s)    Database server [host]:port]], default '%s'
-    \t--database(-d)    Database on server, default '%s'
-    \t--interval(-i)    Interval for data updates, default '%s'
-    \t--starttime(-t)   Use timestanps after this, default begining of data
-    \t--endtime(-e)     Use timestanps after this, default end of data
-    \t--verbose(-v)     Enable verbosity
-    """ %  (options['dbserver'], options['dbname'],  options['interval'])
-    )
-    quit()
-
-# Check command line arguments
-try:
-    (opts, val) = getopt.getopt(argv[1:], "h,d:,s:,,v,i:,t:,e:",
-           ["help", "database", "dbserver", "verbose", "interval", 
"starttime", "endtime"])
-except getopt.GetoptError as e:
-    logging.error('%r' % e)
-    usage(argv)
-    quit()
+import mpld3
+from mpld3 import plugins
+from options import CmdOptions
+from postgresql import Postgresql
 
 # Setup a disk space log filemode. By default, everything
 # gets logged to the disk file
@@ -82,6 +49,31 @@ logging.basicConfig(
      datefmt='%Y-%m-%d %H:%M:%S'
 )
 
+#
+# Create local options class
+#
+class ChartOptions(CmdOptions):
+    """Command line options for this program"""
+
+    def __init__(self):
+        """Initialize additional command line options"""
+        super(ChartOptions, self).__init__()
+        self.options['starttime'] = ""
+        self.options['endtime'] = ""
+        self.options['web'] = False
+
+    def usage(self):
+        """Append additional help messages"""
+        print(argv[0] + ": options: ")
+        help = """
+        \t--starttime(-t)   Use timestanps after this, default begining of data
+        \t--endtime(-e)     Use timestanps after this, default end of data
+        \t--webpage(-w)     Enable HTML output for browser
+        """
+        super(ChartOptions, self).usage(help)
+
+opts = ChartOptions()
+
 # Setup console logging, useful for debugging
 # By default, print nothing to the console. There
 # re two versosity levels, the first just informational
@@ -93,78 +85,50 @@ formatter = logging.Formatter('%(message)s')
 #formatter = logging.Formatter('{%(filename)s:%(lineno)d} - %(message)s')
 ch.setFormatter(formatter)
 root.addHandler(ch)
-#terminator = ch.terminator
-verbosity = logging.CRITICAL
-
-# process command line arguments, will override the defaults
-for (opt, val) in opts:
-    if opt == '--help' or opt == '-h':
-        usage(argv)
-    elif opt == "--starttime" or opt == '-t':
-        options['starttime'] = val
-    elif opt == "--endtime" or opt == '-e':
-        options['endtime'] = val
-    elif opt == "--dbserver" or opt == '-s':
-        options['dbserver'] = val
-    elif opt == "--interval" or opt == '-i':
-        options['interval'] = val
-    elif opt == "--database" or opt == '-d':
-        options['dbname'] = val
-    elif opt == "--verbose" or opt == '-v':
-        if verbosity == logging.INFO:
-            verbosity = logging.DEBUG
-            formatter = logging.Formatter('{%(filename)s:%(lineno)d} 
%(levelname)s - %(message)s')
-            ch.setFormatter(formatter)
-        if verbosity == logging.CRITICAL:
-            verbosity = logging.INFO
+ch.setLevel(opts.get('verbosity'))
 
-ch.setLevel(verbosity)
+#opts.dump()
+#epdb.set_trace()
 
-delta = 0
-dbname = ""
-connect = ""
-if options['dbserver'] is "localhost":
-    connect += " dbname='" + options['dbname'] + "'"
-else:
-    connect += "host='" + options['dbserver'] + "'"
-    connect += " dbname='" + options['dbname'] + "'"
+# delta = 0
+# dbname = ""
+# connect = ""
+# if options['dbserver'] is "localhost":
+#     connect += " dbname='" + options['dbname'] + "'"
+# else:
+#     connect += "host='" + options['dbserver'] + "'"
+#     connect += " dbname='" + options['dbname'] + "'"
 
-logging.debug(connect)
-dbshell = psycopg2.connect(connect)
-if dbshell.closed != 0:
-    logging.error("Couldn't connect with %r" % connect)
-    quit();
+# logging.debug(connect)
+# dbshell = psycopg2.connect(connect)
+# if dbshell.closed != 0:
+#     logging.error("Couldn't connect with %r" % connect)
+#     quit();
 
-dbshell.autocommit = True
-logging.info("Opened connection to %r" % options['dbserver'])
+# dbshell.autocommit = True
+# logging.info("Opened connection to %r" % options['dbserver'])
 
-dbcursor = dbshell.cursor()
-if dbcursor.closed != 0:
-    logging.error("Couldn't get a cursor from %r" % options['dbname'])
-    quit();
+# dbcursor = dbshell.cursor()
+# if dbcursor.closed != 0:
+#     logging.error("Couldn't get a cursor from %r" % options['dbname'])
+#     quit();
 
-logging.info("Opened cursor in %r" % options['dbserver'])
+# logging.info("Opened cursor in %r" % options['dbserver'])
 
 # Get the data on each sensor
 sensors = sensor.Sensors()
 
+db = Postgresql()
+
 # Setup optional timestamp filter
 start = ""
 end = ""
-if options['starttime'] != "":
-    start = "AND timestamp>=%r" % options['starttime']
-elif options['endtime'] != "" and options['starttime'] != "":
-    end = " AND timestamp<=%r" % options['endtime']
-    if options['endtime'] != "" and options['starttime'] == "":
-        end = " AND timestamp<=%r" % options['endtime']
-
-# Create the subslots
-fig, (temp) = plt.subplots(1, 1, sharex=True)
-#fig, (temp, humidity) = plt.subplots(2, 1, sharex=True)
-#fig, (temp, dcvolts, amps) = plt.subplots(3, 1, sharex=True)
-plt.subplots_adjust(top=0.88, bottom=0.20, left=0.10, right=0.95, hspace=0.58,
-                    wspace=0.35)
-
+if opts.get('starttime') != "":
+    start = "AND timestamp>=%r" % opts.get('starttime')
+elif opts.get('endtime') != "" and opts.get('starttime') != "":
+    end = " AND timestamp<=%r" % opts.get('endtime')
+    if opts.get('endtime') != "" and opts.get('starttime') == "":
+        end = " AND timestamp<=%r" % opts.get('endtime')
 
 # https://matplotlib.org/gallery/color/named_colors.html
 colors = list()
@@ -181,48 +145,54 @@ colors.append("purple")
 colors.append("grey")
 colors.append("navy")
 
-def animate(i):
-    logging.debug("Refreshing data...")
-    ids = list()
-    query = "SELECT DISTINCT id FROM weather"
-    logging.debug(query)
-    dbcursor.execute(query)
-    logging.debug("Query returned %r records" % dbcursor.rowcount)
-    for id in dbcursor:
-        print("ID: %r" % id)
-        ids.append(id)
+# Create the subslots
+fig, (temp) = plt.subplots(1, 1, sharex=True)
+#fig, (temp, humidity) = plt.subplots(2, 1, sharex=True)
+#fig, (temp, dcvolts, amps) = plt.subplots(3, 1, sharex=True)
+#plt.subplots_adjust(top=0.88, bottom=0.20, left=0.10, right=0.95, 
hspace=0.58,wspace=0.35)
 
-    cur = 0
-    for id in ids:
-        query = "SELECT id,temperature,humidity,timestamp FROM weather WHERE 
(id='%s' %s %s) ORDER BY timestamp;" % (id[0], start, end)
-        logging.debug(query)
-        dbcursor.execute(query)
-        logging.debug("Query returned %r records" % dbcursor.rowcount)
+#fig, (temp) = plt.subplots(1, 1, sharex=True)
+fig.suptitle('PowerGuru')
+fig.set_figwidth(18)
 
-        x = list()
-        y = list()
-        for model,temperature,humidity,timestamp in dbcursor:
-            #print("TEMP: %r, %r" % (temperature,timestamp))
-            x.append(timestamp)
-            y.append(temperature)
+class plotTemps(object):
+    """Class to create a plot of temperatures"""
 
-        #sensors.dump()
-        #epdb.set_trace()
-        sense = sensors.get(id[0])
-        if sense != None:
-            location = sense.get('location')
-        else:
-            location = id[0]
-        fig.suptitle('PowerGuru')
-        temp.set_ylabel("Temperature in F")
-        temp.set_title("Temperature")
-        temp.grid(which='major', color='red')
-        temp.grid(which='minor', color='blue', linestyle='dashed')
-        temp.minorticks_on()
-        legend = temp.legend(loc='upper left', shadow=True)
-        temp.plot(x, y, color=colors[cur], label=location)
-        cur += 1
+    def __init__(self):
+        cur = 0
+        temp = plt.subplot()
+        for id in sensors.getIDs(sensor.SensorType.TEMPERATURE):
+            x = list()
+            y = list()
+            query = "SELECT id,temperature,humidity,timestamp FROM weather 
WHERE (id='%s' %s %s) ORDER BY timestamp;" % (id, start, end)
+            logging.debug(query)
+            db.query(query)
+            logging.debug("Query returned %r records" % db.rowcount())
 
+            for model,temperature,humidity,timestamp in db.fetchResult():
+                #print("TEMP: %r, %r" % (temperature,timestamp))
+                x.append(timestamp)
+                y.append(temperature)
+
+            #sensors.dump()
+            temp.set_ylabel("Temperature in F")
+            temp.set_title("Temperature")
+            temp.grid(which='major', color='red')
+            temp.grid(which='minor', color='blue', linestyle='dashed')
+            temp.minorticks_on()
+            legend = temp.legend(loc='upper left', shadow=True)
+            sense = sensors.get(id)
+            if sense != None:
+                location = sense.get('location')
+            else:
+                location = id
+            temp.plot(x, y, color=colors[cur], label=location)
+            cur += 1
+
+
+def animate(i):
+    logging.debug("Refreshing data...")
+    tplot = plotTemps()
     # xx = list()
     # yy = list()
     # zz = list()
@@ -270,14 +240,17 @@ def animate(i):
     # Get the time delta between data samples, as it's not worth updating there
     # the display till their in fresh data. Sample may be minutes or hours 
apart,
     # so o need to waste cpu cycles
-    query = "SELECT AGE(%r::timestamp, %r::timestamp);" % 
(x[1].strftime("%Y-%m-%d %H:%M:%S"), x[0].strftime("%Y-%m-%d %H:%M:%S"))
-    logging.debug(query)
-    dbcursor.execute(query)
-    delta = (dbcursor.fetchall())[0][0].total_seconds()
-    logging.debug("Query returned %r" % delta)
-    
+    #query = "SELECT AGE(%r::timestamp, %r::timestamp);" % 
(x[1].strftime("%Y-%m-%d %H:%M:%S"), x[0].strftime("%Y-%m-%d %H:%M:%S"))
+    #logging.debug(query)
+    #db.query(query)
+    #delta = (db.fetchResult())[0][0].total_seconds()
+    #logging.debug("Query returned %r" % delta)
+
 # The timeout is in miliseconds
 #seconds = 1000 * delta
-seconds = 1000 * options['interval']
+seconds = 1000 * opts.get('interval')
 ani = animation.FuncAnimation(fig, animate, interval=seconds)
-plt.show()
+if opts.get('web') is True:
+    mpld3.show(port=9999, open_browser=False)
+else:
+    plt.show()

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


commit 8d439b00e0765ca360c89cdfb6b7b60e0c7b531f
Author: Rob Savoye <address@hidden>
Date:   Thu Feb 21 20:36:28 2019 -0700

    Add CLEANFILES

diff --git a/python/Makefile.am b/python/Makefile.am
index efc8977..dfd7a1c 100644
--- a/python/Makefile.am
+++ b/python/Makefile.am
@@ -19,11 +19,17 @@
 
 AUTOMAKE_OPTIONS = 
 
-python_PYTHON = mergedb.py onewire.py ownet.py chart.py pgd.py
+APPS = mergedb.py chart.py pgd.py
+python_PYTHON =  onewire.py ownet.py setup.py $(APPS)
+EXTRA_DIST = requirements.txt
 
 install-exec-local:
+       @echo $(srcdir)
+       @echo $(top_srcdir)
        $(mkinstalldirs) $(DESTDIR)$(pkgpythondir)
        $(PYTHON) $(srcdir)/setup.py install \
        --prefix $(DESTDIR)$(prefix) \
        --record $(DESTDIR)$(pkgpythondir)/install_files.txt \
        --verbose
+       $(mkinstalldirs) $(prefix)/bin
+       $(INSTALL_SCRIPT) $(APPS) $(prefix)/bin

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


commit 037dbc8325b922b419a1a5af0cfcd74e93b6c111
Author: Rob Savoye <address@hidden>
Date:   Thu Feb 21 20:31:40 2019 -0700

    convert SQL types to python enums

diff --git a/python/sensor.py b/python/sensor.py
index 6e516d5..d688bf3 100755
--- a/python/sensor.py
+++ b/python/sensor.py
@@ -37,9 +37,9 @@ class SensorType(Enum):
     POWER = 5
     CLOCK = 6
     TEMPERATURE = 7
-    MOISTURE = 8
+    HUMIDITY = 8
     UNSUPPORTED = 9
-sensorStrings= ('UNKNOWN', 'ACVOLTAGE', 'DCVOLTAGE', 'AUTH', 'BATTERY', 
'POWER', 'CLOCK', 'TEMPERATURE', 'MOISTURE', 'UNSUPPORTED' )
+sensorStrings= ('UNKNOWN', 'ACVOLTAGE', 'DCVOLTAGE', 'AUTH', 'BATTERY', 
'POWER', 'CLOCK', 'TEMPERATURE', 'HUMIDITY', 'UNSUPPORTED' )
 
 # Types of devices. These enums and their string values must match
 # the database schema's enum. See powerguru.sql for details.
@@ -65,8 +65,10 @@ class Sensors(object):
         # Get any existing sensor data
         query = """SELECT * FROM sensors;"""
         logging.debug(query)
-        result = self.db.query(query)
-        logging.debug("Got %r sensor records: %r" % (self.db.rowcount, 
len(result)))
+        self.db.query(query)
+        result = self.db.fetchResult()
+
+        logging.debug("Got %r sensor records: %r" % (self.db.rowcount(), 
len(result)))
         for id,alias,location,device,sense,channel in result:
             data = dict()
             if id is not None:
@@ -78,7 +80,27 @@ class Sensors(object):
             if device is not None:
                 data['device'] = device
             if sense is not None:
-                data['sensor'] = sense
+                #('UNKNOWN'=0, 'ACVOLTAGE'=1, 'DCVOLTAGE'=2, 'AUTH'=3, 
'BATTERY'=4, 'POWER'=5, 'CLOCK'=6, 'TEMPERATURE'=7, 'HUMIDITY'=8, 
'UNSUPPORTED'=9)
+                if sense == "TEMPERATURE":
+                    data['sensor'] = SensorType.TEMPERATURE
+                elif sense == "UNKNOWN":
+                    data['sensor'] = SensorType.UNKNOWN
+                elif sense == "POWER":
+                    data['sensor'] = SensorType.POWER
+                elif sense == "BATTERY":
+                    data['sensor'] = SensorType.BATTERY
+                elif sense == "AUTH":
+                    data['sensor'] = SensorType.AUTH
+                elif sense == "CLOCK":
+                    data['sensor'] = SensorType.CLOCK
+                elif sense == "UNSUPPORTED":
+                    data['sensor'] = SensorType.UNSUPPORTED
+                elif sense == "HUMIDITY":
+                    data['sensor'] = SensorType.HUMIDITY
+                elif sense == "ACVOLTAGE":
+                    data['sensor'] = SensorType.ACVOLTAGE
+                elif sense == "DCVOLTAGE":
+                    data['sensor'] = SensorType.DCVOLTAGE
             if channel is not None:
                 data['channel'] = channel
             self.sensors[id] = SensorDevice(data)
@@ -89,6 +111,15 @@ class Sensors(object):
             xml += sensor.makeXML()
         return xml
 
+    def getIDs(self, stype=SensorType.UNKNOWN, result=list()):
+        result.clear()
+        for id,sensor in self.sensors.items():
+            if type != None:
+                if sensor.get('sensor') == stype:
+                    result.append(id)
+        logging.debug("sensor.getIDs(%r entries)" % len(result))
+        return result
+
     def dump(self, result=""):
         logging.debug("Sensor.dump(%r entries)" % len(self.sensors))
         for id,sensor in self.sensors.items():

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


commit 973009ea239b5d8f306cd604e9a80b7885acc015
Author: Rob Savoye <address@hidden>
Date:   Thu Feb 21 12:12:11 2019 -0700

    Use new Ppstgresql class.

diff --git a/python/sensor.py b/python/sensor.py
index 03f74de..6e516d5 100755
--- a/python/sensor.py
+++ b/python/sensor.py
@@ -1,23 +1,21 @@
 #!/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/
+"""
+   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 sys
 import epdb
@@ -25,6 +23,8 @@ import logging
 import psycopg2
 from datetime import datetime
 from enum import Enum
+from postgresql import Postgresql
+
 
 # Types of sensors. These enums and their string values must match
 # the database schema's enum. See powerguru.sql for details.
@@ -58,29 +58,16 @@ deviceStrings = ('UNNOWN', 'ONEWIRE', 'OWNET', 'RTL433', 
'RTLSDR', 'USB', 'SERIA
 class Sensors(object):
     """Data about all the sensors"""
     def __init__(self, data=dict()):
+        self.active = False
         self.sensors = dict()
-        # Connect to a postgresql database
-        try:
-            dbname = "powerguru"
-            connect = "dbname=" + dbname
-            self.dbshell = psycopg2.connect(connect)
-            if self.dbshell.closed == 0:
-                self.dbshell.autocommit = True
-                logging.info("Opened connection to %r" % dbname)
-
-            self.dbcursor = self.dbshell.cursor()
-            if self.dbcursor.closed == 0:
-                logging.info("Opened cursor in %r" % dbname)
-
-        except Exception as e:
-            logging.warning("Couldn't connect to database: %r" % e)
+        self.db = Postgresql()
 
         # Get any existing sensor data
         query = """SELECT * FROM sensors;"""
         logging.debug(query)
-        self.dbcursor.execute(query)
-        logging.debug("Got %r sensor records" % self.dbcursor.rowcount)
-        for id,alias,location,device,sense,channel in self.dbcursor:
+        result = self.db.query(query)
+        logging.debug("Got %r sensor records: %r" % (self.db.rowcount, 
len(result)))
+        for id,alias,location,device,sense,channel in result:
             data = dict()
             if id is not None:
                 data['id'] = id

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

Summary of changes:
 python/Makefile.am   |   8 +-
 python/chart.py      | 287 +++++++++++++++++++++++----------------------------
 python/gpio433.py    |  34 +++---
 python/i2c.py        |  37 ++++---
 python/mergedb.py    |  38 +++----
 python/onewire.py    |  32 +++---
 python/options.py    |  90 +++++++++-------
 python/ownet.py      |  34 +++---
 python/pgd.py        |  33 +++---
 python/postgresql.py |  42 +++++---
 python/remote.py     |  31 +++---
 python/rtl433.py     |  32 +++---
 python/rtlsdr.py     |  32 +++---
 python/sensor.py     |  96 ++++++++++-------
 python/triggers.py   |  37 ++++---
 python/weather.py    |  32 +++---
 16 files changed, 450 insertions(+), 445 deletions(-)


hooks/post-receive
-- 
powerguru



reply via email to

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