Skip to content

Commit

Permalink
Stabilize wallbox communication
Browse files Browse the repository at this point in the history
Add HTTPError handling
Add login only on JWT expire

Signed-off-by: Johannes Ott <[email protected]>

Use refresh token to reduce logins to wallbox

Signed-off-by: Johannes Ott <[email protected]>

Refactor SunSpec models

Signed-off-by: Johannes Ott <[email protected]>

refactor models module to several files for readability reasons

Signed-off-by: Johannes Ott <[email protected]>

Refactor to stabilize wallbox communication and cleanup models module

Signed-off-by: Johannes Ott <[email protected]>
  • Loading branch information
DerOetzi committed Jan 5, 2024
1 parent 0320d44 commit 83d48ed
Show file tree
Hide file tree
Showing 13 changed files with 697 additions and 600 deletions.
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ loguru==0.7.2
gmqtt==0.6.13
scheduler==0.8.5
requests==2.31.0
influxdb-client==1.39.0
influxdb-client==1.39.0
pyjwt=2.8.0
4 changes: 2 additions & 2 deletions solaredge2mqtt/influxdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import pkg_resources

from solaredge2mqtt.logging import logger
from solaredge2mqtt.models import Component, PowerFlow
from solaredge2mqtt.models import Component, Powerflow
from solaredge2mqtt.settings import ServiceSettings


Expand Down Expand Up @@ -132,7 +132,7 @@ def _create_component_point(

return point

def write_powerflow(self, powerflow: PowerFlow) -> None:
def write_powerflow(self, powerflow: Powerflow) -> None:
point = Point("powerflow")
for key, value in powerflow.influxdb_fields().items():
point.field(key, value)
Expand Down
11 changes: 6 additions & 5 deletions solaredge2mqtt/modbus.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from solaredge2mqtt.logging import LOGGING_DEVICE_INFO, logger
from solaredge2mqtt.models import (
PowerFlow,
Powerflow,
SunSpecBattery,
SunSpecInverter,
SunSpecMeter,
Expand All @@ -32,7 +32,7 @@ def __init__(self, settings: ServiceSettings):
port=settings.modbus_port,
)

def loop(
async def loop(
self,
) -> Tuple[SunSpecInverter, Dict[str, SunSpecMeter], Dict[str, SunSpecBattery]]:
inverter_raw, meters_raw, batteries_raw = self._get_raw_data()
Expand Down Expand Up @@ -135,18 +135,19 @@ def calc_powerflow(
inverter: SunSpecInverter,
meters: Dict[str, SunSpecMeter],
batteries: Dict[str, SunSpecBattery],
) -> PowerFlow:
) -> Powerflow:
"""
Calculates the power flow in the system by summing the power of all meters and batteries.
It considers both import and export options for each meter in the calculation.
Returns a PowerFlow object representing the total power flow in the system.
"""

powerflow = PowerFlow.calc(inverter, meters, batteries)
powerflow = Powerflow.calc(inverter, meters, batteries)

logger.debug(powerflow)
logger.info(
"Powerflow: PV {pv_production} W, Inverter {inverter.power} W, House {house_consumption} W, "
"Powerflow: PV {pv_production} W, Inverter {inverter.power} W, "
+ "House {house_consumption} W, "
+ "Grid {grid.power} W, Battery {battery.power} W",
pv_production=powerflow.pv_production,
inverter=powerflow.inverter,
Expand Down
Loading

0 comments on commit 83d48ed

Please sign in to comment.