]> git.sven.stormbind.net Git - sven/scripts.git/blobdiff - home/enverbridge.py
Ignore timeouts on the envertech portal
[sven/scripts.git] / home / enverbridge.py
index a1405a6bbecda02b921121ed270d92b54b4bf344..04cbe0e8d365c6d22f772762bda467ac7847fc72 100755 (executable)
@@ -4,8 +4,8 @@
 # on an Envertech EnverBridge device. This is a replacement
 # for the "SetID" programm provided as a Win32 executable at
 # http://www.envertec.com/uploads/bigfiles/Set%20ID.zip
-# Tested online with the EnverBridge 202 and Inverters which
-# have the same serial nummer on both labels.
+# Tested online with the EnverBridge 202 and a EVT 560 module
+# inverter.
 #
 # Logic seems the be the following:
 # Take the inverter id, append the char 9 to 16 of the 16 char
 # port 8765. Wait for a response paket to the broadcast address
 # on port 8764.
 
-from optparse import OptionParser
+import argparse
 import socket
 import sys
 import re
 
-parser = OptionParser(usage="usage: %prog [options] MIIDs")
-parser.add_option("-b", "--bid",
-                  action="store",
-                  type="int",
-                  dest="bid",
-                  help="Serial Number of your EnverBridge")
-(options, args) = parser.parse_args()
+parser = argparse.ArgumentParser()
+parser.add_argument("-b",
+                    "--bid",
+                    action="store",
+                    type=int,
+                    dest="bid",
+                    required=True,
+                    help="Serial Number of your EnverBridge")
+parser.add_argument("miids", nargs="+", help="MIIDs of your MicroInverter")
+args = parser.parse_args()
 
 
 def validateMIID(miids):
@@ -49,17 +52,12 @@ def buildMIIDList(miids):
     return msg
 
 
-# minimal input validation
-if len(args) < 1:
-    print("Error: missing MIIDs, provide at least one inverter serial")
-    sys.exit(22)
-
-validateMIID(args)
+validateMIID(args.miids)
 
 # assemble message string and convert to bytes
-message = str(options.bid) + buildMIIDList(args)
+message = str(args.bid) + buildMIIDList(args.miids)
 message = message.encode()
-print('Sending to EnverBridge with ID', options.bid)
+print('Sending to EnverBridge with ID', args.bid)
 
 # Create a UDP client socket w/ broadcast
 sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)