jacekk015 / zha_quirks

All quirks in one place
MIT License
144 stars 20 forks source link

Maxsmart set_temperature fails when operation_preset is Boost #28

Closed Kampfgnom closed 1 year ago

Kampfgnom commented 1 year ago

I have _TZE200_uiyqstza devices. When on the TRV the boost mode is enabled (operation_preset), then set_temperature fails with an error. In my setup it is triggered by BetterThermostat.

Because this call fails, the BetterThermostat entity goes into "Unavailable" state.

In my local quirk, I "fixed" this, by simply adding a case for Preset.Boost:

        if attribute == "occupied_heating_setpoint":
            mode = self._attr_cache.get(
                self.attributes_by_name["operation_preset"].id, self.Preset.Schedule
            )
            attribute_mode = None
            if mode == self.Preset.Schedule:
                attribute_mode = "occupied_heating_setpoint_auto"
            elif mode == self.Preset.Manual:
                attribute_mode = "occupied_heating_setpoint_manual"
            elif mode == self.Preset.Boost:
                attribute_mode = "occupied_heating_setpoint_auto"

I am uncertain whether this is the correct way to go. Maybe just return None?

Nov 07 09:23:10 homeassistant homeassistant[576]: 2023-11-07 10:23:10.511 ERROR (MainThread) [custom_components.better_thermostat.utils.controlling] better_thermostat BetterThermostat Wohnzimmer: ERROR controlling: climate.heizung_wohnzimmer_2_thermostat
Nov 07 09:23:10 homeassistant homeassistant[576]: Traceback (most recent call last):
Nov 07 09:23:10 homeassistant homeassistant[576]:   File "/config/custom_components/better_thermostat/utils/controlling.py", line 46, in control_queue
Nov 07 09:23:10 homeassistant homeassistant[576]:     _temp = await control_trv(self, trv)
Nov 07 09:23:10 homeassistant homeassistant[576]:             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Nov 07 09:23:10 homeassistant homeassistant[576]:   File "/config/custom_components/better_thermostat/utils/controlling.py", line 268, in control_trv
Nov 07 09:23:10 homeassistant homeassistant[576]:     await set_temperature(self, heater_entity_id, _temperature)
Nov 07 09:23:10 homeassistant homeassistant[576]:   File "/config/custom_components/better_thermostat/utils/bridge.py", line 77, in set_temperature
Nov 07 09:23:10 homeassistant homeassistant[576]:     return await self.real_trvs[entity_id]["adapter"].set_temperature(
Nov 07 09:23:10 homeassistant homeassistant[576]:            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Nov 07 09:23:10 homeassistant homeassistant[576]:   File "/config/custom_components/better_thermostat/adapters/generic.py", line 111, in set_temperature
Nov 07 09:23:10 homeassistant homeassistant[576]:     await self.hass.services.async_call(
Nov 07 09:23:10 homeassistant homeassistant[576]:   File "/usr/src/homeassistant/homeassistant/core.py", line 2035, in async_call
Nov 07 09:23:10 homeassistant homeassistant[576]:     response_data = await coro
Nov 07 09:23:10 homeassistant homeassistant[576]:                     ^^^^^^^^^^
Nov 07 09:23:10 homeassistant homeassistant[576]:   File "/usr/src/homeassistant/homeassistant/core.py", line 2072, in _execute_service
Nov 07 09:23:10 homeassistant homeassistant[576]:     return await target(service_call)
Nov 07 09:23:10 homeassistant homeassistant[576]:            ^^^^^^^^^^^^^^^^^^^^^^^^^^
Nov 07 09:23:10 homeassistant homeassistant[576]:   File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 235, in handle_service
Nov 07 09:23:10 homeassistant homeassistant[576]:     return await service.entity_service_call(
Nov 07 09:23:10 homeassistant homeassistant[576]:            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Nov 07 09:23:10 homeassistant homeassistant[576]:   File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 876, in entity_service_call
Nov 07 09:23:10 homeassistant homeassistant[576]:     response_data = await _handle_entity_call(
Nov 07 09:23:10 homeassistant homeassistant[576]:                     ^^^^^^^^^^^^^^^^^^^^^^^^^^
Nov 07 09:23:10 homeassistant homeassistant[576]:   File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 948, in _handle_entity_call
Nov 07 09:23:10 homeassistant homeassistant[576]:     result = await task
Nov 07 09:23:10 homeassistant homeassistant[576]:              ^^^^^^^^^^
Nov 07 09:23:10 homeassistant homeassistant[576]:   File "/usr/src/homeassistant/homeassistant/components/climate/__init__.py", line 632, in async_service_temperature_set
Nov 07 09:23:10 homeassistant homeassistant[576]:     await entity.async_set_temperature(**kwargs)
Nov 07 09:23:10 homeassistant homeassistant[576]:   File "/usr/src/homeassistant/homeassistant/components/zha/climate.py", line 459, in async_set_temperature
Nov 07 09:23:10 homeassistant homeassistant[576]:     await self._thrm.async_set_heating_setpoint(
Nov 07 09:23:10 homeassistant homeassistant[576]:   File "/usr/src/homeassistant/homeassistant/components/zha/core/cluster_handlers/hvac.py", line 251, in async_set_heating_setpoint
Nov 07 09:23:10 homeassistant homeassistant[576]:     await self.write_attributes_safe({attr: temperature})
Nov 07 09:23:10 homeassistant homeassistant[576]:   File "/usr/src/homeassistant/homeassistant/components/zha/core/cluster_handlers/__init__.py", line 518, in write_attributes_safe
Nov 07 09:23:10 homeassistant homeassistant[576]:     res = await self.write_attributes(attributes, manufacturer=manufacturer)
Nov 07 09:23:10 homeassistant homeassistant[576]:           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Nov 07 09:23:10 homeassistant homeassistant[576]:   File "/usr/src/homeassistant/homeassistant/components/zha/core/cluster_handlers/__init__.py", line 84, in wrapper
Nov 07 09:23:10 homeassistant homeassistant[576]:     return await RETRYABLE_REQUEST_DECORATOR(func)(*args, **kwargs)
Nov 07 09:23:10 homeassistant homeassistant[576]:            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Nov 07 09:23:10 homeassistant homeassistant[576]:   File "/usr/local/lib/python3.11/site-packages/zigpy/util.py", line 138, in retry
Nov 07 09:23:10 homeassistant homeassistant[576]:     return await func()
Nov 07 09:23:10 homeassistant homeassistant[576]:            ^^^^^^^^^^^^
Nov 07 09:23:10 homeassistant homeassistant[576]:   File "/usr/local/lib/python3.11/site-packages/zhaquirks/tuya/__init__.py", line 715, in write_attributes
Nov 07 09:23:10 homeassistant homeassistant[576]:     new_attrs = self.map_attribute(attr_name, record.value.value)
Nov 07 09:23:10 homeassistant homeassistant[576]:                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Nov 07 09:23:10 homeassistant homeassistant[576]:   File "/config/zha_quirks/ts0601_trv_maxsmart.py", line 624, in map_attribute
Nov 07 09:23:10 homeassistant homeassistant[576]:     self.DIRECT_MAPPING_ATTRS[attribute_mode][0]: value
Nov 07 09:23:10 homeassistant homeassistant[576]:     ~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^
Nov 07 09:23:10 homeassistant homeassistant[576]: KeyError: None
jacekk015 commented 1 year ago

Added your solution to the quirk code. To be honest - I have only Maxsmart TRV's and never used boost function after I've coded that. If that works for you it should be good.