Skip to content

Commit

Permalink
added enable_hlc_charging as a method of SlacSessionController (#19)
Browse files Browse the repository at this point in the history
* added enable_hlc_charging as a method of SlacSessionController and improved the examples

* reformatted the code
  • Loading branch information
tropxy authored Apr 26, 2022
1 parent 94c16e9 commit e380a4f
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 53 deletions.
71 changes: 45 additions & 26 deletions slac/examples/multiple_slac_sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,35 +24,54 @@ def __init__(self, slac_config: Config):
self.slac_config = slac_config
self.running_sessions: List["SlacEvseSession"] = []

async def notify_matching_ongoing(self, evse_id: str):
"""overrides the notify matching ongoing method defined in
SlacSessionController"""
logger.info(f"Matching is ongoing for {evse_id}")

async def enable_hlc_charging(self, evse_id: str):
"""
overrides the enable_hlc_charging method defined in SlacSessionController
"""
logger.info(f"Enable PWM and set 5% duty cycle for evse {evse_id}")

async def start(self, cs_config: dict):
while not self.running_sessions:
if cs_config["number_of_evses"] < 1 or (
len(cs_config["parameters"]) != cs_config["number_of_evses"]
):
raise AttributeError("Number of evses provided is invalid.")

for evse_params in cs_config["parameters"]:
evse_id: str = evse_params["evse_id"]
network_interface: str = evse_params["network_interface"]
try:
slac_session = SlacEvseSession(
evse_id, network_interface, self.slac_config
)
await slac_session.evse_set_key()
self.running_sessions.append(slac_session)
except (OSError, TimeoutError, ValueError) as e:
logger.error(
f"PLC chip initialization failed for "
f"EVSE {evse_id}, interface "
f"{network_interface}: {e}. \n"
f"Please check your settings."
)
return
await self.process_cp_state(self.running_sessions[0], "B")
if cs_config["number_of_evses"] < 1 or (
len(cs_config["parameters"]) != cs_config["number_of_evses"]
):
raise AttributeError("Number of evses provided is invalid.")

for evse_params in cs_config["parameters"]:
evse_id: str = evse_params["evse_id"]
network_interface: str = evse_params["network_interface"]
try:
slac_session = SlacEvseSession(
evse_id, network_interface, self.slac_config
)
await slac_session.evse_set_key()
self.running_sessions.append(slac_session)
except (OSError, TimeoutError, ValueError) as e:
logger.error(
f"PLC chip initialization failed for "
f"EVSE {evse_id}, interface "
f"{network_interface}: {e}. \n"
f"Please check your settings."
)
return
for session in self.running_sessions:
asyncio.create_task(self.enable_hlc_and_trigger_slac(session))

async def enable_hlc_and_trigger_slac(self, session):
"""
Dummy method to fake the enabling of the HLC by setting PWM to 5%
and triggers the Matching by handling a CP state change to "B"
"""
await self.enable_hlc_charging(session.evse_id)
await self.process_cp_state(session, "B")
await asyncio.sleep(2)
await self.process_cp_state(self.running_sessions[0], "C")
await self.process_cp_state(session, "C")
await asyncio.sleep(20)
await self.process_cp_state(self.running_sessions[0], "A")
await self.process_cp_state(session, "A")


async def main(env_path: Optional[str] = None):
Expand Down
69 changes: 43 additions & 26 deletions slac/examples/single_slac_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,35 +23,52 @@ def __init__(self, slac_config: Config):
self.slac_config = slac_config
self.running_sessions: List["SlacEvseSession"] = []

async def notify_matching_ongoing(self, evse_id: str):
"""overrides the notify matching ongoing method defined in
SlacSessionController"""
logger.info(f"Matching is ongoing for {evse_id}")

async def enable_hlc_charging(self, evse_id: str):
"""
overrides the enable_hlc_charging method defined in SlacSessionController
"""
logger.info(f"Enable PWM and set 5% duty cycle for evse {evse_id}")

async def start(self, cs_config: dict):
while not self.running_sessions:
if cs_config["number_of_evses"] < 1 or (
len(cs_config["parameters"]) != cs_config["number_of_evses"]
):
raise AttributeError("Number of evses provided is invalid.")

evse_params: dict = cs_config["parameters"][0]
evse_id: str = evse_params["evse_id"]
network_interface: str = evse_params["network_interface"]
try:
slac_session = SlacEvseSession(
evse_id, network_interface, self.slac_config
)
await slac_session.evse_set_key()
self.running_sessions.append(slac_session)
except (OSError, TimeoutError, ValueError) as e:
logger.error(
f"PLC chip initialization failed for "
f"EVSE {evse_id}, interface "
f"{network_interface}: {e}. \n"
f"Please check your settings."
)
return
await self.process_cp_state(self.running_sessions[0], "B")
if cs_config["number_of_evses"] < 1 or (
len(cs_config["parameters"]) != cs_config["number_of_evses"]
):
raise AttributeError("Number of evses provided is invalid.")

evse_params: dict = cs_config["parameters"][0]
evse_id: str = evse_params["evse_id"]
network_interface: str = evse_params["network_interface"]
try:
slac_session = SlacEvseSession(evse_id, network_interface, self.slac_config)
await slac_session.evse_set_key()
self.running_sessions.append(slac_session)
except (OSError, TimeoutError, ValueError) as e:
logger.error(
f"PLC chip initialization failed for "
f"EVSE {evse_id}, interface "
f"{network_interface}: {e}. \n"
f"Please check your settings."
)
return

await self.enable_hlc_and_trigger_slac(self.running_sessions[0])

async def enable_hlc_and_trigger_slac(self, session):
"""
Dummy method to fake the enabling of the HLC by setting PWM to 5%
and triggers the Matching by handling a CP state change to "B"
"""
await self.enable_hlc_charging(session.evse_id)
await self.process_cp_state(session, "B")
await asyncio.sleep(2)
await self.process_cp_state(self.running_sessions[0], "C")
await self.process_cp_state(session, "C")
await asyncio.sleep(20)
await self.process_cp_state(self.running_sessions[0], "A")
await self.process_cp_state(session, "A")


async def main(env_path: Optional[str] = None):
Expand Down
16 changes: 15 additions & 1 deletion slac/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -831,9 +831,23 @@ def __init__(self):
pass

async def notify_matching_ongoing(self, evse_id: str):
"""
Used to Notify an external service that a Matching process is ongoing
"""
pass

async def notify_matching_failed(self, evse_id: str):
"""
Used to Notify an external service that a Matching process has failed
"""
pass

async def enable_hlc_charging(self, evse_id: str):
"""
Used to interface with an external service that controls the PWM of the
Control Pilot circuit and then trigger High Level Communication Charging,
by enabling the PWM and setting the duty cycle to 5%
"""
pass

async def process_cp_state(self, slac_session, state: str):
Expand Down Expand Up @@ -879,7 +893,7 @@ async def start_matching(
in case it fails again, it gives up and just with a transition to B, C or D,
SLAC will restart.
:param slac_session: Instance of SlacEVSESession
:param slac_session: Instance of SlacEvseSession
:param number_of_retries: number of trials before SLAC Mathing is defined
as a failure
:return: None
Expand Down

0 comments on commit e380a4f

Please sign in to comment.