Browse Source

update

main
Peter Shipley 9 years ago
parent
commit
d953215a74
4 changed files with 56 additions and 57 deletions
  1. +28
    -23
      RainEagle/EagleClass.py
  2. +7
    -8
      bin/meter_status.py
  3. +11
    -5
      bin/plot_power.py
  4. +10
    -21
      setup.py

+ 28
- 23
RainEagle/EagleClass.py View File

@@ -167,8 +167,8 @@ class Eagle(object) :
print "debug : = ", self.debug print "debug : = ", self.debug




if self.addr is None :
raise AssertionError("no hostname or IP given")
if self.addr is None :
raise AssertionError("no hostname or IP given")


# preload # preload
if self.mac is None : if self.mac is None :
@@ -183,13 +183,13 @@ class Eagle(object) :
print "Init DeviceMacId = ", self.macid print "Init DeviceMacId = ", self.macid


if self.checkfw : if self.checkfw :
mysetting = self.get_setting_data()
dev_fw_ver = mysetting['device_fw_version']
if ( LooseVersion(dev_fw_ver) < LooseVersion(min_fw_ver) ) :
warn_message = "Warning : device firmware " \
+ "{0} < {1} please concideer " \
+ "updating ".format(dev_fw_ver, min_fw_ver)
warn( warn_message, RuntimeWarning, stacklevel=3)
mysetting = self.get_setting_data()
dev_fw_ver = mysetting['device_fw_version']
if ( LooseVersion(dev_fw_ver) < LooseVersion(min_fw_ver) ) :
warn_message = "Warning : device firmware " \
+ "{0} < {1} please concideer " \
+ "updating ".format(dev_fw_ver, min_fw_ver)
warn( warn_message, RuntimeWarning, stacklevel=3)






@@ -197,8 +197,8 @@ class Eagle(object) :


def list_devices(self, macid=None): def list_devices(self, macid=None):
""" """
Send the LIST_DEVICES command
returns information about the EAGLE device
Send the LIST_DEVICES command
returns information about the EAGLE device


""" """
comm_responce = self._send_soc_comm("list_devices", MacId=macid) comm_responce = self._send_soc_comm("list_devices", MacId=macid)
@@ -221,7 +221,7 @@ class Eagle(object) :
if comm_responce is None: if comm_responce is None:
raise RainEagleResponseError("get_device_data : Null reply") raise RainEagleResponseError("get_device_data : Null reply")
if self.debug : if self.debug :
print comm_responce
print comm_responce
etree = ET.fromstring('<S>' + comm_responce + '</S>') etree = ET.fromstring('<S>' + comm_responce + '</S>')
rv = _et2d(etree) rv = _et2d(etree)
return rv return rv
@@ -331,6 +331,7 @@ class Eagle(object) :
return rv return rv


# 17 # 17
# needs to be rewritten to stream the data via iter
def get_history_data(self, macid=None, starttime="0x00000000", endtime=None, frequency=None) : def get_history_data(self, macid=None, starttime="0x00000000", endtime=None, frequency=None) :
""" Send the GET_HISTORY_DATA command """ Send the GET_HISTORY_DATA command
get a series of summation values over an interval of time get a series of summation values over an interval of time
@@ -361,8 +362,8 @@ class Eagle(object) :


def get_device_list(self, macid=None) : def get_device_list(self, macid=None) :
""" """
Send the LIST_DEVICES command
returns information about the EAGLE device
Send the LIST_DEVICES command
returns information about the EAGLE device


""" """
comm_responce = self._send_http_comm("get_device_list", MacId=macid) comm_responce = self._send_http_comm("get_device_list", MacId=macid)
@@ -419,7 +420,7 @@ class Eagle(object) :
""" """
id = _tohex(id) id = _tohex(id)
comm_responce = self._send_http_comm("confirm_message", comm_responce = self._send_http_comm("confirm_message",
MacId=macid, Id=id)
MacId=macid, Id=id)
return json.loads(comm_responce) return json.loads(comm_responce)


def get_message(self, macid=None) : def get_message(self, macid=None) :
@@ -595,7 +596,7 @@ class Eagle(object) :
if status not in ['on', 'off'] : if status not in ['on', 'off'] :
raise ValueError("set_remote_management status must be 'on' or 'off'") raise ValueError("set_remote_management status must be 'on' or 'off'")
comm_responce = self._send_http_comm("set_remote_management", comm_responce = self._send_http_comm("set_remote_management",
MacId=macid, Status=status)
MacId=macid, Status=status)
return json.loads(comm_responce) return json.loads(comm_responce)




