Merge pull request #4 from evanrich/priceinfo

Add Price info  This closes #4
This commit is contained in:
2018-09-08 14:00:57 -07:00
committed by GitHub
8 changed files with 35 additions and 20 deletions

View File

@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#===========================================================================
#
@@ -17,9 +17,9 @@ messages.
"""
import argparse
import bottle as B
import sys
import json
import bottle as B
import tHome as T
#===========================================================================
@@ -41,6 +41,15 @@ def instant( client, data, cfg ):
return ( cfg.mqttPower, msg )
#===========================================================================
def price( client, data, cfg ):
msg = {
"time" : data.TimeUnix,
"price" : data.Price,
"tier" : data.Tier,
}
return ( cfg.mqttPrice, msg )
#===========================================================================
handlers = {
#"BlockPriceDetail" :
@@ -51,7 +60,7 @@ handlers = {
#"MessageCluster" :
#"MeterInfo" :
#"NetworkInfo" :
#"PriceCluster" :
"PriceCluster" : price,
#"Reading" :
#"ScheduleInfo" :
#"TimeCluster" :

View File

@@ -6,7 +6,7 @@ import os
#
#===========================================================================
host = os.getenv('MQTT_BROKER_IP', '192.168.1.20')
port = os.getenv('MQTT_BROKER_PORT', 1883)
port = os.getenv('MQTT_BROKER_PORT', 31333)
# Keep alive time in seconds. Client sends a ping if no other message
# is sent in this interval.

View File

@@ -17,6 +17,12 @@ mqttEnergy = 'power/elec/Home/energy'
# Instantaneous power usage topic (reports power usage in W)
mqttPower = 'power/elec/Home/power'
#Current price topic (returns current price of electricity from meter)
mqttPrice = 'power/elec/Home/price'
#Current rate label (returns rate label from meter)
mqttRateLabel = 'power/elec/Home/ratelabel'
#===========================================================================
#
# Logging configuration. Env variables are allowed in the file name.

View File

@@ -3,4 +3,4 @@
import tHome as T
d = T.config.parse( "/home/ted/proj/tHome/conf" )
print d
print(d)

View File

@@ -11,7 +11,7 @@ class Data:
#--------------------------------------------------------------------------
def keys( self ):
return self.__dict__.keys()
return list(self.__dict__.keys())
#--------------------------------------------------------------------------
def update( self, rhs ):
@@ -43,7 +43,7 @@ class Data:
def _formatValue( self, value, out, indent ):
if isinstance( value, Data ):
out.write( "%s(\n" % self.__class__.__name__ )
for k, v in sorted( value.__dict__.iteritems() ):
for k, v in sorted( value.__dict__.items() ):
if k[0] == "_":
continue
@@ -56,7 +56,7 @@ class Data:
elif isinstance( value, dict ):
out.write( "{\n" )
for k, v in sorted( value.iteritems() ):
for k, v in sorted( value.items() ):
if k[0] == "_":
continue

View File

@@ -33,7 +33,7 @@ def loads( text ):
#=============================================================================
def _toStr( data, ignoreDicts=False ):
# Convert unicode to string.
if isinstance( data, unicode ):
if isinstance( data, str ):
return data.encode( 'utf-8' )
# For lists, process each item.
@@ -45,7 +45,7 @@ def _toStr( data, ignoreDicts=False ):
if isinstance( data, dict ) and not ignoreDicts:
return {
_toStr( k, ignoreDicts=True ) : _toStr( v, ignoreDicts=True )
for k, v in data.iteritems()
for k, v in data.items()
}
# Otherwise return the original object.

View File

@@ -138,7 +138,7 @@ class Poll:
# themselves. So make a copy of the dict value list list
# containing all the objects so we're not modifying the client
# dictionary as we loop over it.
clients = self.clients.values()[:]
clients = list(self.clients.values())[:]
for c in clients:
c.close()
@@ -169,7 +169,7 @@ class Poll:
# Returns tuple (fileDescriptor, bitFlag) of the files
# that can act.
events = self.poll.poll( timeOut_msec )
except select.error, v:
except select.error as v:
# Not sure why, but sometimes with a timeout value, you can
# get an "interrupted system call" error thrown. Web
# searches indicate this isn't really an error and should be

View File

@@ -2,18 +2,18 @@
from tHome.util import Data
d = Data( a=1, b="asdf", c=2 )
print d
print "----"
print(d)
print("----")
d = Data( a=1, b="asdf", c=[2,3,4] )
print d
print "----"
print(d)
print("----")
d = Data( a=1, b="asdf", c={'a':3, 'b':4} )
print d
print "----"
print(d)
print("----")
d = Data( a=1, b=[ Data(a=1,b=2) ], c={'a':3, 'b':[1,2,3]} )
print d
print "----"
print(d)
print("----")