Skip to content

Commit

Permalink
Fix KeyError in ChargingProfile (#457)
Browse files Browse the repository at this point in the history
* Fix KeyError on `climatisationOn`

* Allow any ChargingProfile entry not to exist
  • Loading branch information
rikroe authored Jun 22, 2022
1 parent 2e5bd15 commit d751fea
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
26 changes: 20 additions & 6 deletions bimmer_connected/vehicle/charging_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,25 @@ def _parse_vehicle_data(cls, vehicle_data: Dict) -> Dict:

charging_profile = vehicle_data["status"]["chargingProfile"]

retval["is_pre_entry_climatization_enabled"] = bool(charging_profile["climatisationOn"])
retval["departure_times"] = [DepartureTimer(t) for t in charging_profile["departureTimes"]]
retval["preferred_charging_window"] = ChargingWindow(charging_profile["reductionOfChargeCurrent"])
retval["timer_type"] = TimerTypes(charging_profile["chargingControlType"])
retval["charging_preferences"] = ChargingPreferences(charging_profile["chargingPreference"])
retval["charging_mode"] = ChargingMode(charging_profile["chargingMode"])
retval["is_pre_entry_climatization_enabled"] = (
bool(charging_profile["climatisationOn"]) if "" in charging_profile else None
)
retval["departure_times"] = [DepartureTimer(t) for t in charging_profile.get("departureTimes", [])]
retval["preferred_charging_window"] = (
ChargingWindow(charging_profile["reductionOfChargeCurrent"])
if "reductionOfChargeCurrent" in charging_profile
else None
)
retval["timer_type"] = (
TimerTypes(charging_profile["chargingControlType"]) if "chargingControlType" in charging_profile else None
)
retval["charging_preferences"] = (
ChargingPreferences(charging_profile["chargingPreference"])
if "chargingPreference" in charging_profile
else None
)
retval["charging_mode"] = (
ChargingMode(charging_profile["chargingMode"]) if "chargingMode" in charging_profile else None
)

return retval
2 changes: 1 addition & 1 deletion test/responses/G21/json_export.json
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@
"has_check_control_messages": false
},
"charging_profile": {
"is_pre_entry_climatization_enabled": false,
"is_pre_entry_climatization_enabled": null,
"timer_type": "weeklyPlanner",
"departure_times": [
{
Expand Down

0 comments on commit d751fea

Please sign in to comment.