From 17c9c37160eaa706df94a73ef640254416a25086 Mon Sep 17 00:00:00 2001 From: okaegi Date: Mon, 19 Dec 2022 10:41:13 +0100 Subject: [PATCH] =?UTF-8?q?Leistungsmessung=20=C3=BCber=20Lovato=20Z=C3=A4?= =?UTF-8?q?hler=20f=C3=BCr=20Smarthome?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Neu wird der Lovato Zähler als separate Leistungsmessung unterstützt. Ebenso wurde auf static Types umgestellt. sdm120, sdm630 und Lovato Zähler werden aus openWB 2.0 Verzeichnis genommen Neu werden diese Zähler für Smarthome aus dem Openwb 2.0 Verzeischniss aufgerufen. Die separaten verzeichnisse unter Smarthome wurden gelöscht. Anpassung wegen static Types --- modules/smarthome/sdm120/sdm120.py | 33 ------- modules/smarthome/sdm630/sdm630.py | 33 ------- runs/mqttsub.py | 2 +- runs/usmarthome/smartbase.py | 80 ++++++++-------- runs/usmarthome/smartmeas.py | 147 ++++++++++++++++------------- web/settings/smarthomeconfig.php | 9 +- 6 files changed, 132 insertions(+), 172 deletions(-) delete mode 100644 modules/smarthome/sdm120/sdm120.py delete mode 100644 modules/smarthome/sdm630/sdm630.py diff --git a/modules/smarthome/sdm120/sdm120.py b/modules/smarthome/sdm120/sdm120.py deleted file mode 100644 index 2f5ac4fa5..000000000 --- a/modules/smarthome/sdm120/sdm120.py +++ /dev/null @@ -1,33 +0,0 @@ -#!/usr/bin/python3 -import sys -import os -import time -import getopt -import socket -import struct -import binascii -import json -devicenumber = str(sys.argv[1]) -seradd = str(sys.argv[2]) -sdmid = int(sys.argv[3]) -port = int(sys.argv[4]) - -from pymodbus.client.sync import ModbusTcpClient - -client = ModbusTcpClient(seradd, port=port) - -#KWH Total Import -resp = client.read_input_registers(0x0048,2, unit=sdmid) -vwh = struct.unpack('>f',struct.pack('>HH',*resp.registers)) -vwh2 = float("%.3f" % vwh[0]) * int(1000) -vwh3 = str(vwh2) - -#Aktueller Verbrauch -resp = client.read_input_registers(0x000C,2, unit=sdmid) -watti = struct.unpack('>f',struct.pack('>HH',*resp.registers)) -watt = int(watti[0]) - -answer = '{"power":' + str(watt) + ',"powerc":' + str(vwh3) + '} ' -f1 = open('/var/www/html/openWB/ramdisk/smarthome_device_ret' + str(devicenumber), 'w') -json.dump(answer,f1) -f1.close() diff --git a/modules/smarthome/sdm630/sdm630.py b/modules/smarthome/sdm630/sdm630.py deleted file mode 100644 index c0a570958..000000000 --- a/modules/smarthome/sdm630/sdm630.py +++ /dev/null @@ -1,33 +0,0 @@ -#!/usr/bin/python3 -import sys -import os -import time -import getopt -import socket -import struct -import binascii -import json -devicenumber = str(sys.argv[1]) -seradd = str(sys.argv[2]) -sdmid = int(sys.argv[3]) -port = int(sys.argv[4]) - -from pymodbus.client.sync import ModbusTcpClient - -client = ModbusTcpClient(seradd, port=port) - -#KWH Total Import -resp = client.read_input_registers(0x0156,2, unit=sdmid) -vwh = struct.unpack('>f',struct.pack('>HH',*resp.registers)) -vwh2 = float("%.3f" % vwh[0]) * int(1000) -vwh3 = str(vwh2) - -#Aktueller Verbrauch -resp = client.read_input_registers(0x0034,2, unit=sdmid) -watti = struct.unpack('>f',struct.pack('>HH',*resp.registers)) -watt = int(watti[0]) - -answer = '{"power":' + str(watt) + ',"powerc":' + str(vwh3) + '} ' -f1 = open('/var/www/html/openWB/ramdisk/smarthome_device_ret' + str(devicenumber), 'w') -json.dump(answer,f1) -f1.close() diff --git a/runs/mqttsub.py b/runs/mqttsub.py index 7d9de345d..fd223f830 100755 --- a/runs/mqttsub.py +++ b/runs/mqttsub.py @@ -197,7 +197,7 @@ def on_message(client, userdata, msg): client.publish("openWB/config/get/SmartHome/Devices/"+str(devicenumb)+"/device_type", msg.payload.decode("utf-8"), qos=0, retain=True) if (( "openWB/config/set/SmartHome/Device" in msg.topic) and ("device_measureType" in msg.topic)): devicenumb=re.sub(r'\D', '', msg.topic) - validDeviceMeasureTypes = ['shelly','tasmota','http','mystrom','sdm630','we514','fronius','json','avm','mqtt','sdm120','smaem'] # 'pyt' is deprecated and will be removed! + validDeviceMeasureTypes = ['shelly','tasmota','http','mystrom','sdm630','lovato','we514','fronius','json','avm','mqtt','sdm120','smaem'] # 'pyt' is deprecated and will be removed! if ( 1 <= int(devicenumb) <= numberOfSupportedDevices and len(str(msg.payload.decode("utf-8"))) > 2): try: deviceMeasureTypeIndex = validDeviceMeasureTypes.index(msg.payload.decode("utf-8")) diff --git a/runs/usmarthome/smartbase.py b/runs/usmarthome/smartbase.py index 2a4709b78..bd9293d70 100644 --- a/runs/usmarthome/smartbase.py +++ b/runs/usmarthome/smartbase.py @@ -1,9 +1,10 @@ #!/usr/bin/python3 import time import os +from typing import Dict, Tuple, Any from usmarthome.global0 import log from usmarthome.smartbase0 import Sbase0 -from usmarthome.smartmeas import Slsdm630, Slsdm120, Slwe514, Slfronius +from usmarthome.smartmeas import Slsdm630, Sllovato, Slsdm120, Slwe514, Slfronius from usmarthome.smartmeas import Sljson, Slsmaem, Slshelly, Sltasmota, Slmqtt from usmarthome.smartmeas import Slhttp, Slavm, Slmystrom from usmarthome.smartbut import Sbshelly @@ -22,12 +23,12 @@ class Sbase(Sbase0): nureinschaltinsec = 0 eindevstatus = 0 - def __init__(self): + def __init__(self) -> None: # setting super().__init__() print('__init__ Sbase executed') - self.mqtt_param = {} - self.mqtt_param_del = {} + self.mqtt_param = {} # type: Dict[str, str] + self.mqtt_param_del = {} # type: Dict[str, str] self.device_name = 'none' self.devstatus = 10 # (10 = ueberschuss gesteuert oder manual, @@ -53,7 +54,7 @@ def __init__(self): self.newdevice_manual = 0 self.newdevice_manual_control = 0 self.device_type = 'none' - self._smart_param = {} + self._smart_param = {} # type: Dict[str, str] self._uberschussoffset = 0 self._uberschuss = 0 self.device_canswitch = 0 @@ -75,9 +76,9 @@ def __init__(self): self._device_ip = 'none' self._device_measuretype = 'none' self._device_measureip = 'none' - self._device_measureportsdm = '8899' - self._device_dacport = '8899' - self._device_measureid = '0' + self._device_measureportsdm = 8899 + self._device_dacport = 8899 + self._device_measureid = 0 self._device_finishtime = '00:00' self._device_starttime = '00:00' self._device_endtime = '00:00' @@ -89,8 +90,8 @@ def __init__(self): self._device_pbtype = 'none' self._device_lambdaueb = 'UP' self._old_pbtype = 'none' - self._mydevicepb = 'none' - self._oldrelais = '2' + self._mydevicepb = 'none' # type: Any + self._oldrelais = 2 self._oldwatt = 0 self._device_chan = 0 self._device_updatesec = 0 @@ -123,12 +124,13 @@ def __init__(self): self.device_setauto = 0 self.gruppe = 'none' self.btchange = 0 + self._mydevicemeasure = 'none' # type: Any - def __del__(self): + def __del__(self) -> None: print('__del__ Sbase executed ') - def prewatt(self, uberschuss, uberschussoffset): + def prewatt(self, uberschuss: int, uberschussoffset: int) -> None: self._uberschuss = uberschuss self._uberschussoffset = uberschussoffset if (self._deviceconfiguredold == "9") and (self._deviceconfigured == @@ -154,7 +156,7 @@ def prewatt(self, uberschuss, uberschussoffset): # prepare end self.getueb() - def postwatt(self): + def postwatt(self) -> None: (self.newwatt, self.newwattk) = self.sepwatt(self.newwatt, self.newwattk) # bei reiner Leistungsmessung relais nur nach Watt setzten @@ -168,7 +170,7 @@ def postwatt(self): self.relais = 0 self.mqtt_param = {} pref = 'openWB/SmartHome/Devices/' + str(self.device_nummer) + '/' - self.mqtt_param[pref + 'RelayStatus'] = self.relais + self.mqtt_param[pref + 'RelayStatus'] = str(self.relais) if (self.c_mantime_f == 'Y') and (self.device_manual != 1): # nach Ausschalten manueller Modus mindestens 30 Sek + # max( ausschaltverzögerung,mindeseinschaltdauer @@ -226,7 +228,7 @@ def postwatt(self): else: self.c_oldstampeinschaltdauer = 0 self.c_oldstampeinschaltdauer_f = 'N' - self.mqtt_param[pref + 'RunningTimeToday'] = self.runningtime + self.mqtt_param[pref + 'RunningTimeToday'] = str(self.runningtime) # Einschaltzeit des Relais setzen if (self._oldrelais == 0): if (self.relais == 1): @@ -242,9 +244,9 @@ def postwatt(self): self.mqtt_param[pref + 'TemperatureSensor1'] = self.temp1 if (self.device_temperatur_configured > 2): self.mqtt_param[pref + 'TemperatureSensor2'] = self.temp2 - self.mqtt_param[pref + 'Watt'] = self._oldwatt - self.mqtt_param[pref + 'Wh'] = self._wh - self.mqtt_param[pref + 'WHImported_temp'] = self._wpos + self.mqtt_param[pref + 'Watt'] = str(self._oldwatt) + self.mqtt_param[pref + 'Wh'] = str(self._wh) + self.mqtt_param[pref + 'WHImported_temp'] = str(self._wpos) self.mqtt_param[pref + 'oncountnor'] = self.oncountnor self.mqtt_param[pref + 'OnCntStandby'] = self.oncntstandby # nur bei Status 10 on status mitnehmen @@ -252,7 +254,7 @@ def postwatt(self): sendstatus = self.relais + self.devstatus else: sendstatus = self.devstatus - self.mqtt_param[pref + 'Status'] = sendstatus + self.mqtt_param[pref + 'Status'] = str(sendstatus) if (self.gruppe == 'A'): Sbase.ausschaltwatt = Sbase.ausschaltwatt + self._oldwatt elif (self.gruppe == 'E'): @@ -260,7 +262,7 @@ def postwatt(self): Sbase.einrelais = 1 Sbase.eindevstatus = max(Sbase.eindevstatus, self.devstatus) - def updatepar(self, input_param): + def updatepar(self, input_param: Dict[str, str]) -> None: self._smart_param = input_param.copy() self.device_nummer = int(self._smart_param.get('device_nummer', '0')) for key, value in self._smart_param.items(): @@ -327,11 +329,11 @@ def updatepar(self, input_param): elif (key == 'device_measureip'): self._device_measureip = value elif (key == 'device_measurePortSdm'): - self._device_measureportsdm = value + self._device_measureportsdm = valueint elif (key == 'device_dacport'): - self._device_dacport = value + self._device_dacport = valueint elif (key == 'device_measureid'): - self._device_measureid = value + self._device_measureid = valueint elif (key == 'device_finishTime'): self._device_finishtime = value elif (key == 'device_startTime'): @@ -390,7 +392,7 @@ def updatepar(self, input_param): " " + value) else: log.info("(" + str(self.device_nummer) + ") " - + __class__.__name__ + " überlesen " + key + + + "Sbase überlesen " + key + " " + value) self._first_run = 0 pref = 'openWB/SmartHome/Devices/' + str(self.device_nummer) + '/' @@ -451,6 +453,8 @@ def updatepar(self, input_param): del self._mydevicemeasure if (self._device_measuretype == 'sdm630'): self._mydevicemeasure = Slsdm630() + elif (self._device_measuretype == 'lovato'): + self._mydevicemeasure = Sllovato() elif (self._device_measuretype == 'sdm120'): self._mydevicemeasure = Slsdm120() elif (self._device_measuretype == 'we514'): @@ -494,14 +498,14 @@ def updatepar(self, input_param): str(self.device_nummer), 'w') as f: f.write(str(self.device_homeconsumtion)) - def getueb(self): + def getueb(self) -> None: # (1 = mit Speicher, 2 = mit offset , 0 = manual eingeschaltet) if (self.ueberschussberechnung == 2): self.devuberschuss = self._uberschussoffset else: self.devuberschuss = self._uberschuss - def preturn(self, zustand, ueberschussberechnung, updatecnt): + def preturn(self, zustand: int, ueberschussberechnung: int, updatecnt: int) -> None: self.ueberschussberechnung = ueberschussberechnung with open(self._basePath+'/ramdisk/device' + str(self.device_nummer) + '_req_relais', 'w') as f: @@ -519,7 +523,7 @@ def preturn(self, zustand, ueberschussberechnung, updatecnt): self._c_eintime_f = 'Y' self._c_eintime = int(time.time()) - def sepwatt(self, newwatt, newwattk): + def sepwatt(self, newwatt: int, newwattk: int) -> Tuple[int, int]: if (self._device_differentmeasurement == 0): return newwatt, newwattk # ueberschuss übertragen @@ -529,7 +533,7 @@ def sepwatt(self, newwatt, newwattk): self.newwattk = self._mydevicemeasure.newwattk return self.newwatt, self.newwattk - def conditions(self, speichersoc): + def conditions(self, speichersoc: int) -> None: # do not do anything in case none type or can switch = no # or device manuam mode if ((self.device_canswitch == 0) or @@ -550,8 +554,8 @@ def conditions(self, speichersoc): work_ausschaltschwelle = self._device_ausschaltschwelle work_ausschaltverzoegerung = self._device_ausschaltverzoegerung local_time = datetime.now(timezone.utc).astimezone() - localhour = int(local_time.strftime(format="%H")) - localminute = int(local_time.strftime(format="%M")) + localhour = int(local_time.strftime("%H")) + localminute = int(local_time.strftime("%M")) localinsec = int((localhour * 60 * 60) + (localminute * 60)) if (localinsec < Sbase.nureinschaltinsec) and (Sbase.eindevices > 0): log.info("(" + str(self.device_nummer) + ") " + @@ -966,8 +970,8 @@ def conditions(self, speichersoc): self._c_ausverz_f = 'N' # rechne Zeit exclusive einschaltgruppe local_time = datetime.now(timezone.utc).astimezone() - localh = int(local_time.strftime(format="%H")) - localminute = int(local_time.strftime(format="%M")) + localh = int(local_time.strftime("%H")) + localminute = int(local_time.strftime("%M")) localinsec = int((localh * 60 * 60) + (localminute * 60)) Sbase.nureinschaltinsec = localinsec + Sbase.einverz return @@ -1132,7 +1136,7 @@ def conditions(self, speichersoc): self._c_einverz_f = 'N' self._c_ausverz_f = 'N' - def simcount(self, watt2, pref, importfn, exportfn, nummer, wattks): + def simcount(self, watt2: int, pref: str, importfn: str, exportfn: str, nummer: str, wattks: int) -> None: # Zaehler mitgeliefert in WH , zurueckrechnen fuer simcount if wattks > 0: wattposkh = wattks @@ -1191,8 +1195,8 @@ def simcount(self, watt2, pref, importfn, exportfn, nummer, wattks): wattnegh = wattnegh + watt1 else: wattposh = wattposh + watt1 - wattposkh = wattposh/3600 - wattnegkh = (wattnegh*-1)/3600 + wattposkh = int(wattposh/3600) + wattnegkh = int((wattnegh*-1)/3600) with open(self._basePath+'/ramdisk/'+pref+'watt0pos', 'w') as f: f.write(str(wattposh)) self._wpos = wattposh @@ -1210,17 +1214,17 @@ def simcount(self, watt2, pref, importfn, exportfn, nummer, wattks): with open(self._basePath+'/ramdisk/'+pref+'wh0', 'w') as f: f.write(str(watt2)) - def getwatt(self, uberschuss, uberschussoffset): + def getwatt(self, uberschuss: int, uberschussoffset: int) -> None: self.prewatt(uberschuss, uberschussoffset) self.newwatt = 0 self.newwattk = 0 self.relais = 0 self.postwatt() - def turndevicerelais(self, zustand, ueberschussberechnung, updatecnt): + def turndevicerelais(self, zustand: int, ueberschussberechnung: int, updatecnt: int) -> None: pass - def updatebutton(self): + def updatebutton(self) -> None: self.newdevice_manual = self.device_manual self.newdevice_manual_control = self.device_manual_control self.btchange = 0 diff --git a/runs/usmarthome/smartmeas.py b/runs/usmarthome/smartmeas.py index a2304cab5..f58a366ff 100644 --- a/runs/usmarthome/smartmeas.py +++ b/runs/usmarthome/smartmeas.py @@ -1,10 +1,15 @@ from usmarthome.smartbase0 import Sbase0 from usmarthome.global0 import log +from typing import Dict, Tuple +from modules.common import modbus +from modules.common import sdm +from modules.common import lovato + import subprocess class Slbase(Sbase0): - def __init__(self): + def __init__(self) -> None: # # setting super().__init__() @@ -19,14 +24,14 @@ def __init__(self): self.newwatt = 0 self.newwattk = 0 self.relais = 0 - self._smart_param = {} + self._smart_param = {} # type: Dict[str, str] self._device_differentmeasureoment = 0 self._device_configured = '0' self._device_ip = 'none' self._device_measuretype = 'none' self._device_measureip = 'none' - self._device_measureportsdm = '8899' - self._device_measureid = '0' + self._device_measureportsdm = 8899 + self._device_measureid = 0 self._device_measuresmaser = '123' self._device_measuresmaage = 15 self._device_leistungurl = 'none' @@ -45,7 +50,7 @@ def __init__(self): self._device_measchan = 0 self._device_chan = 0 - def updatepar(self, input_param): + def updatepar(self, input_param: Dict[str, str]) -> None: self._smart_param = input_param.copy() self.device_nummer = int(self._smart_param.get('device_nummer', '0')) for key, value in self._smart_param.items(): @@ -88,7 +93,7 @@ def updatepar(self, input_param): elif (key == 'device_measureip'): self._device_measureip = value elif (key == 'device_measurePortSdm'): - self._device_measureportsdm = value + self._device_measureportsdm = valueint elif (key == 'device_measuresmaage'): self._device_measuresmaage = valueint elif (key == 'device_measchan'): @@ -98,7 +103,7 @@ def updatepar(self, input_param): elif (key == 'device_measuresmaser'): self._device_measuresmaser = value elif (key == 'device_measureid'): - self._device_measureid = value + self._device_measureid = valueint elif (key == 'device_leistungurl'): self._device_leistungurl = value elif (key == 'device_measureurl'): @@ -127,27 +132,27 @@ def updatepar(self, input_param): self._device_stateurl = value else: log.info("(" + str(self.device_nummer) + ") " - + __class__.__name__ + " überlesen " + key + + + "Slbase überlesen " + key + " " + value) - def __del__(self): + def __del__(self) -> None: print('__del__ Slbase executed ') class Slmqtt(Slbase): - def __init__(self): + def __init__(self) -> None: # setting super().__init__() print('__init__ Slmqtt excuted') - def getwattread(self): + def getwattread(self) -> None: self._watt(self._device_ip) - def sepwattread(self): + def sepwattread(self) -> Tuple[int, int]: self._watt(self._device_measureip) return self.newwatt, self.newwattk - def _watt(self, ip): + def _watt(self, ip: str) -> None: argumentList = ['python3', self._prefixpy + 'mqtt/watt.py', str(self.device_nummer), str(ip), str(self.devuberschuss)] @@ -164,19 +169,19 @@ def _watt(self, ip): class Slshelly(Slbase): - def __init__(self): + def __init__(self) -> None: # setting super().__init__() print('__init__ Slshelly excuted') - def getwattread(self): + def getwattread(self) -> None: self._watt(self._device_ip, self._device_chan) - def sepwattread(self): + def sepwattread(self) -> Tuple[int, int]: self._watt(self._device_measureip, self._device_measchan) return self.newwatt, self.newwattk - def _watt(self, ip, chan): + def _watt(self, ip: str, chan: int) -> None: argumentList = ['python3', self._prefixpy + 'shelly/watt.py', str(self.device_nummer), str(ip), '0', str(chan)] @@ -214,24 +219,24 @@ def _watt(self, ip, chan): class Slavm(Slbase): - def __init__(self): + def __init__(self) -> None: # setting super().__init__() print('__init__ Slavm excuted') - def getwattread(self): + def getwattread(self) -> None: self._watt(self._device_ip, self._device_actor, self._device_username, self._device_password) - def sepwattread(self): + def sepwattread(self) -> Tuple[int, int]: self._watt(self._device_measureip, self._device_measureavmactor, self._device_measureavmusername, self._device_measureavmpassword) return self.newwatt, self.newwattk - def _watt(self, ip, act, user, pw): + def _watt(self, ip: str, act: str, user: str, pw: str) -> None: argumentList = ['python3', self._prefixpy + 'avmhomeautomation/watt.py', str(self.device_nummer), str(ip), @@ -250,19 +255,19 @@ def _watt(self, ip, act, user, pw): class Sltasmota(Slbase): - def __init__(self): + def __init__(self) -> None: # setting super().__init__() print('__init__ Sltasmota excuted') - def getwattread(self): + def getwattread(self) -> None: self._watt(self._device_ip) - def sepwattread(self): + def sepwattread(self) -> Tuple[int, int]: self._watt(self._device_measureip) return self.newwatt, self.newwattk - def _watt(self, ip): + def _watt(self, ip: str) -> None: argumentList = ['python3', self._prefixpy + 'tasmota/watt.py', str(self.device_nummer), str(ip), '0'] try: @@ -278,21 +283,21 @@ def _watt(self, ip): class Slhttp(Slbase): - def __init__(self): + def __init__(self) -> None: # setting super().__init__() print('__init__ Slhttp excuted') - def getwattread(self): + def getwattread(self) -> None: self._watt(self._device_leistungurl, 'none', self._device_stateurl) - def sepwattread(self): + def sepwattread(self) -> Tuple[int, int]: self._watt(self._device_measureurl, self._device_measureurlc, 'none') return self.newwatt, self.newwattk - def _watt(self, url, urlc, urls): + def _watt(self, url: str, urlc: str, urls: str) -> None: argumentList = ['python3', self._prefixpy + 'http/watt.py', str(self.device_nummer), '0', str(self.devuberschuss), url, urlc, @@ -312,19 +317,19 @@ def _watt(self, url, urlc, urls): class Slmystrom(Slbase): - def __init__(self): + def __init__(self) -> None: # setting super().__init__() print('__init__ Slmystrom excuted') - def getwattread(self): + def getwattread(self) -> None: self._watt(self._device_ip) - def sepwattread(self): + def sepwattread(self) -> Tuple[int, int]: self._watt(self._device_measureip) return self.newwatt, self.newwattk - def _watt(self, ip): + def _watt(self, ip: str) -> None: argumentList = ['python3', self._prefixpy + 'mystrom/watt.py', str(self.device_nummer), str(ip), '0'] try: @@ -347,12 +352,12 @@ def _watt(self, ip): class Slsmaem(Slbase): - def __init__(self): + def __init__(self) -> None: # setting super().__init__() print('__init__ Slsmaem excuted') - def sepwattread(self): + def sepwattread(self) -> Tuple[int, int]: argumentList = ['python3', self._prefixpy + 'smaem/watt.py', str(self.device_nummer), str(self._device_measureip), str(self._device_measuresmaser), @@ -371,12 +376,12 @@ def sepwattread(self): class Slwe514(Slbase): - def __init__(self): + def __init__(self) -> None: # setting super().__init__() print('__init__ Slwe514 excuted') - def sepwattread(self): + def sepwattread(self) -> Tuple[int, int]: argumentList = ['python3', self._prefixpy + 'we514/watt.py', str(self.device_nummer), str(self._device_measureip), str(self._device_measureid)] @@ -394,12 +399,12 @@ def sepwattread(self): class Sljson(Slbase): - def __init__(self): + def __init__(self) -> None: # setting super().__init__() print('__init__ Sljson excuted') - def sepwattread(self): + def sepwattread(self) -> Tuple[int, int]: argumentList = ['python3', self._prefixpy + 'json/watt.py', str(self.device_nummer), self._device_measurejsonurl, @@ -418,12 +423,12 @@ def sepwattread(self): class Slfronius(Slbase): - def __init__(self): + def __init__(self) -> None: # setting super().__init__() print('__init__ Slfronius excuted') - def sepwattread(self): + def sepwattread(self) -> Tuple[int, int]: argumentList = ['python3', self._prefixpy + 'fronius/watt.py', str(self.device_nummer), str(self._device_measureip), str(self._device_measureid)] @@ -440,23 +445,42 @@ def sepwattread(self): return self.newwatt, self.newwattk +class Sllovato(Slbase): + def __init__(self) -> None: + # setting + super().__init__() + print('__init__ Sllovato excuted') + + def sepwattread(self) -> Tuple[int, int]: + try: + # neu aus openwb 2.0 + with modbus.ModbusTcpClient_(self._device_measureip, self._device_measureportsdm) as tcp_client: + lov = lovato.Lovato(self._device_measureid, tcp_client) + _, newwatt = lov.get_power() + self.newwatt = int(newwatt) + self.newwattk = 0 + except Exception as e1: + log.warning("Leistungsmessung %s %d %s Fehlermeldung: %s " + % ('Lovato ', self.device_nummer, + str(self._device_measureip), str(e1))) + return self.newwatt, self.newwattk + + class Slsdm630(Slbase): - def __init__(self): + def __init__(self) -> None: # setting super().__init__() print('__init__ Slsdm630 excuted') - def sepwattread(self): - argumentList = ['python3', self._prefixpy + 'sdm630/sdm630.py', - str(self.device_nummer), str(self._device_measureip), - str(self._device_measureid), - str(self._device_measureportsdm)] + def sepwattread(self) -> Tuple[int, int]: try: - proc = subprocess.Popen(argumentList) - proc.communicate() - answer = self.readret() - self.newwatt = int(answer['power']) - self.newwattk = int(answer['powerc']) + # neu aus openwb 2.0 + with modbus.ModbusTcpClient_(self._device_measureip, self._device_measureportsdm) as tcp_client: + sdm630 = sdm.Sdm630(self._device_measureid, tcp_client) + # log.warning(" sdm630 id %s " % ( str(id(sdm630)))) + _, newwatt = sdm630.get_power() + self.newwatt = int(newwatt) + self.newwattk = int(sdm630.get_imported()) except Exception as e1: log.warning("Leistungsmessung %s %d %s Fehlermeldung: %s " % ('Sdm630 ', self.device_nummer, @@ -465,22 +489,19 @@ def sepwattread(self): class Slsdm120(Slbase): - def __init__(self): + def __init__(self) -> None: # setting super().__init__() print('__init__ Slsdm120 excuted') - def sepwattread(self): - argumentList = ['python3', self._prefixpy + 'sdm120/sdm120.py', - str(self.device_nummer), str(self._device_measureip), - str(self._device_measureid), - str(self._device_measureportsdm)] + def sepwattread(self) -> Tuple[int, int]: try: - proc = subprocess.Popen(argumentList) - proc.communicate() - answer = self.readret() - self.newwatt = int(answer['power']) - self.newwattk = int(answer['powerc']) + # neu aus openwb 2.0 + with modbus.ModbusTcpClient_(self._device_measureip, self._device_measureportsdm) as tcp_client: + sdm120 = sdm.Sdm120(self._device_measureid, tcp_client) + _, newwatt = sdm120.get_power() + self.newwatt = int(newwatt) + self.newwattk = int(sdm120.get_imported()) except Exception as e1: log.warning("Leistungsmessung %s %d %s Fehlermeldung: %s " % ('Sdm120 ', self.device_nummer, diff --git a/web/settings/smarthomeconfig.php b/web/settings/smarthomeconfig.php index f21d4949e..3a3f94c0a 100644 --- a/web/settings/smarthomeconfig.php +++ b/web/settings/smarthomeconfig.php @@ -792,10 +792,11 @@ + -
+
@@ -816,19 +817,19 @@
-
+
-
+
Standardeinstellungen verschiedener Geräte:
- SDM630: 8899
+ SDM630/Lovato: 8899
Elgris: 502