@@ -615,7 +616,7 @@ class Eagle(object) :
if source not in ['meter', 'internet'] : if source not in ['meter', 'internet'] :
raise ValueError("set_time_source Source must be 'meter' or 'internet'") raise ValueError("set_time_source Source must be 'meter' or 'internet'")
comm_responce = self._send_http_comm("set_time_source", comm_responce = self._send_http_comm("set_time_source",
MacId=macid, Source=source)
MacId=macid, Source=source)
return json.loads(comm_responce) return json.loads(comm_responce)


def get_price(self, macid=None) : def get_price(self, macid=None) :
@@ -674,7 +675,7 @@ class Eagle(object) :
'set_price_status': 'success' 'set_price_status': 'success'
""" """
comm_responce = self._send_http_comm("set_price", comm_responce = self._send_http_comm("set_price",
MacId=macid,
MacId=macid,
Price="0xFFFFFFFF", Price="0xFFFFFFFF",
TrailingDigits="0x00") TrailingDigits="0x00")
return json.loads(comm_responce) return json.loads(comm_responce)
@@ -724,7 +725,7 @@ class Eagle(object) :


See also get_uploader() to retrieve current uploader cloud config See also get_uploader() to retrieve current uploader cloud config
""" """
if url is None :
if url is None :
raise ValueError("invalid url.\n") raise ValueError("invalid url.\n")


if url.__len__() > 200 : if url.__len__() > 200 :
@@ -781,8 +782,8 @@ class Eagle(object) :


def _send_http_comm(self, cmd, **kwargs): def _send_http_comm(self, cmd, **kwargs):


if self.debug :
print "\n\n_send_http_comm : ", cmd
if self.debug :
print "\n\n_send_http_comm : ", cmd


commstr = "<LocalCommand>\n" commstr = "<LocalCommand>\n"
commstr += "<Name>{0!s}</Name>\n".format(cmd) commstr += "<Name>{0!s}</Name>\n".format(cmd)
@@ -791,8 +792,12 @@ class Eagle(object) :
commstr += "<{0}>{1!s}</{0}>\n".format(k, v) commstr += "<{0}>{1!s}</{0}>\n".format(k, v)
commstr += "</LocalCommand>\n" commstr += "</LocalCommand>\n"


if self.debug :
print(commstr)
if cmd == "set_cloud" :
print(commstr)
return dict()

if self.debug :
print(commstr)


url = "http://{0}/cgi-bin/cgi_manager".format(self.addr) url = "http://{0}/cgi-bin/cgi_manager".format(self.addr)




+ 7
- 8
bin/meter_status.py View File

@@ -50,9 +50,8 @@ def main() :
parser = create_parser() parser = create_parser()
args, unknown = parser.parse_known_args() args, unknown = parser.parse_known_args()


print "Args = ", args, vars(args)
print "unknown = ", unknown
exit(0)
# print "Args = ", args, vars(args)
# print "unknown = ", unknown


eg = Eagle(**vars(args)) eg = Eagle(**vars(args))
# timeout=45, # timeout=45,
@@ -94,9 +93,9 @@ def print_currentsummation(cs) :
if 'TimeStamp' in cs : if 'TimeStamp' in cs :
time_stamp = to_epoch_1970(cs['TimeStamp']) time_stamp = to_epoch_1970(cs['TimeStamp'])
print "{0:s} : ".format(time.asctime(time.localtime(time_stamp))) print "{0:s} : ".format(time.asctime(time.localtime(time_stamp)))
print "\tReceived = {0:{width}.3f} Kw".format(reading_received, width=10)
print "\tDelivered = {0:{width}.3f} Kw".format(reading_delivered, width=10)
print "\t\t{0:{width}.3f} Kw".format( (reading_delivered - reading_received), width=14)
print "\tReceived = {0:10.3f} Kw".format(reading_received)
print "\tDelivered = {0:10.3f} Kw".format(reading_delivered)
print "\tMeter = {0:10.3f} Kw".format( (reading_delivered - reading_received))




def print_instantdemand(idemand) : def print_instantdemand(idemand) :
@@ -124,8 +123,8 @@ def print_instantdemand(idemand) :
time_stamp = to_epoch_1970(idemand['TimeStamp']) time_stamp = to_epoch_1970(idemand['TimeStamp'])
print "{0:s} : ".format(time.asctime(time.localtime(time_stamp))) print "{0:s} : ".format(time.asctime(time.localtime(time_stamp)))


