Browse Source

Backup

main
Peter Shipley 11 years ago
parent
commit
da05a90955
3 changed files with 166 additions and 12 deletions
  1. +41
    -0
      .gitignore
  2. +120
    -10
      RainEagle/EagleClass.py
  3. +5
    -2
      test.py

+ 41
- 0
.gitignore View File

@@ -0,0 +1,41 @@
*.py[cod]

EGG-INFO
.exrc
test.*
Sav/*
Bak/*
*bak

# C extensions
*.so

# Packages
*.egg
*.egg-info
dist
build
eggs
parts
var
sdist
develop-eggs
.installed.cfg
lib
lib64

# Installer logs
pip-log.txt

# Unit test / coverage reports
.coverage
.tox
nosetests.xml

# Translations
*.mo

# Mr Developer
.mr.developer.cfg
.project
.pydevproject

+ 120
- 10
RainEagle/EagleClass.py View File

@@ -3,9 +3,57 @@ import socket
import sys
import os
import time
import xml.etree.ElementTree as ET


__all__ = ['Eagle']

def et2d(et) :
""" Etree to Dict

converts an ETree to a Dict Tree
lists are created for duplicate tag

if there are multiple XML of the name name
an list array is used
attrib tags are converted to "tag_name" + "attrib_name"

if an invalid arg is passed a empty dict is retrurned


arg: ETree Element obj

returns: a dict obj
"""
d = dict()
if not isinstance(et, ET.Element) :
return d
children = list(et)
if et.attrib :
for k, v in list(et.items()) :
d[et.tag + "-" + k] = v
if children :
for child in children :
if child.tag in d :
if type(d[child.tag]) != list :
t = d[child.tag]
d[child.tag] = [t]
if list(child) or child.attrib :
if child.tag in d :
d[child.tag].append(et2d(child))
else :
d[child.tag] = et2d(child)
else :
if child.tag in d :
d[child.tag].append(child.text)
else :
d[child.tag] = child.text
return d



#
# Simple Base class for ISY Class
class Eagle(object) :

def __init__(self, **kwargs):
@@ -14,7 +62,7 @@ class Eagle(object) :
if self.debug :
print self.__class__.__name__, __name__
self.addr = kwargs.get("addr", os.getenv('EAGLE_ADDR', None))
self.port = kwargs.get("port", 5002)
self.port = kwargs.get("port", os.getenv('EAGLE_PORT', 5002))
self.soc = None


@@ -78,24 +126,76 @@ class Eagle(object) :
return replystr

# command as class funtions
# commands as class funtions

def list_devices(self):
comm_responce = self._send_comm("list_devices")
return comm_responce
# temp debug data
comm_responce = "<DeviceInfo>" \
" <DeviceMacId>0xd8d5b90000000xxx</DeviceMacId>" \
" <InstallCode>0x9ac4382dffa81xxx</InstallCode>" \
" <LinkKeyHigh>7e572b66c5b444xxx</LinkKeyHigh>" \
" <LinkKeyLow>94227dca4e773xxx</LinkKeyLow>" \
" <FWVersion>1.4.27 (5278)</FWVersion>" \
" <HWVersion>1.2.3</HWVersion>" \
" <Manufacturer>Rainforest Automation, I</Manufacturer>" \
" <ModelId>RFA-Z109 EAGLE</ModelId>" \
" <DateCode>20130308PO020621</DateCode>" \
"</DeviceInfo>\n"

etree = ET.fromstring('<S>' + comm_responce + '</S>' )
rv = et2d(etree)
return rv

# 3
def get_device_data(self, macid) :
""" Send the GET_DEVICE_DATA command to get a data dump """
comm_responce = self._send_comm("get_device_data", MacId=macid)
return comm_responce
# temp debug data
comm_responce = "<NetworkInfo>" \
" <DeviceMacId>0xd8d5b90000000xxx</DeviceMacId>" \
" <Status>Rejoining</Status>" \
" <MeterMacId>0x001350030011bxxx</MeterMacId>" \
" <ExtPanId>0x7fffffffffffffff</ExtPanId>" \
" <ShortAddr>0x0000ffff</ShortAddr>" \
" <Channel>24</Channel>" \
" <LinkStrength>156</LinkStrength>" \
"</NetworkInfo>" \
"<DeviceInfo>" \
" <DeviceMacId>0xd8d5b90000000xxx</DeviceMacId>" \
" <InstallCode>0x9ac4382dffa81xxx</InstallCode>" \
" <LinkKeyHigh>7e572b66c5b44xxx</LinkKeyHigh>" \
" <LinkKeyLow>94227dca4e773xxx</LinkKeyLow>" \
" <FWVersion>1.4.27 (5278)</FWVersion>" \
" <HWVersion>1.2.3</HWVersion>" \
" <Manufacturer>Rainforest Automation, I</Manufacturer>" \
" <ModelId>RFA-Z109 EAGLE</ModelId>" \
" <DateCode>20130308PO020621</DateCode>" \
"</DeviceInfo>" \
"<InstantaneousDemand>" \
" <DeviceMacId>0xd8d5b90000000xxx</DeviceMacId>" \
" <MeterMacId>0x001350030011bxxx</MeterMacId>" \
" <Demand>0x00000bf1</Demand>" \
" <TimeStamp>0x195193e3</TimeStamp>" \
" <Multiplier>0x00000001</Multiplier>" \
" <Divisor>0x000003e8</Divisor>" \
" <DigitsRight>0x00000003</DigitsRight>" \
" <DigitsLeft>0x0000000f</DigitsLeft>" \
" <SuppressLeadingZero>0x0001</SuppressLeadingZero>" \
"</InstantaneousDemand>"

etree = ET.fromstring('<S>' + comm_responce + '</S>' )
rv = et2d(etree)
return rv

# 10
def get_instantaneous_demand(self, macid, interval) :
""" Send the GET_INSTANTANEOUS_DEMAND command to get the real time demand from the meter"""
comm_responce = self._send_comm("get_instantaneous_demand",
MacId=macid, Interval=interval)
return comm_responce
etree = ET.fromstring('<S>' + comm_responce + '</S>' )
rv = et2d(etree)
return rv

# 11
def get_demand_values(self, macid, interval, frequency=None ) :
@@ -104,27 +204,35 @@ class Eagle(object) :
if frequency :
kwargs["Frequency"] = frequency
comm_responce = self._send_comm("get_demand_values", **kwargs)
return comm_responce
etree = ET.fromstring('<S>' + comm_responce + '</S>' )
rv = et2d(etree)
return rv

# 12
def get_summation_values(self, macid, interval) :
""" Send the GET_SUMMATION_VALUES command to get a series of net summation values """
comm_responce = self._send_comm("get_summation_values",
MacId=macid, Interval=interval )
return comm_responce
etree = ET.fromstring('<S>' + comm_responce + '</S>' )
rv = et2d(etree)
return rv

# 14
def set_fast_poll(self, macid, frequency, duration) :
""" set the fast poll mode on the meter. """
comm_responce = self._send_comm("get_instantaneous_demand",
MacId=macid, Frequency=frequency, Duration=duration)
return comm_responce
etree = ET.fromstring('<S>' + comm_responce + '</S>' )
rv = et2d(etree)
return rv

# 15
def get_fast_poll_status(self, macid) :
""" get the current status of fast poll mode. """
comm_responce = self._send_comm("get_fast_poll_status", MacId=macid)
return comm_responce
etree = ET.fromstring('<S>' + comm_responce + '</S>' )
rv = et2d(etree)
return rv


# 17
@@ -136,7 +244,9 @@ class Eagle(object) :
if frequency :
kwargs["Frequency"] = frequency
comm_responce = self._send_comm("get_fast_poll_status", **kwargs)
return comm_responce
etree = ET.fromstring('<S>' + comm_responce + '</S>' )
rv = et2d(etree)
return rv

# Do nothing
# (syntax check)


+ 5
- 2
test.py View File

@@ -1,9 +1,12 @@

import RainEagle
from pprint import pprint


eg = RainEagle.Eagle( debug=1 )

eg.list_devices()
r = eg.list_devices()
pprint(r)

eg.get_device_data("EE:24:01:05:50:23")
r = eg.get_device_data("EE:24:01:05:50:23")
pprint(r)

Loading…
Cancel
Save