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 a "Calibrate" Button for Shelly Cover Entities #114632

Open
SaSa1983 opened this issue Apr 2, 2024 · 8 comments
Open

Add a "Calibrate" Button for Shelly Cover Entities #114632

SaSa1983 opened this issue Apr 2, 2024 · 8 comments

Comments

@SaSa1983
Copy link
Contributor

SaSa1983 commented Apr 2, 2024

The problem

From time to time covers may need to be recalibrated.
Thus it would be nice to have a configuration button entity alongside the cover entity itself.
This is only required if the Shelly device has type "roller" and supports positioning.

In this case it would be nice to have a button which triggers Sheely Cover.Calibrate

What version of Home Assistant Core has the issue?

2024.3.3

What was the last working version of Home Assistant Core?

2024.3.3

What type of installation are you running?

Home Assistant OS

Integration causing the issue

Shelly

Link to integration documentation on our website

https://www.home-assistant.io/integrations/shelly/

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

No response

@home-assistant
Copy link

home-assistant bot commented Apr 2, 2024

Hey there @balloob, @bieniu, @thecode, @chemelli74, @bdraco, mind taking a look at this issue as it has been labeled with an integration (shelly) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of shelly can trigger bot actions by commenting:

  • @home-assistant close Closes the issue.
  • @home-assistant rename Awesome new title Renames the issue.
  • @home-assistant reopen Reopen the issue.
  • @home-assistant unassign shelly Removes the current integration label and assignees on the issue, 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 issue.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


shelly documentation
shelly source
(message by IssueLinks)

@SaSa1983
Copy link
Contributor Author

SaSa1983 commented Apr 2, 2024

I already figured that I just need to add a button to the "BUTTONS" list in homeassistant/components/shelly/button.py
But I am unsure about the lambda expressions, since I'm currently in office and do not have access to my Python IDE

@SaSa1983
Copy link
Contributor Author

SaSa1983 commented Apr 2, 2024

My assumption is that I need to do something like this (pseudo-code) for execution:

if (is_instance(coordinator.device, BlockDevice)) {
  # In Gen 1devices it is always index 0
  coordinator.device.http_request("get", "roller/0/calibrate")
}
else {
  coordinator.device.call_rpc(("Cover.Calibrate", {"id": coordinator.device.status["id"]})
}

and something like this (pseudo-code) for supported: 

if (is_instance(coordinator.device, BlockDevice)) {
# In Gen 1devices it is always index 0
  return coordinator.device.settings["rollers"] is not None and coordinator.device.settings["rollers"][0]["positioning"] is True
}
else {
  return coordinator.device.status["pos_control"] is True
}

@SaSa1983
Copy link
Contributor Author

SaSa1983 commented Apr 2, 2024

My guess for the button is:


    ShellyButtonDescription[ShellyBlockCoordinator | ShellyRpcCoordinator](
        key="calibrate",
        name="Calibrate",
        translation_key="calibrate",
        entity_category=EntityCategory.CONFIG,
        press_action=lambda coordinator: 
            coordinator.device.call_rpc("Cover.Calibrate", {"id": coordinator.device.status["id"]})
            if isinstance(coordinator, ShellyRpcCoordinator)
            else coordinator.device.http_request("get", "roller/0/calibrate"),
        supported=lambda coordinator: 
            coordinator.device.status["pos_control"]
            if isinstance(coordinator, ShellyRpcCoordinator)
            else coordinator.device.settings["rollers"] is not None and coordinator.device.settings["rollers"][0]["positioning"]
    ),

@SaSa1983
Copy link
Contributor Author

SaSa1983 commented Apr 2, 2024

We could define a method calibrate_cover(self) -> None and is_cover_calibration_supported(self) -> bool
in the ShellyBlockCoordinator and the ShellyRpcCoordinator

and use coordinator.is_cover_calibration_supported() for supported lambda expression and
coordinator.calibrate_cover() for press_action lambda expression

@bieniu
Copy link
Member

bieniu commented Apr 2, 2024

This is a pretty good idea for a new feature. A few comments from me:

  • press_action should be implemented as a device class method in the aioshelly backend library
  • the lambda for supported needs simplification or a dedicated function as you proposed
  • we have to remember that there are gen2+ devices which support two rollers

Since you have started to analyze this feature and I assume that you have devices on which you can test it, I encourage you to open a pull request with this change.

@SaSa1983
Copy link
Contributor Author

I currently only have Gen1 Devices. I'm using a shelly 2.5. But sure, I could test this at least with the Gen1 Device.

@SaSa1983
Copy link
Contributor Author

I currently only have Gen1 Devices. I'm using a shelly 2.5. But sure, I could test this at least with the Gen1 Device. But since not having Gen2 / Gen3 devices I'm unable to test any implementation against it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants