Repository: bimmerconnected/bimmer_connected
Pull request #634 (2024-07-14 19:05:48)

Add ChargingMode.NO_ACTION
## Proposed change
<!--
  Describe the big picture of your changes here to communicate to the
  maintainers why we should accept this pull request. If it fixes a bug
  or resolves a feature request, be sure to link to that issue in the
  additional information section.
-->
Add `ChargingMode.NO_ACTION` sometimes returned by vehicles.

## Type of change
- [x] Bugfix (non-breaking change which fixes an issue)
- [ ] New feature (which adds functionality to this library)
- [ ] Breaking change (fix/feature causing existing functionality to break)
- [ ] Code quality improvements to existing code or addition of tests

## Additional information
<!--
  Details are important, and help maintainers processing your PR.
  Please be sure to fill out additional details, if applicable.
-->

- This PR fixes or closes issue: fixes https://github.com/home-assistant/core/issues/101531 (cc @admkhe)
- This PR is related to issue: https://github.com/bimmerconnected/bimmer_connected/discussions/628#discussioncomment-10044922

## Checklist
<!--
  Put an `x` in the boxes that apply. You can also fill these out after
  creating the PR. If you're unsure about any of them, don't hesitate to ask.
  We're here to help! This is simply a reminder of what we are going to look
  for before merging your code.
-->

- [x] The code change is tested and works locally.
- [x] Tests have been added to verify that the new code works.



Patch:
diff --git a/bimmer_connected/vehicle/charging_profile.py b/bimmer_connected/vehicle/charging_profile.py
index 3c128cd..27458cc 100644
--- a/bimmer_connected/vehicle/charging_profile.py
+++ b/bimmer_connected/vehicle/charging_profile.py
@@ -16,12 +16,15 @@ class ChargingMode(StrEnum):
 
     IMMEDIATE_CHARGING = "IMMEDIATE_CHARGING"
     DELAYED_CHARGING = "DELAYED_CHARGING"
+    NO_ACTION = "NO_ACTION"
     UNKNOWN = "UNKNOWN"
 
 
 MAP_CHARGING_MODE_TO_REMOTE_SERVICE = {
     ChargingMode.IMMEDIATE_CHARGING: "CHARGING_IMMEDIATELY",
     ChargingMode.DELAYED_CHARGING: "TIME_SLOT",
+    ChargingMode.NO_ACTION: "NO_ACTION",
+    ChargingMode.UNKNOWN: "NO_ACTION",
 }
 
 


Test patch:
diff --git a/bimmer_connected/tests/test_remote_services.py b/bimmer_connected/tests/test_remote_services.py
index 6567621..fd489bc 100644
--- a/bimmer_connected/tests/test_remote_services.py
+++ b/bimmer_connected/tests/test_remote_services.py
@@ -207,7 +207,7 @@ async def test_set_charging_settings(bmw_fixture: respx.Router):
 
 
 @pytest.mark.asyncio
-async def test_set_charging_profile(bmw_fixture: respx.Router):
+async def test_set_charging_profile(bmw_fixture: respx.Router, monkeypatch: pytest.MonkeyPatch):
     """Test setting the charging profile on a car."""
 
     account = await prepare_account_with_vehicles()
@@ -238,6 +238,11 @@ async def test_set_charging_profile(bmw_fixture: respx.Router):
     await vehicle.remote_services.trigger_charging_profile_update(precondition_climate=True)
     assert vehicle.charging_profile.is_pre_entry_climatization_enabled is True
 
+    # test with an unknown charging mode
+    monkeypatch.setattr(vehicle.charging_profile, "charging_mode", ChargingMode.UNKNOWN)
+    await vehicle.remote_services.trigger_charging_profile_update(charging_mode=ChargingMode.IMMEDIATE_CHARGING)
+    assert vehicle.charging_profile.charging_mode == ChargingMode.IMMEDIATE_CHARGING
+
 
 @pytest.mark.asyncio
 async def test_vehicles_without_enabled_services(bmw_fixture: respx.Router):