Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #39

Merged
merged 17 commits into from
Nov 17, 2023
Merged

Dev #39

Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 45 additions & 41 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,55 +161,59 @@ 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"]:
socketio.emit('updateSensorData', {'metric': "batteryPower", 'value': payload, 'sn': sn, 'date': round(time.time()*1000)})

elif "solarflow-hub" in msg.topic:
try:
payload = int(payload)
payload = float(payload)
except:
log.error(f'Error converting payload to int: {payload}')

if "outputHomePower" == property:
socketio.emit('updateSensorData', {'metric': 'outputHome', 'value': int(payload), 'date': round(time.time()*1000)})
if "solarInputPower" == property:
socketio.emit('updateSensorData', {'metric': 'solarInput', 'value': int(payload), 'date': round(time.time()*1000)})
if "outputPackPower" == property:
socketio.emit('updateSensorData', {'metric': 'outputPack', 'value': -int(payload), 'date': round(time.time()*1000)})
if "packInputPower" == property:
socketio.emit('updateSensorData', {'metric': 'outputPack', 'value': int(payload), 'date': round(time.time()*1000)})
if "electricLevel" == property:
socketio.emit('updateSensorData', {'metric': 'electricLevel', 'value': int(payload), 'date': round(time.time()*1000)})
device_details["electricLevel"] = payload
if "homeUsage" == property:
socketio.emit('updateSensorData', {'metric': 'homeUsage', 'value': int(float(payload)), 'date': round(time.time()*1000)})
if "outputLimit" == property:
socketio.emit('updateLimit', {'property': 'outputLimit', 'value': f'{payload} W'})
device_details["outputLimit"] = payload
if "socSet" == property:
socketio.emit('updateLimit', {'property': 'socSet', 'value': f'{payload/10} %'})
device_details["socSet"] = payload
if "minSoc" == property:
socketio.emit('updateLimit', {'property': 'minSoc', 'value': f'{payload/10} %'})
device_details["minSoc"] = payload
if "inverseMaxPower" == property:
socketio.emit('updateLimit', {'property': 'inverseMaxPower', 'value': f'{payload} W'})
device_details["inverseMaxPower"] = payload
if "packNum" == property:
socketio.emit('updateLimit', {'property': 'packNum', 'value': f'{payload}'})
device_details["packNum"] = payload
if "wifiState" == property:
socketio.emit('updateLimit', {'property': 'wifiState', 'value': f'{bool(int(payload))}'})
device_details["wifiState"] = payload
if "masterSoftVersion" == property:
socketio.emit('updateLimit', {'property': 'masterSoftVersion', 'value': softVersion(payload)})
device_details["masterSoftVersion"] = payload

log.warning(f'{property} is type {type(property).__name__}: {payload}')

if type(payload) is float or type(payload) is int:
if "outputHomePower" == property:
socketio.emit('updateSensorData', {'metric': 'outputHome', 'value': int(payload), 'date': round(time.time()*1000)})
if "solarInputPower" == property:
socketio.emit('updateSensorData', {'metric': 'solarInput', 'value': int(payload), 'date': round(time.time()*1000)})
if "outputPackPower" == property:
socketio.emit('updateSensorData', {'metric': 'outputPack', 'value': -int(payload), 'date': round(time.time()*1000)})
if "packInputPower" == property:
socketio.emit('updateSensorData', {'metric': 'outputPack', 'value': int(payload), 'date': round(time.time()*1000)})
if "electricLevel" == property:
socketio.emit('updateSensorData', {'metric': 'electricLevel', 'value': int(payload), 'date': round(time.time()*1000)})
device_details["electricLevel"] = payload
if "homeUsage" == property:
socketio.emit('updateSensorData', {'metric': 'homeUsage', 'value': int(float(payload)), 'date': round(time.time()*1000)})
if "outputLimit" == property:
socketio.emit('updateLimit', {'property': 'outputLimit', 'value': f'{payload} W'})
device_details["outputLimit"] = payload
if "socSet" == property:
socketio.emit('updateLimit', {'property': 'socSet', 'value': f'{payload/10} %'})
device_details["socSet"] = payload
if "minSoc" == property:
socketio.emit('updateLimit', {'property': 'minSoc', 'value': f'{payload/10} %'})
device_details["minSoc"] = payload
if "inverseMaxPower" == property:
socketio.emit('updateLimit', {'property': 'inverseMaxPower', 'value': f'{int(payload)} W'})
device_details["inverseMaxPower"] = payload
if "packNum" == property:
socketio.emit('updateLimit', {'property': 'packNum', 'value': f'{int(payload)}'})
device_details["packNum"] = payload
if "wifiState" == property:
socketio.emit('updateLimit', {'property': 'wifiState', 'value': f'{bool(int(payload))}'})
device_details["wifiState"] = payload
if "masterSoftVersion" == property:
socketio.emit('updateLimit', {'property': 'masterSoftVersion', 'value': softVersion(int(payload))})
device_details["masterSoftVersion"] = payload


def on_connect(client, userdata, flags, rc):
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