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

Calculate _attr_native_value when no restore state and appliance is running in Whirlpool #88559

Merged
merged 10 commits into from May 31, 2023

Conversation

mkmer
Copy link
Contributor

@mkmer mkmer commented Feb 21, 2023

Proposed change

Currently, if the appliance is running when the integration is added (aka restore state is None), the time stamp will not be calculated until the appliance finishes a cycle.
This change will allow a time stamp to be set if the appliance is running when the integration is added.

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

  • 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 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

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

Code owner commands

Code owners of whirlpool can trigger bot actions by commenting:

  • @home-assistant close Closes the issue.
  • @home-assistant rename Renames the issue.
  • @home-assistant reopen Reopen the issue.
  • @home-assistant unassign whirlpool Removes the current integration label and assignees on the issue, add the integration domain after the command.

move init at startup if _attr_native_value is None
homeassistant/components/whirlpool/sensor.py Outdated Show resolved Hide resolved
@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.

@home-assistant home-assistant bot marked this pull request as draft February 22, 2023 08:17
@mkmer mkmer marked this pull request as ready for review February 22, 2023 13:33
@mkmer mkmer changed the title Initialize _attr_native_value when no restore state in Whirlpool Calculate _attr_native_value when no restore state in Whirlpool Feb 22, 2023
@mkmer mkmer changed the title Calculate _attr_native_value when no restore state in Whirlpool Calculate _attr_native_value when no restore state and appliance is running in Whirlpool Feb 27, 2023
@mkmer
Copy link
Contributor Author

mkmer commented Apr 10, 2023

I believe the requested changes have been satisfied. What do I need to do to get this over the bar?

@frenck frenck added the smash Indicator this PR is close to finish for merging or closing label Apr 11, 2023
@mkmer
Copy link
Contributor Author

mkmer commented May 23, 2023

Stuck?

@balloob balloob dismissed emontnemery’s stale review May 31, 2023 01:48

Concern addressed

@balloob balloob merged commit bfec3d6 into home-assistant:dev May 31, 2023
24 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 comments in a new PR. Thanks!

if (
isinstance(self._attr_native_value, datetime)
and abs(new_timestamp - self._attr_native_value) > timedelta(seconds=60)
or self._attr_native_value is None
Copy link
Member

Choose a reason for hiding this comment

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

It's more efficient to start with the None check as that is faster than isinstance and Python conditions will short circuit.

await init_integration(hass)
# restore from cache
state = hass.states.get(entity_id)
state.state = "unknown"
Copy link
Member

Choose a reason for hiding this comment

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

Should this be an assertion?

state.state = "unknown"

state = await update_sensor_state(hass, entity_id, mock_sensor1_api)
state.state = datetime.now().isoformat()
Copy link
Member

Choose a reason for hiding this comment

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

This too?

@mkmer mkmer deleted the Whirlpool-Init-when-running branch May 31, 2023 18:11
@mkmer mkmer mentioned this pull request May 31, 2023
20 tasks
@github-actions github-actions bot locked and limited conversation to collaborators Jun 1, 2023
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: whirlpool 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.

None yet

5 participants