# 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):
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)