Skip to content

Commit

Permalink
Updated protocol buffer schemas to more closely match the latest tesl…
Browse files Browse the repository at this point in the history
…a web app.
  • Loading branch information
brian committed Jan 16, 2022
1 parent 1519cd4 commit 0fe4f17
Show file tree
Hide file tree
Showing 6 changed files with 2,717 additions and 1,840 deletions.
81 changes: 76 additions & 5 deletions examples/vitals/pull_vitals.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,80 @@
x = 0
output = {}
while(x < num):
parent = str(pw.devices[x].device[0].device.componentParentDin.value)
name = str(pw.devices[x].device[0].device.din.value)
print("Device %d: %s " % (x, pw.devices[x].device[0].device.din.value))
print(" - %s" % pw.devices[x].device[0].device.componentParentDin.value)
print(" - %s" % pw.devices[x].device[0].device.din.value)
device = pw.devices[x].device.device
parent = str(device.componentParentDin.value)
vitals = pw.devices[x].vitals
alerts = pw.devices[x].alerts

name = str(device.din.value)
print("Device %d: %s " % (x, name))

# e.STSTSM = "STSTSM",
# e.POD = "TEPOD",
# e.PINV = "TEPINV",
# e.PVAC = "PVAC",
# e.PVS = "PVS",
# e.SYNC = "TESYNC",
# e.MSA = "TEMSA",
# e.NEURIO = "NEURIO",
# e.ACPW = "ACPW",
# e.PVI = "PVI",
# e.SPW = "SPW"

if name.startswith("TETHC--"):
print(" - Inverter")

if device.HasField("partNumber"):
print(" - Part Number: %s" % device.partNumber.value)
if device.HasField("serialNumber"):
print(" - Serial Number: %s" % device.serialNumber.value)
if device.HasField("manufacturer"):
print(" - Manufacturer: %s" % device.manufacturer.value)
if device.HasField("siteLabel"):
print(" - Site Label: %s" % device.siteLabel.value)
if device.HasField("componentParentDin"):
print(" - Parent DIN: %s" % device.componentParentDin.value)
if device.HasField("firmwareVersion"):
print(" - Firmware Version: %s" % device.firmwareVersion.value)
if device.HasField("firstCommunicationTime"):
print(" - First Communicated At: %s" % device.firstCommunicationTime.ToDatetime())
if device.HasField("lastCommunicationTime"):
print(" - Last Communicated At: %s" % device.lastCommunicationTime.ToDatetime())
# if device.HasField("connectionParameters"):
# print(" - Connection Parameters: %s" % device.connectionParameters)

if device.HasField("deviceAttributes"):
attributes = device.deviceAttributes
if attributes.HasField("teslaEnergyEcuAttributes"):
print(" - Ecu:")
print(" - type: %i" % attributes.teslaEnergyEcuAttributes.ecuType)
if attributes.HasField("generatorAttributes"):
print(" - Generator:")
print(" - nameplateRealPowerW: %i" % attributes.generatorAttributes.nameplateRealPowerW)
print(" - nameplateApparentPowerVa: %i" % attributes.generatorAttributes.nameplateApparentPowerVa)
if attributes.HasField("pvInverterAttributes"):
print(" - Inverter:")
print(" - nameplateRealPowerW: %i" % attributes.pvInverterAttributes.nameplateRealPowerW)
if attributes.HasField("meterAttributes"):
print(" - Meter:")
for location in attributes.meterAttributes.meterLocation:
print(" - location: %i" % location)
a = 0

while (a < len(alerts)):
if (a == 0):
print(" - Alerts:")

print(" - ALERT_%i = %s" % (a, alerts[a]) )
a += 1

print(" - Vitals:")

for y in pw.devices[x].vitals:
vital_name = str(y.name)
if (y.HasField('intValue')):
print(" - %s = %i" % (y.name, y.intValue))
vital_value = y.intValue
if(y.HasField('boolValue')):
print(" - %s = %r" % (y.name,y.boolValue))
vital_value = y.boolValue
Expand All @@ -74,6 +141,10 @@
output[name] = {}
output[name]['Parent'] = parent
output[name][vital_name] = vital_value

if name in output.keys() and len(alerts) > 0:
output[name]["ALERT_Count"] = len(pw.devices[x].alerts)

x += 1

json_out = json.dumps(output, indent=4, sort_keys=True)
Expand Down
Loading

0 comments on commit 0fe4f17

Please sign in to comment.