Skip to content

Commit

Permalink
Fix charging settings mock (#554)
Browse files Browse the repository at this point in the history
Co-authored-by: rikroe <rikroe@users.noreply.github.com>
  • Loading branch information
rikroe and rikroe authored Aug 9, 2023
1 parent 95cd1de commit b27e299
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions bimmer_connected/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,11 @@ def service_trigger_sideeffect(
new_state = ChargingState.PLUGGED_IN if "stop" in service else ChargingState.CHARGING
self.states[vin]["state"]["electricChargingState"]["chargingStatus"] = new_state

elif service in ["vehicle-finder"]:
# nothing to do here as this is handled by the
# return of REMOTE_SERVICE_RESPONSE_EVENTPOSITION
pass

json_data = load_response(REMOTE_SERVICE_RESPONSE_INITIATED)
json_data["eventId"] = str(uuid4())

Expand All @@ -244,8 +249,12 @@ def service_trigger_sideeffect(
def charging_settings_sideeffect(self, request: httpx.Request, vin: str) -> httpx.Response:
"""Check if payload is a valid charging settings payload and return evendId."""
cs = ChargingSettings(**json.loads(request.content))
self.states[vin]["state"]["electricChargingState"]["chargingTarget"] = cs.chargingTarget
self.states[vin]["state"]["chargingProfile"]["chargingSettings"]["acCurrentLimit"] = cs.acLimitValue

# this endpoint allows fields to be omitted, so we have to check for that
if cs.chargingTarget:
self.states[vin]["state"]["electricChargingState"]["chargingTarget"] = cs.chargingTarget
if cs.acLimitValue:
self.states[vin]["state"]["chargingProfile"]["chargingSettings"]["acCurrentLimit"] = cs.acLimitValue

return self.service_trigger_sideeffect(request, vin)

Expand All @@ -270,6 +279,8 @@ def charging_profile_sideeffect(self, request: httpx.Request, vin: str) -> httpx
if not isinstance(data["isPreconditionForDepartureActive"], bool):
return httpx.Response(500)

# this endpoint does not allow fields to be omitted, so we can assume that they are always present

# separate charging profile endpoint
self.charging_settings[vin]["chargeAndClimateTimerDetail"]["chargingMode"]["chargingPreference"] = data[
"chargingMode"
Expand Down

0 comments on commit b27e299

Please sign in to comment.