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

Ecovacs position sensor #117697

Closed
wants to merge 27 commits into from
Closed

Conversation

lnx85
Copy link

@lnx85 lnx85 commented May 18, 2024

Breaking change

Proposed change

Add position sensors (last_position and charger_position)
Add update_positions command

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:

Link to documentation PR: home-assistant/home-assistant.io#32831

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 @OverloadUT, @mib1185, @edenhaus, @Augar, mind taking a look at this pull request as it has been labeled with an integration (ecovacs) you are listed as a code owner for? Thanks!

Code owner commands

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

Copy link
Contributor

@mib1185 mib1185 left a comment

Choose a reason for hiding this comment

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

Hi @lnx85

thanks for your contribution, but i've concerns about these sensors and their intention. I think this functionality should be implemented as an integration service with response data.

homeassistant/components/ecovacs/sensor.py Outdated Show resolved Hide resolved
homeassistant/components/ecovacs/sensor.py Outdated Show resolved Hide resolved
homeassistant/components/ecovacs/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 May 18, 2024 16:22
@lnx85
Copy link
Author

lnx85 commented May 18, 2024

Hi @lnx85

thanks for your contribution, but i've concerns about these sensors and their intention. I think this functionality should be implemented as an integration service with response data.

@mib1185 With deebot_client I can send the GetPos() command, but the related response is triggered as an event on the event_bus and it is not directly returned by the command call.
How can I implement a service with response if my call don't get a direct response?

Co-authored-by: Michael <35783820+mib1185@users.noreply.github.com>
@mib1185
Copy link
Contributor

mib1185 commented May 18, 2024

What is the intention or use case for these sensors?
Maybe a combination of a event and an event entity can fullfill the use-case?

@lnx85
Copy link
Author

lnx85 commented May 18, 2024

Before this integration became part of the HA core, I was using the getPos custom command to get the bot coordinates and track its position on a map.

You can also trigger automations based on bot position if you know room bounds.

I can try implementing the same feature by using an Event entity. I'm also waiting for a PR on deebot_client library which includes the bot direction (0..360deg) that can be exported in addition to bot coordinates (x,y).

@mib1185
Copy link
Contributor

mib1185 commented May 19, 2024

i'm not familiar with the former custom component, nor these new ecovacs devices (still own a quiet old and "stupid" deebot slim 🙈)
But i would guess, that the tracking on the map was not done by the custom integration, but the device itself and than just updated the map image which is shown in HA? 🤔 @edenhaus what do you think?

@lnx85
Copy link
Author

lnx85 commented May 19, 2024

@mib1185 In my use case position is used to track the bot on a custom home map, not the original one.

I can achieve the same goal if the custom_command is not limited to dict (GetPos command requires a list of args) and if custom_command response is available as it was in the previous version of the integration (when in was a custom_component and not in the HA core)

@edenhaus
Copy link
Contributor

With deebot_client I can send the GetPos() command, but the related response is triggered as an event on the event_bus and it is not directly returned by the command call

With some changes in the dependency and HA ecovacs integration, it is possible to return the response for any command.

homeassistant/components/ecovacs/vacuum.py Outdated Show resolved Hide resolved
homeassistant/components/ecovacs/vacuum.py Outdated Show resolved Hide resolved
homeassistant/components/ecovacs/sensor.py Outdated Show resolved Hide resolved
@lnx85
Copy link
Author

lnx85 commented May 19, 2024

Sensors removed, event entity added.

There's one problem left: getPos command is called only at device init and if you want to update the position you have to call the command yourself.

Do I need to write a new service?

Copy link
Contributor

@edenhaus edenhaus left a comment

Choose a reason for hiding this comment

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

Will discuss this PR internally if we should allow adding entities for any command or if they will be only available as service responses
I have the feeling that with this PR soon or later other commands will be added as entities (example the trace of the vacuum)

homeassistant/components/ecovacs/event.py Show resolved Hide resolved
homeassistant/components/ecovacs/const.py Outdated Show resolved Hide resolved
homeassistant/components/ecovacs/event.py Show resolved Hide resolved
homeassistant/components/ecovacs/event.py Show resolved Hide resolved
tests/components/ecovacs/snapshots/test_sensor.ambr Outdated Show resolved Hide resolved
async def on_event(event: PositionsEvent) -> None:
"""Handle event."""
event_data: dict[str, dict] = {
position.type.name.lower(): {
Copy link
Contributor

Choose a reason for hiding this comment

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

The positions in PositionsEvent are on purpose a list as someone could have multiple charges, which this entity currently does not support.

Please don't make any changes to this PR until I have discussed it internally and come back to you. So we don't waste your time ;)

@edenhaus
Copy link
Contributor

I discussed it internally, and we don't accept the creation of entities for command responses as it will be used only in specific use cases, and it will lead to the entity creation for any command, which is something we don't want.
Please use command responses instead.

To add support for command responses, changes in the library are required. Feel free to open a PR for it :)
I'm currently short on time, so I can't implement it myself, but I will take the time to review it or answer any questions.

I will close this PR as we need to add support for it in the library first.

@edenhaus edenhaus closed this May 21, 2024
@lnx85
Copy link
Author

lnx85 commented May 21, 2024

I discussed it internally, and we don't accept the creation of entities for command responses as it will be used only in specific use cases, and it will lead to the entity creation for any command, which is something we don't want. Please use command responses instead.

To add support for command responses, changes in the library are required. Feel free to open a PR for it :) I'm currently short on time, so I can't implement it myself, but I will take the time to review it or answer any questions.

I will close this PR as we need to add support for it in the library first.

@edenhaus I opened a new thread on deebot_client: DeebotUniverse/client.py#507

@lnx85 lnx85 deleted the ecovacs-position-sensor branch May 21, 2024 15:23
@github-actions github-actions bot locked and limited conversation to collaborators May 22, 2024
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.

None yet

4 participants