Skip to content

Commit c40edff

Browse files
authored
add TxDefaultProfile to set charging rate (#312)
1 parent fe80357 commit c40edff

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

custom_components/ocpp/api.py

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,6 @@ async def set_charge_rate(self, limit_amps: int = 32, limit_watts: int = 22000):
509509
ckey.charge_profile_max_stack_level.value
510510
)
511511
stack_level = int(resp)
512-
513512
req = call.SetChargingProfilePayload(
514513
connector_id=0,
515514
cs_charging_profiles={
@@ -532,11 +531,33 @@ async def set_charge_rate(self, limit_amps: int = 32, limit_watts: int = 22000):
532531
if resp.status == ChargingProfileStatus.accepted:
533532
return True
534533
else:
535-
_LOGGER.warning("Failed with response: %s", resp.status)
536-
await self.notify_ha(
537-
f"Warning: Set charging profile failed with response {resp.status}"
534+
_LOGGER.debug(
535+
"ChargePointMaxProfile is not supported by this charger, trying TxDefaultProfile instead..."
538536
)
539-
return False
537+
req = call.SetChargingProfilePayload(
538+
connector_id=0,
539+
cs_charging_profiles={
540+
om.charging_profile_id.value: 8,
541+
om.stack_level.value: stack_level,
542+
om.charging_profile_kind.value: ChargingProfileKindType.relative.value,
543+
om.charging_profile_purpose.value: ChargingProfilePurposeType.tx_default_profile.value,
544+
om.charging_schedule.value: {
545+
om.charging_rate_unit.value: units,
546+
om.charging_schedule_period.value: [
547+
{om.start_period.value: 0, om.limit.value: lim}
548+
],
549+
},
550+
},
551+
)
552+
resp = await self.call(req)
553+
if resp.status == ChargingProfileStatus.accepted:
554+
return True
555+
else:
556+
_LOGGER.warning("Failed with response: %s", resp.status)
557+
await self.notify_ha(
558+
f"Warning: Set charging profile failed with response {resp.status}"
559+
)
560+
return False
540561

541562
async def set_availability(self, state: bool = True):
542563
"""Become operative."""

0 commit comments

Comments
 (0)