RobertD502 / home-assistant-flair

Custom component for Home Assistant Core for Flair pucks, vents, rooms, structures, and minisplits
MIT License
87 stars 12 forks source link

Changing Flair puck thermostat set point while it is off returns a 422 error #30

Closed fcfort closed 1 year ago

fcfort commented 1 year ago

If the Flair Puck is in "off" mode, changing the set point temperature returns an error message to the UI. See screenshot below for an example.

This does not happen with my ecobee thermostat for instance. Instead the temperature set point is changed but the ecobee thermostat stays in the "off" state.

A better experience would be to either not allow the change or to reject the change in set point rather than return an error.

Screen Shot 2022-08-10 at 13 14 01

Complete error message:

Log Details (ERROR)
Logger: homeassistant.components.websocket_api.http.connection
Source: custom_components/flair/climate.py:393
Integration: Home Assistant WebSocket API ([documentation](https://www.home-assistant.io/integrations/websocket_api), [issues](https://github.com/home-assistant/home-assistant/issues?q=is%3Aissue+is%3Aopen+label%3A%22integration%3A+websocket_api%22))
First occurred: 1:13:46 PM (2 occurrences)
Last logged: 1:13:59 PM

[2795027400] ApiError<HTTP Response: 422>
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 1713, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1750, in _execute_service
    await cast(Callable[[ServiceCall], Awaitable[None]], handler.job.target)(
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 204, in handle_service
    await service.entity_service_call(
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 676, in entity_service_call
    future.result()  # pop exception if have
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 930, in async_request_call
    await coro
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 713, in _handle_entity_call
    await result
  File "/usr/src/homeassistant/homeassistant/components/climate/__init__.py", line 588, in async_service_temperature_set
    await entity.async_set_temperature(**kwargs)
  File "/usr/src/homeassistant/homeassistant/components/climate/__init__.py", line 446, in async_set_temperature
    await self.hass.async_add_executor_job(
  File "/usr/local/lib/python3.10/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/flair/climate.py", line 393, in set_temperature
    self._hvac_unit.set_hvac_temp(temp)
  File "/usr/local/lib/python3.10/site-packages/flair/hvac_units/hvac_unit.py", line 186, in set_hvac_temp
    self.api.control_hvac(self, HVAC_UNITS, attributes, relationships)
  File "/usr/local/lib/python3.10/site-packages/flair/flair_helper.py", line 230, in control_hvac
    self.client.update(resource_type, id, attributes, relationships)
  File "/usr/local/lib/python3.10/site-packages/hass_flair_api/client.py", line 248, in update
    return self.handle_resp(
  File "/usr/local/lib/python3.10/site-packages/hass_flair_api/client.py", line 339, in handle_resp
    raise ApiError(resp)
hass_flair_api.client.ApiError: ApiError<HTTP Response: 422>
RobertD502 commented 1 year ago

When you say the puck is in "off" mode, are you referring to the minisplit or AC unit that you're controlling with the puck being in off mode?

Edit: Disregard. I was on mobile and missed your log which shows you're talking about HVAC unit control. Flair is a bit odd as it doesn't allow setting temp on HVAC units if the HVAC mode is set to off - not sure why they chose this design as plenty of units support setting temp while off which is what Sensibo does just fine.

However, I do agree that I should handle this error better instead of letting the backend client that they wrote handle the exception. I believe the best thing to do is to remove being able to set the temperature when the mode is off since Flair doesn't support this feature.

I'm actually in the middle of a full rewrite. I have written a new asynchronous library that utilizes OAuth2 tokens and am ~50% done rewriting the home assistant Flair integration to use this new library. I'll keep in mind what you just brought up and will remove setting the temp as an option when the mode is set to off.

If you happen to have your OAuth2 credentials from Flair....would you be up for testing out the integration once I'm done writing it? I'm always in need of individuals that use the pucks for IR control.

fcfort commented 1 year ago

Yes please, happy to be a beta tester.

RobertD502 commented 1 year ago

@fcfort Pre-Release is live. You can access the update by setting the switch "Show beta versions" to On for the Flair integration within HACS:

image

Post any bugs/discussion regarding 0.1.0 to the 0.1.0 Discussion.