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 utility_meter on DST changes #129862

Open
wants to merge 7 commits into
base: dev
Choose a base branch
from
Open

Conversation

dgomes
Copy link
Contributor

@dgomes dgomes commented Nov 5, 2024

Breaking change

Proposed change

Due to an underlying unsolved bug in croniter kiorky/croniter#1 that affects DST changes this PR moves to cronsim

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:

Comment on lines 1807 to 1816
async def test_self_reset_hourly_dst2(hass: HomeAssistant) -> None:
"""Test weekly reset of meter in DST change conditions."""

hass.config.time_zone = "Europe/Berlin"
dt_util.set_default_time_zone(dt_util.get_time_zone(hass.config.time_zone))
await _test_self_reset(
hass, gen_config("daily"), "2024-10-26T23:59:00.000000+02:00"
)


Copy link
Contributor

@epenet epenet Nov 5, 2024

Choose a reason for hiding this comment

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

What is this testing?
The test passes locally even without the new dependency and without the code changes.
I would expect the tests to fail without the dependency/code changes, and pass with the dependency/code changes.

Copy link
Contributor Author

@dgomes dgomes Nov 5, 2024

Choose a reason for hiding this comment

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

I was targeting the situation in #129504 which I'm failing to replicate :(

Ended up refactoring the code a bit and updating the dependency instead

@dgomes
Copy link
Contributor Author

dgomes commented Nov 5, 2024

>>> import pytz
>>> tz = pytz.timezone("Europe/Berlin")
>>> schedule = croniter("0 0 * * *", tz.localize(datetime(2024, 10, 26, 23, 59)))
>>> schedule.next(datetime)
datetime.datetime(2024, 10, 27, 0, 0, tzinfo=<DstTzInfo 'Europe/Berlin' CEST+2:00:00 DST>)
>>> schedule.next(datetime)
datetime.datetime(2024, 10, 28, 0, 0, tzinfo=<DstTzInfo 'Europe/Berlin' CET+1:00:00 STD>)

This actually works standalone

@dgomes
Copy link
Contributor Author

dgomes commented Nov 5, 2024

One possibility is to change to https://github.com/cuu508/cronsim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Utility meter with monthly reset resetted one hour too early
2 participants