|
15 | 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
16 | 16 |
|
17 | 17 | __author__ = "Tobias Kraft" |
18 | | -__version__ = "1.84" |
| 18 | +__version__ = "1.85" |
19 | 19 |
|
20 | 20 | import requests |
21 | 21 | import time |
|
30 | 30 | from packaging import version |
31 | 31 | import argparse |
32 | 32 | import json |
| 33 | +import subprocess |
33 | 34 |
|
34 | 35 | logging.basicConfig( |
35 | 36 | format='%(asctime)s %(levelname)-8s %(message)s', |
@@ -1057,6 +1058,17 @@ def SetPowerStatus(self, pInverterId: int, pActive: bool): |
1057 | 1058 | if response['type'] != 'success': |
1058 | 1059 | raise Exception(f"Error: SetPowerStatus error: {response['message']}") |
1059 | 1060 |
|
| 1061 | +class Script(Powermeter): |
| 1062 | + def __init__(self, file: str, ip: str, user: str, password: str): |
| 1063 | + self.file = file |
| 1064 | + self.ip = ip |
| 1065 | + self.user = user |
| 1066 | + self.password = password |
| 1067 | + |
| 1068 | + def GetPowermeterWatts(self): |
| 1069 | + power = subprocess.check_output([self.file, self.ip, self.user, self.password]) |
| 1070 | + return CastToInt(power) |
| 1071 | + |
1060 | 1072 |
|
1061 | 1073 | def CreatePowermeter() -> Powermeter: |
1062 | 1074 | shelly_ip = config.get('SHELLY', 'SHELLY_IP') |
@@ -1115,6 +1127,13 @@ def CreatePowermeter() -> Powermeter: |
1115 | 1127 | config.get('VZLOGGER', 'VZL_PORT'), |
1116 | 1128 | config.get('VZLOGGER', 'VZL_UUID') |
1117 | 1129 | ) |
| 1130 | + elif config.getboolean('SELECT_POWERMETER', 'USE_SCRIPT'): |
| 1131 | + return Script( |
| 1132 | + config.get('SCRIPT', 'SCRIPT_FILE'), |
| 1133 | + config.get('SCRIPT', 'SCRIPT_IP'), |
| 1134 | + config.get('SCRIPT', 'SCRIPT_USER'), |
| 1135 | + config.get('SCRIPT', 'SCRIPT_PASS') |
| 1136 | + ) |
1118 | 1137 | else: |
1119 | 1138 | raise Exception("Error: no powermeter defined!") |
1120 | 1139 |
|
|
0 commit comments