Skip to content
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

Fix Tibber get_prices when called with aware datetime #123289

Merged
merged 5 commits into from
Oct 2, 2024

Conversation

functionpointer
Copy link
Contributor

@functionpointer functionpointer commented Aug 7, 2024

Proposed change

Change tibber.get_prices action to accept both aware and naive datetimes, in addition to simple dates.

I have implemented this by changing __get_date() to always output aware datetimes, and then modifying __get_prices() to work with that. Naive datetimes and simple dates are interpreted to be in the default timezone, by using as_local() from homeassistant.utils.dt

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)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

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
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format 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 correctly.
    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.

To help with the load of incoming pull requests:

@home-assistant
Copy link

home-assistant bot commented Aug 7, 2024

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

Code owner commands

Code owners of tibber can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign tibber Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the pull request.

@functionpointer functionpointer force-pushed the tibber-prices-aware branch 2 times, most recently from 9c12522 to 2e6effc Compare August 7, 2024 12:37
@MartinHjelmare MartinHjelmare changed the title Tibber: Fix get_prices when called with aware datetime Fix Tibber get_prices when called with aware datetime Aug 7, 2024
@frenck frenck added the smash Indicator this PR is close to finish for merging or closing label Aug 8, 2024
@functionpointer

This comment was marked as off-topic.

@functionpointer

This comment was marked as off-topic.

@functionpointer

This comment was marked as off-topic.

@frenck
Copy link
Member

frenck commented Sep 23, 2024

@functionpointer Please don't ping people for reviews. The PR is in the queue and will be picked up eventually. If the PR needs attention from someone specific, the bot will ping instead.

Thanks! 👍

../Frenck

@home-assistant home-assistant bot marked this pull request as draft September 25, 2024 08:51
@home-assistant
Copy link

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍

Learn more about our pull request process.

@edenhaus edenhaus removed the smash Indicator this PR is close to finish for merging or closing label Sep 25, 2024
@functionpointer functionpointer marked this pull request as ready for review September 25, 2024 11:12
@home-assistant home-assistant bot marked this pull request as draft September 25, 2024 11:27
@functionpointer functionpointer marked this pull request as ready for review September 25, 2024 11:40
@frenck frenck added this to the 2024.10.0 milestone Sep 27, 2024
Copy link
Contributor

@edenhaus edenhaus left a comment

Choose a reason for hiding this comment

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

Thanks @functionpointer 👍

@edenhaus edenhaus merged commit 5bd2d27 into home-assistant:dev Oct 2, 2024
30 checks passed
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.

Please address the comment in a new PR. Thanks!

freezer.move_to(STARTTIME)
call = ServiceCall(DOMAIN, PRICE_SERVICE_NAME, {"start": start_time})

result = await __get_prices(call, hass=create_mock_hass())
Copy link
Member

@MartinHjelmare MartinHjelmare Oct 2, 2024

Choose a reason for hiding this comment

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

Please test the services by calling the services from the core service registry, while patching the library. Use hass.services.async_call.

https://developers.home-assistant.io/docs/development_testing#writing-tests-for-integrations

Set up integration with a MockConfigEntry while patching the library client, and then call the service.

frenck pushed a commit that referenced this pull request Oct 2, 2024
* Tibber: Add extra test to expose aware/naive datetime issue

* Tibber: Fix get_prices action not working with aware datetimes

* Tibber: Simplify comparison

* Tibber: Combine timezone tests into single parametrized one

* Tibber: Split test again to prevent if statement
@github-actions github-actions bot locked and limited conversation to collaborators Oct 3, 2024
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.

Tibber can't compare offset-naive and offset-aware datetimes
5 participants