print "\tDemand = {0:{width}.3f} Kw".format(reading, width=10)
print "\tAmps = {0:{width}.3f}".format( ((reading * 1000) / 240), width=10)
print "\tDemand = {0:10.3f} Kw".format(reading)
print "\tAmps = {0:10.3f}".format( ((reading * 1000) / 240))




# #


+ 11
- 5
bin/plot_power.py View File

@@ -31,6 +31,10 @@ def main(eg) :
def print_data(eg) : def print_data(eg) :
rh = eg.get_history_data() rh = eg.get_history_data()
#+ # endtime=None, frequency=None) : #+ # endtime=None, frequency=None) :
global curr_day


curr_day = time.gmtime(1);


for dat in rh['HistoryData']['CurrentSummation'] : for dat in rh['HistoryData']['CurrentSummation'] :
print_currentsummation(dat) print_currentsummation(dat)
@@ -83,11 +87,13 @@ def print_currentsummation(cs) :
#print "\t\tnew max_delta_delivered :", max_delta_delivered #print "\t\tnew max_delta_delivered :", max_delta_delivered


time_struct = time.localtime(time_stamp) time_struct = time.localtime(time_stamp)
if curr_day != time_struct.tm_mday :
curr_day = time_struct.tm_mday
print "# day_delta_received={0:0.4f}".format(day_delta_received) \
+ "\tday_delta_delivered={0:0.4f}".format(day_delta_delivered) \
+ " : {0:0.4f}".format((day_delta_delivered - day_delta_received))
if curr_day.tm_mday != time_struct.tm_mday :
curr_day = time_struct
print "# {0} day_delta_received={1:0.4f}".format( \
time.strftime("%a %Y-%m-%d", curr_day),
day_delta_received) \
+ "\tday_delta_delivered={0:0.4f}".format(day_delta_delivered) \
+ " : {0:0.4f}".format((day_delta_delivered - day_delta_received))
day_delta_received = 0 day_delta_received = 0
day_delta_delivered = 0 day_delta_delivered = 0




+ 10
- 21
setup.py View File

@@ -10,38 +10,27 @@ from distutils.core import setup
class install_scripts_and_symlinks(install_scripts): class install_scripts_and_symlinks(install_scripts):
'''Like install_scripts, but also replicating nonexistent symlinks''' '''Like install_scripts, but also replicating nonexistent symlinks'''
def run(self): def run(self):
print "=============install_scripts_and_symlinks run"
install_scripts.run(self)
# Replicate symlinks if they don't exist
print self
print "data_files = ", dir( self.distribution.data_files)
print type(self.distribution.data_files)
print self.distribution.data_files
for script in self.distribution.scripts:
print "\n---script = ",script
if os.path.islink(script):
target = os.readlink(script)
newlink = os.path.join(self.install_dir, os.path.basename(script))
if not os.path.exists(newlink):
print "++++++++++", target, " -> ", newlink
# os.symlink(target, newlink)
install_scripts.run(self)
# Replicate symlinks if they don't exist
for script in self.distribution.scripts:
if os.path.islink(script):
newlink = os.path.join(self.install_dir, os.path.basename(script))




setup( setup(
name='RainEagle', name='RainEagle',
version='0.1.7',
version='0.1.7a',
author='Peter Shipley', author='Peter Shipley',
author_email='Peter.Shipley@gmail.com', author_email='Peter.Shipley@gmail.com',
packages=find_packages(), packages=find_packages(),
scripts=[ 'bin/meter_status.py', 'bin/plot_power.py' ], scripts=[ 'bin/meter_status.py', 'bin/plot_power.py' ],
data_files=[ ],
# ('examples', ['bin/isy_find.py', 'bin/isy_progs.py',
# 'bin/isy_log.py', 'bin/isy_net_wol.py']),
# ('bin', ['bin/isy_nodes.py', 'bin/isy_var.py']) ],
data_files=[
('examples', ['bin/plot_power.py', 'bin/gnup_poweruse.txt']),
('bin', ['bin/meter_status.py']) ],
url='https://github.com/evilpete/RainEagle', url='https://github.com/evilpete/RainEagle',
license='BSD', license='BSD',
description='Python Class for utilizing the Rainforest Automation Eagle ( RFA-Z109 ) socket API.', description='Python Class for utilizing the Rainforest Automation Eagle ( RFA-Z109 ) socket API.',
long_description=open('README.md').read(),
long_description=open('README.txt').read(),
cmdclass = { 'install_scripts': install_scripts_and_symlinks } cmdclass = { 'install_scripts': install_scripts_and_symlinks }
) )




Loading…
Cancel
Save