Skip to content
Closed
Show file tree
Hide file tree
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
20 changes: 11 additions & 9 deletions packages/modules/common/evse.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,21 @@ def __init__(self, modbus_id: int, client: modbus.ModbusSerialClient_) -> None:

def get_plug_charge_state(self) -> Tuple[bool, bool, float]:
time.sleep(0.1)
set_current, _, state_number = self.client.read_holding_registers(
raw_set_current, _, state_number = self.client.read_holding_registers(
1000, [ModbusDataType.UINT_16]*3, unit=self.id)
# remove leading zeros
set_current = int(set_current)
log.debug("Gesetzte Stromstärke EVSE: "+str(set_current) +
self.set_current = int(raw_set_current)
log.debug("Gesetzte Stromstärke EVSE: "+str(self.set_current) +
", Status: "+str(state_number)+", Modbus-ID: "+str(self.id))
state = EvseStatusCode(state_number)
if state == EvseStatusCode.FAILURE:
raise ValueError("Unbekannter Zustand der EVSE: State " +
str(state)+", Soll-Stromstärke: "+str(set_current))
str(state)+", Soll-Stromstärke: "+str(self.set_current))
plugged = state.plugged
charging = set_current > 0 if state.charge_enabled else False
if set_current > 32:
set_current = set_current / 100
return plugged, charging, set_current
charging = self.set_current > 0 if state.charge_enabled else False
if self.set_current > 32:
self.set_current = self.set_current / 100
return plugged, charging, self.set_current

def get_firmware_version(self) -> int:
return self.version
Expand Down Expand Up @@ -111,4 +111,6 @@ def deactivate_precise_current(self) -> None:

def set_current(self, current: int) -> None:
time.sleep(0.1)
self.client.write_registers(1000, current, unit=self.id)
formatted_current = round(current*100) if self._precise_current else round(current)
if self.set_current != formatted_current:
self.client.write_registers(1000, formatted_current, unit=self.id)
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import time
from helpermodules.broker import BrokerClient
from helpermodules.logger import ModifyLoglevelContext

from helpermodules.utils import run_command
from helpermodules.utils.error_handling import CP_ERROR, ErrorTimerContext
Expand Down Expand Up @@ -53,15 +52,6 @@ def __init__(self, local_charge_point_num: int,
phases_in_use=0,
power=0)
self._client = client_handler
version = self._client.evse_client.get_firmware_version()
with ModifyLoglevelContext(log, logging.DEBUG):
log.debug(f"Firmware-Version der EVSE: {version}")
if version < 17:
self._precise_current = False
else:
if self._client.evse_client.is_precise_current_active() is False:
self._client.evse_client.activate_precise_current()
self._precise_current = self._client.evse_client.is_precise_current_active()

self.version = SubData.system_data["system"].data["version"]
self.current_branch = SubData.system_data["system"].data["current_branch"]
Expand All @@ -83,9 +73,7 @@ def on_message(client, userdata, message):

def set_current(self, current: float) -> None:
with SingleComponentUpdateContext(self.fault_state, update_always=False):
formatted_current = round(current*100) if self._precise_current else round(current)
if self.set_current_evse != formatted_current:
self._client.evse_client.set_current(formatted_current)
self._client.evse_client.set_current(current)

def get_values(self, phase_switch_cp_active: bool, last_tag: str) -> ChargepointState:
def store_state(chargepoint_state: ChargepointState) -> None:
Expand All @@ -95,7 +83,6 @@ def store_state(chargepoint_state: ChargepointState) -> None:
self.store_internal.update()
with self.client_error_context:
chargepoint_state = self.old_chargepoint_state
self.set_current_evse = chargepoint_state.evse_current

evse_state, counter_state = self._client.request_and_check_hardware(self.fault_state)
power = counter_state.power
Expand All @@ -108,7 +95,6 @@ def store_state(chargepoint_state: ChargepointState) -> None:
self.old_phases_in_use = phases_in_use

time.sleep(0.1)
self.set_current_evse = evse_state.set_current
self.client_error_context.reset_error_counter()

if phase_switch_cp_active:
Expand All @@ -135,7 +121,7 @@ def store_state(chargepoint_state: ChargepointState) -> None:
phases_in_use=phases_in_use,
power_factors=counter_state.power_factors,
rfid=last_tag,
evse_current=self.set_current_evse,
evse_current=evse_state.set_current,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

set_current kilngt für mich zu sehr nach Setter-Funktion, actual_current fände ich besser...

serial_number=counter_state.serial_number,
max_evse_current=evse_state.max_current,
version=self.version,
Expand Down