gurumitts / pylutron-caseta

Apache License 2.0
153 stars 98 forks source link

Serena wood blinds 405 MethodNotAllowed when setting the position #142

Closed dzink3 closed 3 months ago

dzink3 commented 1 year ago

When setting the position of one of the serena wood blinds I get a 405 MethodNotAllowed exception. The logs show the following stack trace:

Logger: homeassistant.components.websocket_api.http.connection
Source: components/lutron_caseta/cover.py:80
Integration: Home Assistant WebSocket API (documentation, issues)
First occurred: 9:42:01 PM (4 occurrences)
Last logged: 9:42:08 PM

[547747776496] 405 MethodNotAllowed
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 199, in handle_call_service
    await hass.services.async_call(
  File "/usr/src/homeassistant/homeassistant/core.py", line 1849, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1889, in _execute_service
    await cast(Callable[[ServiceCall], Awaitable[None]], handler.job.target)(
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 226, in handle_service
    await service.entity_service_call(
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 798, in entity_service_call
    future.result()  # pop exception if have
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 980, in async_request_call
    await coro
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 838, in _handle_entity_call
    await result
  File "/usr/src/homeassistant/homeassistant/components/lutron_caseta/cover.py", line 80, in async_set_cover_position
    await self._smartbridge.set_value(self.device_id, position)
  File "/usr/local/lib/python3.10/site-packages/pylutron_caseta/smartbridge.py", line 345, in set_value
    await self._request(
  File "/usr/local/lib/python3.10/site-packages/pylutron_caseta/smartbridge.py", line 258, in _request
    raise BridgeResponseError(response)
pylutron_caseta.BridgeResponseError: 405 MethodNotAllowed

I can open and close the blinds fully with the respective buttons, just not setting them to a state in between.

Is this an issue with my setup? Or is this an issue with the integration of serena wood blinds?

Thanks!

swails commented 1 year ago

I'm pretty sure wood blinds allow you to set the tilt, not the position.

dzink3 commented 1 year ago

Yes, my language might not have been clear. With position I meant the tilt. When I was following the integration of these wood blinds, it sounded like some of the positioning functions of shades can be reused for the wood blinds and they would make the blinds tilt to certain angles. I am trying to confirm whether some part of the implementation is not working correctly or whether my setup is not correct.

Maybe some more details on my setup: I am using home assistant with the lutron caseta integration. A year ago I tried to add the wood blinds, but the integration was still missing. Last month I updated to the newer versions and the wood blinds were detected and showed up in home assistant. Again, if I fully open or close them through home assistant everything is working, however if I use the slider to set a tilt in between, I get the above exception.

swails commented 1 year ago

I suspect that the integration is trying to set position rather than tilt. The response from the bridge (405 Not Implemented) is what you'd expect to get back when you try a method that isn't supported in a RESTful service (the LEAP service is designed to be RESTful).

I suspect "Open" and "Closed" work because they're special-cases. However, anything else is probably (erroneously) sent as GoToPosition (or something like that), while it should be sent as GoToTilt.

Exact names may well be (and probably are) wrong, but that's the basic idea.

dzink3 commented 1 year ago

I see! This is what was described in this thread I guess: https://github.com/gurumitts/pylutron-caseta/pull/89.

I was under the impression that the code would check what type of blind it is (e.g., by checking device['tilt'] is not None) and then call the right function accordingly. But it seems I would have to do that myself, is that right?

I don't have much experience with HA, but do I have to write my own scripts to call the right functions? Some rough pointers would be greatly appreciated!

dzink3 commented 1 year ago

I think my issue is the same as the one reported here: https://github.com/home-assistant/core/issues/81525.

If I follow the stack trace, it seems that in pylutron_caseta/smartbridge.py the function set_value is called, not set_tilt. From this comment (https://github.com/gurumitts/pylutron-caseta/pull/89#issuecomment-1132333127), it sounds like one could distinguish on the device object which blind it is and redirect to the set_tilt function accordingly. The other alternative would be to call the set_tilt function directly from HA (instead of going through the set_value function at all). Which route to take seems to be a higher level design question that is hard to answer without knowledge of the project, but I am happy to try either way. Maybe @swails or @mdonoughe could help with what path is appropriate here.

wujiaqi commented 5 months ago

I have a PR open here to address tilt functionality in serena wood blinds https://github.com/home-assistant/core/pull/113791, it works in my local testing. I'm using the latter method, to call set_tilt from HA rather than set_value

dzink3 commented 5 months ago

Hey @wujiaqi, That's fantastic news! Thank you for putting the work in to fix this and for letting me know! Is there anything I can help with to get this landed?

wujiaqi commented 5 months ago

The PR was merged, I'm new to the HA project so I don't know the full release train, but my hope is that it's pending to make it to a release!

wujiaqi commented 4 months ago

It looks like the change is now present in the latest HA core release. I see the UI change and it works now. However it seems like blinds do not work with Google Home via Nabu Casa, as I see a separate issue related to this https://community.home-assistant.io/t/blinds-not-controllable-via-google-assistant-nabu-casa-user/420859/7