mirror of
https://github.com/alexhopeoconnor/SunGather.git
synced 2026-10-23 02:52:10 +10:00
Add -r registersfilename commandline argument
Allow specifying the registerfile from commandline. ex: $ python3 sungather.py -c /path/to/config.yaml -r /other/path/registers-sungrow.yaml
This commit is contained in:
@@ -122,6 +122,7 @@ usage: python3 sungather.py [options]
|
|||||||
|
|
||||||
Commandline arguments override any config file settings
|
Commandline arguments override any config file settings
|
||||||
**-c config.yaml** - Specify config file.
|
**-c config.yaml** - Specify config file.
|
||||||
|
**-r registersfile.yaml** - Specify registersfile.
|
||||||
**-v 30** - Logging Level, 10 = Debug, 20 = Info, 30 = Warning (default), 40 = Error
|
**-v 30** - Logging Level, 10 = Debug, 20 = Info, 30 = Warning (default), 40 = Error
|
||||||
**--runonce** - Run once then exit
|
**--runonce** - Run once then exit
|
||||||
**-h** - print this help message and exit (also --help)
|
**-h** - print this help message and exit (also --help)
|
||||||
|
|||||||
+14
-10
@@ -429,10 +429,11 @@ class SungrowInverter():
|
|||||||
|
|
||||||
def main():
|
def main():
|
||||||
configfilename = 'config.yaml'
|
configfilename = 'config.yaml'
|
||||||
|
registersfilename = 'registers-sungrow.yaml'
|
||||||
logfolder = ''
|
logfolder = ''
|
||||||
|
|
||||||
try:
|
try:
|
||||||
opts, args = getopt.getopt(sys.argv[1:],"hc:l:v:", "runonce")
|
opts, args = getopt.getopt(sys.argv[1:],"hc:r:l:v:", "runonce")
|
||||||
except getopt.GetoptError:
|
except getopt.GetoptError:
|
||||||
logging.debug(f'No options passed via command line')
|
logging.debug(f'No options passed via command line')
|
||||||
|
|
||||||
@@ -443,16 +444,19 @@ def main():
|
|||||||
print(f'usage: python3 sungather.py [options]')
|
print(f'usage: python3 sungather.py [options]')
|
||||||
print(f'\nCommandling arguments override any config file settings')
|
print(f'\nCommandling arguments override any config file settings')
|
||||||
print(f'Options and arguments:')
|
print(f'Options and arguments:')
|
||||||
print(f'-c config.yaml : Specify config file.')
|
print(f'-c config.yaml : Specify config file.')
|
||||||
print(f'-l /logs/ : Specify folder to store logs.')
|
print(f'-r registers-file.yaml : Specify registers file.')
|
||||||
print(f'-v 30 : Logging Level, 10 = Debug, 20 = Info, 30 = Warning (default), 40 = Error')
|
print(f'-l /logs/ : Specify folder to store logs.')
|
||||||
print(f'--runonce : Run once then exit')
|
print(f'-v 30 : Logging Level, 10 = Debug, 20 = Info, 30 = Warning (default), 40 = Error')
|
||||||
print(f'-h : print this help message and exit (also --help)')
|
print(f'--runonce : Run once then exit')
|
||||||
|
print(f'-h : print this help message and exit (also --help)')
|
||||||
print(f'\nExample:')
|
print(f'\nExample:')
|
||||||
print(f'python3 sungather.py -c /full/path/config.yaml\n')
|
print(f'python3 sungather.py -c /full/path/config.yaml\n')
|
||||||
sys.exit()
|
sys.exit()
|
||||||
elif opt == '-c':
|
elif opt == '-c':
|
||||||
configfilename = arg
|
configfilename = arg
|
||||||
|
elif opt == '-r':
|
||||||
|
registersfilename = arg
|
||||||
elif opt == '-l':
|
elif opt == '-l':
|
||||||
logfolder = arg
|
logfolder = arg
|
||||||
elif opt == '-v':
|
elif opt == '-v':
|
||||||
@@ -481,12 +485,12 @@ def main():
|
|||||||
sys.exit(f"Failed Loading config, missing Inverter settings")
|
sys.exit(f"Failed Loading config, missing Inverter settings")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
registersfile = yaml.safe_load(open('registers-sungrow.yaml', encoding="utf-8"))
|
registersfile = yaml.safe_load(open(registersfilename, encoding="utf-8"))
|
||||||
logging.info(f"Loaded registers: {os.getcwd()}/registers-sungrow.yaml")
|
logging.info(f"Loaded registers: {registersfilename}")
|
||||||
logging.info(f"Registers file version: {registersfile.get('version','UNKNOWN')}")
|
logging.info(f"Registers file version: {registersfile.get('version','UNKNOWN')}")
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
logging.error(f"Failed: Loading registers: {os.getcwd()}/registers-sungrow.yaml {err}")
|
logging.error(f"Failed: Loading registers: {registersfilename} {err}")
|
||||||
sys.exit(f"Failed: Loading registers: {os.getcwd()}/registers-sungrow.yaml {err}")
|
sys.exit(f"Failed: Loading registers: {registersfilename} {err}")
|
||||||
|
|
||||||
config_inverter = {
|
config_inverter = {
|
||||||
"host": configfile['inverter'].get('host',None),
|
"host": configfile['inverter'].get('host',None),
|
||||||
|
|||||||
Reference in New Issue
Block a user