Repository: bimmerconnected/bimmer_connected
Pull request #395 (2022-01-04 14:24:39)

Add CHARGE_NOW remote service
## 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 the `CHARGE_NOW` service. Based on https://github.com/bimmerconnected/bimmer_connected/discussions/387, but cannot test due to not having an EV.

@Nhubbers: Are you able to try this out?

## Type of change
- [ ] Bugfix (non-breaking change which fixes an issue)
- [x] 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 #
- This PR is related to issue: https://github.com/bimmerconnected/bimmer_connected/discussions/387

## 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.


codecov-commenter: # [Codecov](https://codecov.io/gh/bimmerconnected/bimmer_connected/pull/395?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=bimmerconnected) Report
> Merging [#395](https://codecov.io/gh/bimmerconnected/bimmer_connected/pull/395?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=bimmerconnected) (490b27d) into [master](https://codecov.io/gh/bimmerconnected/bimmer_connected/commit/42b7386df4382ec69db1cc4d08280650c1e63239?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=bimmerconnected) (42b7386) will **increase** coverage by `0.02%`.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://codecov.io/gh/bimmerconnected/bimmer_connected/pull/395/graphs/tree.svg?width=650&height=150&src=pr&token=qNT50j82f6&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=bimmerconnected)](https://codecov.io/gh/bimmerconnected/bimmer_connected/pull/395?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=bimmerconnected)

```diff
@@            Coverage Diff             @@
##           master     #395      +/-   ##
==========================================
+ Coverage   96.91%   96.93%   +0.02%     
==========================================
  Files           8        8              
  Lines         939      946       +7     
==========================================
+ Hits          910      917       +7     
  Misses         29       29              
```

| Flag | Coverage Δ | |
|---|---|---|
| 3.10.x | `96.82% <100.00%> (+0.02%)` | :arrow_up: |
| 3.6 | `96.92% <100.00%> (+0.02%)` | :arrow_up: |
| 3.7 | `?` | |
| 3.8 | `96.82% <100.00%> (+0.02%)` | :arrow_up: |
| 3.9 | `96.82% <100.00%> (+0.02%)` | :arrow_up: |

Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=bimmerconnected#carryforward-flags-in-the-pull-request-comment) to find out more.

| [Impacted Files](https://codecov.io/gh/bimmerconnected/bimmer_connected/pull/395?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=bimmerconnected) | Coverage Δ | |
|---|---|---|
| [bimmer\_connected/remote\_services.py](https://codecov.io/gh/bimmerconnected/bimmer_connected/pull/395/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=bimmerconnected#diff-YmltbWVyX2Nvbm5lY3RlZC9yZW1vdGVfc2VydmljZXMucHk=) | `95.55% <100.00%> (+0.24%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/bimmerconnected/bimmer_connected/pull/395?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=bimmerconnected).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=bimmerconnected)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/bimmerconnected/bimmer_connected/pull/395?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=bimmerconnected). Last update [42b7386...490b27d](https://codecov.io/gh/bimmerconnected/bimmer_connected/pull/395?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=bimmerconnected). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=bimmerconnected).

Nhubbers: @rikroe Will definitely give this a shot! thanks!

Patch:
diff --git a/bimmer_connected/remote_services.py b/bimmer_connected/remote_services.py
index 99cbd51..954314b 100644
--- a/bimmer_connected/remote_services.py
+++ b/bimmer_connected/remote_services.py
@@ -48,6 +48,7 @@ class _Services(str, Enum):
     REMOTE_DOOR_UNLOCK = 'DOOR_UNLOCK'
     REMOTE_HORN = 'HORN_BLOW'
     REMOTE_AIR_CONDITIONING = 'CLIMATE_NOW'
+    REMOTE_CHARGE_NOW = 'CHARGE_NOW'
 
 
 class RemoteServiceStatus:  # pylint: disable=too-few-public-methods
@@ -134,6 +135,17 @@ class RemoteServices:
         event_id = self._trigger_remote_service(_Services.REMOTE_HORN)
         return self._block_until_done(_Services.REMOTE_HORN, event_id)
 
+    def trigger_charge_now(self) -> RemoteServiceStatus:
+        """Trigger the vehicle to start charging.
+
+        A state update is NOT triggered after this, as the vehicle state is unchanged.
+        """
+        _LOGGER.debug('Triggering charge now')
+        event_id = self._trigger_remote_service(_Services.REMOTE_CHARGE_NOW)
+        result = self._block_until_done(_Services.REMOTE_CHARGE_NOW, event_id)
+        self._trigger_state_update()
+        return result
+
     def trigger_remote_air_conditioning(self) -> RemoteServiceStatus:
         """Trigger the air conditioning to start.
 


Test patch:
diff --git a/test/test_remote_services.py b/test/test_remote_services.py
index ffdba9b..e773f28 100644
--- a/test/test_remote_services.py
+++ b/test/test_remote_services.py
@@ -91,6 +91,7 @@ class TestRemoteServices(TestCase):
             ("CLIMATE_STOP", "trigger_remote_air_conditioning_stop", True),
             ("VEHICLE_FINDER", "trigger_remote_vehicle_finder", False),
             ("HORN_BLOW", "trigger_remote_horn", False),
+            ("CHARGE_NOW", "trigger_charge_now", True),
             ("SEND_POI", "trigger_send_poi", False),
         ]