8000 Replace charging_time_remaining with charging_end_time in bmw_connected_drive by rikroe · Pull Request #60942 · home-assistant/core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Replace charging_time_remaining with charging_end_time in bmw_connected_drive #60942

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Dec 22, 2021

Conversation

rikroe
Copy link
Contributor
@rikroe rikroe commented Dec 3, 2021

Breaking change

charging_time_remaining (in hours) has been replaced with charging_end_time (timestamp) to not clutter the HA state machine. Please calculate the remaining time using HA sensors/automations if needed.

Proposed change

Replace charging_time_remaing (in hours) with charging_end_time (timestamp).
As the BMW API seems to be very flaky and we have to parse the end time from a string like 100% at ~04:01AM, a second sensor charging_end_time_mybmw shows the orignal value extracted from the API.

I originally planned to set the original value as sensor attribute, but as this is not desired added it as a second sensor.
The original value is needed as there are many discussions if the data extracted is correct at all (with some users saying that the BMW API itself returns wrong values which is hard to verify if not easily visible in HA):

Upgrade to bimmer_connected==0.8.6 is needed for this functionality No dependency upgrade needed, as 0.8.6 is already part of 2021.12.4.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue:
  • Link to documentation pull request:

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • The code has been formatted using Black (black --fast homeassistant tests)
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out c 8000 orrectly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.
  • Untested files have been added to .coveragerc.

The integration reached or maintains the following Integration Quality Scale:

  • No score or internal
  • 🥈 Silver
  • 🥇 Gold
  • 🏆 Platinum

To help with the load of incoming pull requests:

@probot-home-assistant
Copy link

Hey there @gerard33, mind taking a look at this pull request as it has been labeled with an integration (bmw_connected_drive) you are listed as a code owner for? Thanks!
(message by CodeOwnersMention)

@rikroe rikroe mentioned this pull request Dec 3, 2021
22 tasks
@MartinHjelmare MartinHjelmare changed the title BMW: Replace charging_time_remaining with charging_end_time Replace charging_time_remaining with charging_end_time in bmw_connected_drive Dec 4, 2021
@rikroe rikroe requested a review from MartinHjelmare December 4, 2021 16:47
Copy link
Member
@MartinHjelmare MartinHjelmare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Let's wait with merging this PR until we merge the other PR, to avoid potential merge conflicts if we want to cherry pick the other PR for the release.

@MartinHjelmare MartinHjelmare marked this pull request as draft December 4, 2021 22:28
@rikroe
Copy link
Contributor Author
rikroe commented Dec 4, 2021

Thanks! Perfectly fine with me.

unit_metric=TIME_HOURS,
unit_imperial=TIME_HOURS,
"charging_end_time": BMWSensorEntityDescription(
key="charging_end_time",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just want to make sure, this returns a UTC datetime timestamp?

Copy link
Contributor Author
@rikroe rikroe Dec 6, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a tz-aware datetime object (https://github.com/bimmerconnected/bimmer_connected/blob/master/bimmer_connected/vehicle_status.py#L452) and displayed the correct time when testing.

EDIT: Nevermind, it is showing a value moved by one hour (CET timezone). I'll update to return UTC.

EDIT²: Nevermind², the tz-aware datetime values are parsed correctly and shown in the entity registry in UTC. If shown via lovelace they are converted to the correct timezone.

@rikroe rikroe force-pushed the mybmw-charing_end_time branch from b584822 to 678db85 Compare December 6, 2021 20:59
@rikroe
Copy link
Contributor Author
rikroe commented Dec 6, 2021

I just found out that I forgot to add something in the library for this to work. I'll have to release a new version before this can be merged.

@rikroe
Copy link
Contributor Author
rikroe commented Dec 7, 2021

Updated the library & adjusted the PR text for the new library changelog & diff.

@rikroe rikroe marked this pull request as ready for review December 7, 2021 20:16
@MartinHjelmare
Copy link
Member

Please rebase on latest dev branch. Then we can merge. 👍

@rikroe rikroe force-pushed the mybmw-charing_end_time branch from 0c7a56e to c510e2a Compare December 9, 2021 18:06
@rikroe
Copy link
Contributor Author
rikroe commented Dec 9, 2021

Rebased and updated the new sensor to SensorDeviceClass.

@rikroe
Copy link
Contributor Author
rikroe commented Dec 9, 2021

I think I just figured out why the time was not reported correctly by the API, however it is not yet merged or released in the library (bimmerconnected/bimmer_connected#382).

Does it make more sense to:

  • Wait with this PR until we have released a new library version and got some feedback?
  • Merge to get the breaking change through and then fix in a coming minor update?

The second option of course only applies if this PR would make it to 2021.12, don't know what your plans are here.

@MartinHjelmare
Copy link
Member

No, this PR won't make the December release tomorrow.

@rikroe
Copy link
Contributor Author
rikroe commented Dec 10, 2021

(y) Thats perfectly fine.
Then I'd like to wait with this PR until I get some feedback from testers using our custom component before merging, as apparently there are some issues that haven't been solved yet.

@MartinHjelmare MartinHjelmare marked this pull request as draft December 10, 2021 08:16
@MartinHjelmare
Copy link
Member

Good. Ping me when we're ready.

@rikroe rikroe force-pushed the mybmw-charing_end_time branch from c510e2a to 34d27bf Compare December 21, 2021 20:28
@rikroe rikroe marked this pull request as ready for review December 21, 2021 20:55
@rikroe
Copy link
Contributor Author
rikroe commented Dec 21, 2021

I think this is ready for HA next.

Just wondered if there is an ADR/general statement that one should use a timestamp instead of a duration (that of course changes all the time, cluttering the state machine). I remember reading something similar for a breaking change to cert_expiry (#42338), but there also not much other support given.

@MartinHjelmare
Copy link
Member
MartinHjelmare commented Dec 22, 2021

Yes, we don't allow relative times in the state machine if the relative time changes just because time passes. If the time measures an interval and only is updated when the device or service feature changes, it may be ok to store that in the state machine. Eg a device was started, ran for 1 min, then stopped, so run time increased by 1 minute. We normally don't want to use seconds as resolution for run times though, as that is normally not interesting and causes not needed state changes. Minutes is ok.

We don't have an ADR for it though.

@MartinHjelmare
Copy link
Member

Should we merge?

@rikroe
Copy link
Contributor Autho 9E81 r
rikroe commented Dec 22, 2021

I've just added half of a sentence to the breaking change section why we are doing it. If that looks fine for you, this is ready to be merged.

Thanks!

@MartinHjelmare MartinHjelmare merged commit 986b60e into home-assistant:dev Dec 22, 2021
@rikroe rikroe deleted the mybmw-charing_end_time branch December 22, 2021 11:56
@github-actions github-actions bot locked and limited conversation to collaborators Dec 23, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0