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

Clear the Hydrawise next_cycle sensor when the value is unknown #111971

Closed
wants to merge 1 commit into from

Conversation

dknowles2
Copy link
Contributor

Proposed change

If the next_cycle sensor value is unknown, we currently set it to datetime.max. Despite that being a constant value, it causes the sensor entities to update on every data refresh. (See #110054) Setting this to None changes the value to show as "unknown", which should prevent updates. (It's also arguably more correct)

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.
  • Untested files have been added to .coveragerc.

To help with the load of incoming pull requests:

@home-assistant
Copy link

home-assistant bot commented Mar 1, 2024

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

Code owner commands

Code owners of hydrawise 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 hydrawise 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.

@@ -99,4 +97,4 @@ def _update_attrs(self) -> None:
if (next_run := self.zone.scheduled_runs.next_run) is not None:
self._attr_native_value = dt_util.as_utc(next_run.start_time)
else:
self._attr_native_value = datetime.max.replace(tzinfo=dt_util.UTC)
self._attr_native_value = None
Copy link
Member

@Kane610 Kane610 Mar 2, 2024

Choose a reason for hiding this comment

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

I think that the change should be to make the sensor unavailable rather than unknown

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, unavailable is a separate property. None is a perfectly valid value and converts to "unknown". See the test case.

Copy link
Member

Choose a reason for hiding this comment

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

Check this discussion as I think it's equivalent to this. #104522 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, I misunderstood your original comment.

I don't think setting this to unavailable is correct.

https://developers.home-assistant.io/docs/core/entity#generic-properties says "Indicate if Home Assistant is able to read the state and control the underlying device."

In this case, we can read the sensor value just fine--it just doesn't have a value. That's equivalent to None, which equates to "unknown".

Copy link
Member

Choose a reason for hiding this comment

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

Ok! I will leave it up to another member to determine this :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If you're not comfortable reviewing this, can you unassign yourself so someone else can review?

@dknowles2 dknowles2 requested a review from Kane610 March 2, 2024 17:37
@frenck frenck added the smash Indicator this PR is close to finish for merging or closing label Mar 14, 2024
@thomaskistler
Copy link
Contributor

I integrated this change into #116303 since we are already touching all the sensor code there.

@dknowles2 dknowles2 closed this May 10, 2024
@dknowles2 dknowles2 deleted the hydrawise-suspended branch May 10, 2024 12:10
@github-actions github-actions bot locked and limited conversation to collaborators May 11, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bugfix by-code-owner cla-signed has-tests integration: hydrawise Quality Scale: No score small-pr PRs with less than 30 lines. smash Indicator this PR is close to finish for merging or closing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Hydrawise entities showing minutely updates
4 participants