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

Add scene support to roborock #137203

Merged
merged 11 commits into from
Feb 9, 2025
Merged

Add scene support to roborock #137203

merged 11 commits into from
Feb 9, 2025

Conversation

regevbr
Copy link
Contributor

@regevbr regevbr commented Feb 2, 2025

Proposed change

Add ability to start scenes as added in Python-roborock/python-roborock#317

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 Feb 2, 2025

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

Code owner commands

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

@regevbr
Copy link
Contributor Author

regevbr commented Feb 2, 2025

@Lash-L this is still pending the release of the feature, and not yet tested, but I would appreciate your initial review

@allenporter
Copy link
Contributor

I don't think buttons are the right way to surface scenes. Are scene entities a fit for this?

@regevbr
Copy link
Contributor Author

regevbr commented Feb 2, 2025

I don't think buttons are the right way to surface scenes. Are scene entities a fit for this?

No, because ha scenes are for reproducing states of several entities. Here the name is misleading, the app calls it routine or program and it just fires a custom predefined program of the vacuum

@Lash-L
Copy link
Contributor

Lash-L commented Feb 2, 2025

I don't think buttons are the right way to surface scenes. Are scene entities a fit for this?

No, because ha scenes are for reproducing states of several entities. Here the name is misleading, the app calls it routine or program and it just fires a custom predefined program of the vacuum

Allen is a core maintainer and I'm going to defer to him for any entity recommendations or final decisions in that regard. I can do a look through of all roborock logic after an entity is cemented.

The dependency bump will have to split into a separate PR

@allenporter
Copy link
Contributor

I don't think buttons are the right way to surface scenes. Are scene entities a fit for this?

No, because ha scenes are for reproducing states of several entities. Here the name is misleading, the app calls it routine or program and it just fires a custom predefined program of the vacuum

Sticking to the first part: I don't think buttons are the right way to surface this.

@regevbr regevbr changed the title feature: add scene buttons to roborock feature: add scene support to roborock Feb 3, 2025
@regevbr
Copy link
Contributor Author

regevbr commented Feb 3, 2025

Changed to scene.
Once released I will create a separate initial PR to update the version of the lib first

@regevbr
Copy link
Contributor Author

regevbr commented Feb 3, 2025

upgrade pr - #137244

@regevbr
Copy link
Contributor Author

regevbr commented Feb 3, 2025

Validated locally that it works :-)
image

@regevbr regevbr marked this pull request as ready for review February 3, 2025 16:07
@regevbr
Copy link
Contributor Author

regevbr commented Feb 3, 2025

@Lash-L ready for review

@regevbr
Copy link
Contributor Author

regevbr commented Feb 3, 2025

Added tests to fully cover new logic and created PR to update the docs

_LOGGER = logging.getLogger(__name__)


class RoborockRestApi:
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this class is needed. It looks like the API for RoborockApiClient is incorrect and it should take these as constructor arguments like the other clients do.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can you please further explain what you mean and what you need fixing?
I guess you are talking about the fact that a function requires to get the user data as param instead of having it in the constructor?
Even if that was the case, we would still want to wrap the functionality in our own class.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Lash-L thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please further explain what you mean and what you need fixing?

I'm saying make it look how the other APIs look, rather than a new style.

I'm saying (1) remove this class (2) update the class in the upstream library to take these constructors arguments.

I guess you are talking about the fact that a function requires to get the user data as param instead of having it in the constructor?

That's part of it.

Even if that was the case, we would still want to wrap the functionality in our own class.

Why? The other APIs don't have this and call the api directly. I don't see why this is special.

Copy link
Contributor

@Lash-L Lash-L Feb 4, 2025

Choose a reason for hiding this comment

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

update the class in the upstream library to take these constructors arguments

The RoborockApiClient should not take these arguments. As the RoborockApiClient is used for finding out what devices exist in the first place, whereas these parameters imply that you already know what devices you have.

Perhaps the coordinator could just have the api included like is currently done and these functions can live on the coordinator? Not sure - but I also don't think a RoborockRestAPI class needs to exist.

Perhaps the api client could be modified to store the user data once already called? But you would still need to specify the device duid - which would be present in the coordinator already.

The RoborockApiClient (could maybe be renamed to be RoborockWebClient to make things clearer?) is one client for all devices, whereas our other clients are one client for one device

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@home-assistant
Copy link

home-assistant bot commented Feb 4, 2025

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 4, 2025 03:40
@regevbr regevbr marked this pull request as ready for review February 8, 2025 08:44
@home-assistant home-assistant bot requested a review from allenporter February 8, 2025 08:44
),
)
for coordinator, scenes in zip(
config_entry.runtime_data.v1, scene_lists, strict=False
Copy link
Contributor

Choose a reason for hiding this comment

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

My understanding is that strict=False implies its ok for the lists to not have the same length. That should not happen. You added this which wasn't in the example i had -- can you remove or help me understand why this could possibly be OK? It would just introduce bugs if it were true, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was added by automatically by Ruff and I failed to notice it. I chnaged it to True

Copy link
Contributor

@allenporter allenporter left a comment

Choose a reason for hiding this comment

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

The force pushing, or whateve,r is making it difficult to review changes between review rounds.

@regevbr
Copy link
Contributor Author

regevbr commented Feb 9, 2025

The force pushing, or whateve,r is making it difficult to review changes between review rounds.

Yes Im aware, that is why I do a rebase so commit history is kept and should not affect the "changes since last review" methodology.

In any case I need to rebase again now cause there are conflicts with recent changes to his integration that were already emerged. How do you want me to proceed with it?

@Lash-L
Copy link
Contributor

Lash-L commented Feb 9, 2025

Personally @regevbr - I just hit the resolve conflicts button in github or 'update branch' button in github.

@regevbr
Copy link
Contributor Author

regevbr commented Feb 9, 2025

Personally @regevbr - I just hit the resolve conflicts button in github or 'update branch' button in github.

That is what i did

@regevbr regevbr requested a review from allenporter February 9, 2025 18:45
Copy link
Contributor

@allenporter allenporter left a comment

Choose a reason for hiding this comment

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

Oh sorry, i see there there are still conflicts.

@home-assistant home-assistant bot marked this pull request as draft February 9, 2025 19:13
@regevbr regevbr marked this pull request as ready for review February 9, 2025 20:44
@home-assistant home-assistant bot requested a review from allenporter February 9, 2025 20:44
@regevbr
Copy link
Contributor Author

regevbr commented Feb 9, 2025

Oh sorry, i see there there are still conflicts.

resolved

@allenporter allenporter merged commit 379bf10 into home-assistant:dev Feb 9, 2025
32 checks passed
@regevbr regevbr deleted the roborock branch February 9, 2025 21:40
@github-actions github-actions bot locked and limited conversation to collaborators Feb 10, 2025
@allenporter
Copy link
Contributor

@regevbr we decided your original proposal to use buttons was correct. However, given this was late in the release cycle we needed to revert so we can target 2025.4 with this. Are you open to sending another PR to add back to button? If you're annoyed at me understandable :) and i can do it but also wanted your name to be on the feature.

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.

4 participants