Skip to content

Commit

Permalink
Dev (#39)
Browse files Browse the repository at this point in the history
* convert temperature from Kelvin to Celsius
  • Loading branch information
reinhard-brandstaedter authored Nov 17, 2023
1 parent da52027 commit 740bace
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/solarflow-status.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def on_zendure_message(client, userdata, msg):
if "socLevel" in pack:
socketio.emit('updateSensorData', {'metric': 'socLevel', 'value': pack["socLevel"], 'date': sn})
if "maxTemp" in pack:
socketio.emit('updateSensorData', {'metric': 'maxTemp', 'value': pack["maxTemp"]/100, 'date': sn})
socketio.emit('updateSensorData', {'metric': 'maxTemp', 'value': pack["maxTemp"]/10 - 273.15, 'date': sn})
if "minVol" in pack:
socketio.emit('updateSensorData', {'metric': 'minVol', 'value': pack["minVol"]/100, 'date': sn})
if "maxVol" in pack:
Expand Down Expand Up @@ -161,9 +161,13 @@ def on_local_message(client, userdata, msg):

if "batteries" in msg.topic:
sn = msg.topic.split('/')[-2]
if property not in ["socLevel", "power"]:
if property not in ["socLevel", "power","maxTemp"]:
payload = float(payload)/100

# convert Kelvin to Celsius
if property in ["maxTemp"]:
payload = float(f'{float(payload)/10 - 273.15:.2f}')

if property in ["minVol", "maxVol", "maxTemp", "totalVol", "socLevel"]:
socketio.emit('updateSensorData', {'metric': property, 'value': payload, 'date': sn})
if property in ["power"]:
Expand Down Expand Up @@ -328,7 +332,7 @@ def connect():
if "packDataList" in device_details:
for battery in device_details["packDataList"]:
socketio.emit('updateSensorData', {'metric': 'socLevel', 'value': battery["socLevel"], 'date': battery["sn"]})
socketio.emit('updateSensorData', {'metric': 'maxTemp', 'value': battery["maxTemp"]/10 if battery["maxTemp"] < 1000 else battery["maxTemp"]/100 , 'date': battery["sn"]})
socketio.emit('updateSensorData', {'metric': 'maxTemp', 'value': battery["maxTemp"]/10 - 27.315 if battery["maxTemp"] < 1000 else battery["maxTemp"]/10 - 273.15 , 'date': battery["sn"]})

def set_local_limit(payload):
global local_client
Expand Down

0 comments on commit 740bace

Please sign in to comment.