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

Readings obtained twice in six minutes #361

Open
ArchaicRider opened this issue Sep 19, 2023 · 0 comments
Open

Readings obtained twice in six minutes #361

ArchaicRider opened this issue Sep 19, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@ArchaicRider
Copy link

I've enabled debugging and have been reading the logs for this integration and noticed that it obtains readings at 0 & 5 mins along with 30 & 35 mins past the hour. My HA is a lightly loaded system not really doing much as I learn about the system.

A few days later I noticed this was not happening, just one reading at each of 3 & 33 mins past the hour.

I've managed to reproduce the duplication in the logs by restarting my HA at exactly zero seconds on the hour e.g. 11:00:00

I would expect the integration to trigger once in the period 0-5 mins past the hour and once in the period 30-35 mins past the hour.

This with version 1.0.3

I think that I've found the problem in the sensor.py

async def should_update() -> bool:
"""Check if time is between 0-5 or 30-35 minutes past the hour."""
minutes = datetime.now().minute
if (0 <= minutes <= 5) or (30 <= minutes <= 35):
return True
return False

If this code is called every 5 minutes starting at zero minutes past the hour it will return true four times an hour (0,5,30,35), rather than the required two.

This is because minutes is an integer and the criteria in the if statement each catch a six minute period.

Changing the code to...

async def should_update() -> bool:
"""Check if time is between 1-5 or 31-35 minutes past the hour."""
minutes = datetime.now().minute
if (1 <= minutes <= 5) or (31 <= minutes <= 35):
return True
return False

Would stop the extra runs, I think.

AR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant