Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into feature/schemas-dir-a…
Browse files Browse the repository at this point in the history
…utodetect

Signed-off-by: Kai-Uwe Hermann <[email protected]>
  • Loading branch information
hikinggrass committed Nov 21, 2024
2 parents 256e1f8 + b1c0ff0 commit 0d14004
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 25 deletions.
2 changes: 1 addition & 1 deletion everest-testing/src/everest/testing/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__="0.4.2"
__version__="0.4.3"
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,14 @@

@dataclass
class EverestEnvironmentOCPPConfiguration:
libocpp_path: Path
ocpp_version: OCPPVersion
central_system_port: int
central_system_host: str = "127.0.0.1"
ocpp_module_id: str = "ocpp"
template_ocpp_config: Optional[
Path] = None # Path for OCPP config to be used; if not provided, will be determined from everest config
device_model_component_config_path: Optional[
Path] = None # Path of the OCPP device model json schemas. If not set, {libocpp_path} / 'config/v201/component_config' will be used
Path] = None # Path of the OCPP device model json schemas.
configuration_strategies: list[OCPPModuleConfigurationStrategy] | None = None


Expand Down Expand Up @@ -208,9 +207,7 @@ def _setup_libocpp_configuration(self, temporary_paths: _EverestEnvironmentTempo
elif self._ocpp_config.ocpp_version == OCPPVersion.ocpp16:
source_ocpp_config = self._determine_configured_charge_point_config_path_from_everest_config()
elif self._ocpp_config.ocpp_version == OCPPVersion.ocpp201:
source_ocpp_config = self._ocpp_config.device_model_component_config_path \
if self._ocpp_config.device_model_component_config_path \
else self._ocpp_config.libocpp_path / 'config/v201/component_config'
source_ocpp_config = self._ocpp_config.device_model_component_config_path

return liboccp_configuration_helper.generate_ocpp_config(
central_system_port=self._ocpp_config.central_system_port,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ def plug_out(self, connector_id=1):
f"{self._mqtt_external_prefix}everest_external/nodered/{connector_id}/carsim/cmd/modify_charging_session",
"unplug")

def plug_out_iso(self, connector_id=1):
self._mqtt_client.publish(
f"{self._mqtt_external_prefix}everest_external/nodered/{connector_id}/carsim/cmd/modify_charging_session",
"iso_stop_charging;iso_wait_v2g_session_stopped;unplug")

def swipe(self, token, connectors=None):
connectors = connectors if connectors is not None else [1]
provided_token = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ def plug_in_ac_iso(self, payment_type, connector_id):
"""
raise NotImplementedError()

def plug_out_iso(self, connector_id):
"""
Plug out of an electric vehicle properly ending the ISO15118 session.
"""
raise NotImplementedError()

def plug_out(self):
"""
Plug out of an electric vehicle from the chargepoint.
Expand Down
59 changes: 40 additions & 19 deletions everest-testing/src/everest/testing/ocpp_utils/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ def ocpp_config(request, central_system: CentralSystem, test_config: OcppTestCon
central_system_port=central_system.port,
central_system_host="127.0.0.1",
ocpp_version=ocpp_version,
libocpp_path=Path(request.config.getoption("--libocpp")),
template_ocpp_config=Path(ocpp_config_marker.args[0]) if ocpp_config_marker else None,
device_model_component_config_path=Path(f"{request.config.getoption('--everest-prefix')}/share/everest/modules/OCPP201/component_config"),
configuration_strategies=ocpp_configuration_strategies
)

Expand Down Expand Up @@ -103,9 +103,45 @@ def test_config():


class FtpThread(Thread):
def __init__(self, directory, port, test_config: OcppTestConfiguration, ftp_socket,
group = None, target = None, name = None, args = ..., kwargs = None, *, daemon = None):
super().__init__(group, target, name, args, kwargs, daemon=daemon)
self.directory = directory
self.port = port
self.test_config = test_config
self.ftp_socket = ftp_socket

def set_directory(self, directory):
self.directory = directory

def set_port(self, port):
self.port = port

def set_test_config(self, test_config: OcppTestConfiguration):
self.test_config = test_config

def set_socket(self, ftp_socket):
self.ftp_socket = ftp_socket

def stop(self):
self.server.close_all()

def run(self):
shutil.copyfile(self.test_config.firmware_info.update_file, os.path.join(
self.directory, "firmware_update.pnx"))
shutil.copyfile(self.test_config.firmware_info.update_file_signature,
os.path.join(self.directory, "firmware_update.pnx.base64"))

authorizer = DummyAuthorizer()
authorizer.add_user(getpass.getuser(), "12345", self.directory, perm="elradfmwMT")

handler = FTPHandler
handler.authorizer = authorizer

self.server = servers.FTPServer(self.ftp_socket, handler)

self.server.serve_forever()


@pytest.fixture
def ftp_server(test_config: OcppTestConfiguration):
Expand All @@ -120,29 +156,14 @@ def ftp_server(test_config: OcppTestConfiguration):
ftp_socket.bind(address)
port = ftp_socket.getsockname()[1]

def _ftp_server(test_config: OcppTestConfiguration, ftp_socket):
shutil.copyfile(test_config.firmware_info.update_file, os.path.join(
d, "firmware_update.pnx"))
shutil.copyfile(test_config.firmware_info.update_file_signature,
os.path.join(d, "firmware_update.pnx.base64"))

authorizer = DummyAuthorizer()
authorizer.add_user(getpass.getuser(), "12345", d, perm="elradfmwMT")

handler = FTPHandler
handler.authorizer = authorizer

server = servers.FTPServer(ftp_socket, handler)

server.serve_forever()

ftp_thread = FtpThread(target=_ftp_server, args=[test_config, ftp_socket])
ftp_thread = FtpThread(directory=d, port=port, test_config=test_config, ftp_socket=ftp_socket)
ftp_thread.daemon = True
ftp_thread.set_port(port)
ftp_thread.start()

yield ftp_thread

ftp_thread.stop()

shutil.rmtree(d)


Expand Down

0 comments on commit 0d14004

Please sign in to comment.