hoymiles-wifi/hoymiles_wifi/__main__.py

30 lines
1.1 KiB
Python
Raw Normal View History

import argparse
2023-12-19 08:28:47 +00:00
from hoymiles_wifi.inverter import Inverter
2023-11-17 11:10:33 +00:00
import time
def main():
parser = argparse.ArgumentParser(description="Hoymiles HMS Monitoring")
2023-12-19 11:15:08 +00:00
parser.add_argument("--host", type=str, required=True, help="IP address or hostname of the inverter")
2023-12-19 11:08:05 +00:00
parser.add_argument("command", type=str, choices=['get-real-data-new', 'get-real-data-hms', 'get-real-data', 'get-config', 'network-info', 'app-information-data', 'app-get-hist-power'], help="Command to execute")
args = parser.parse_args()
2023-12-19 11:15:08 +00:00
inverter = Inverter(args.host)
2023-11-17 11:10:33 +00:00
2023-12-19 11:15:08 +00:00
try:
while True:
# Execute the specified command
response = getattr(inverter, args.command, lambda: None)()
if response:
print(f"{args.command.capitalize()} Response: {response}")
else:
print(f"Unable to retrieve {args.command.replace('_', ' ')}")
2023-12-19 07:41:57 +00:00
2023-12-19 11:15:08 +00:00
# Sleep for a while before the next update
time.sleep(60)
except KeyboardInterrupt:
print("Exiting.")
2023-11-17 11:10:33 +00:00
if __name__ == "__main__":
2023-11-17 11:45:17 +00:00
main()