home-assistant / frontend

:lollipop: Frontend for Home Assistant
https://demo.home-assistant.io
Other
3.98k stars 2.71k forks source link

Climate more-info view doesn't fallback to temperature setpoint if `TARGET_HUMIDITY` is removed from `supported_features` #21414

Closed mill1000 closed 2 months ago

mill1000 commented 2 months ago

Checklist

Describe the issue you are experiencing

Background I'm developing a climate integration that only supports a target humidity in certain HVAC modes. i.e. 'Dry' mode.

I've tried to represent this by adding ClimateEntityFeature.TARGET_HUMIDITY to supported_features when the HVAC mode is set to 'Dry'. At first, this works as expected. The climate entity only shows a temperature setpoint until the mode is set to 'Dry', upon which the humidity setpoint becomes available.

The Issue The problem occurs when the more-info view is set to adjust the humidity setpoint, and the HVAC mode is changed from 'Dry' to any other mode. The view fails to fallback to the temperature setpoint leaving the user unable to adjust the temperature until the view is closed and re-opened.

Easiest to see via a GIF. ac_dry_setpoint

Describe the behavior you expected

The view should fallback to the temperature setpoint.

Steps to reproduce the issue

  1. Have a climate entity that conditionally supports TARGET_HUMIDITY.
  2. Open the more-info view, switch to humidity setpoint.
  3. Remove TARGET_HUMIDITY from supported features.
  4. Observe that more-info view can't adjust any setpoint.

What version of Home Assistant Core has the issue?

2024.7.2

What was the last working version of Home Assistant Core?

No response

In which browser are you experiencing the issue with?

Firefox 127, Chrome 126.0.6478.127

Which operating system are you using to run this browser?

Windows 10 Pro 22H2 19045.4598

State of relevant entities

Attributes in dry mode

hvac_modes: auto, cool, dry, heat, fan_only, off 
min_temp: 61 
max_temp: 86 
target_temp_step: 1 
min_humidity: 30 
max_humidity: 99 
fan_modes: auto, high, medium, low, silent 
preset_modes: none, eco 
swing_modes: off, vertical, horizontal, both 
current_temperature: null 
temperature: 63 
current_humidity: 67 
humidity: 40 
fan_mode: auto 
preset_mode: none 
swing_mode: off 
follow_me: false 
friendly_name: Midea AC 123 
supported_features: 445

Attributes in cool mode

hvac_modes: auto, cool, dry, heat, fan_only, off
min_temp: 61
max_temp: 86
target_temp_step: 1
fan_modes: auto, high, medium, low, silent
preset_modes: none, eco, sleep, boost
swing_modes: off, vertical, horizontal, both
current_temperature: null
temperature: 63
current_humidity: 67
fan_mode: auto
preset_mode: none
swing_mode: off
follow_me: false
friendly_name: Midea AC 123
supported_features: 441

Problem-relevant frontend configuration

N/A

Javascript errors shown in your browser console/inspector

None

Additional information

No response

piitaya commented 2 months ago

We should check that with core but I'm not sure it's a best practice to change the supported features based on state.

mill1000 commented 2 months ago

Yeah that's fair. I took a quick look and found some other implementations that change supported_features on the fly, but it would be good to get confirmation if its unintended behavior.

piitaya commented 2 months ago

According to the documentation : https://developers.home-assistant.io/docs/core/entity/#generic-properties

It's allowed to change device_class, supported_features or any property included in a domain's capability_attributes. However, since these entity properties often are not expected to change at all and some entity consumers may not be able to update them at a free rate, we recommend only changing them when absolutely required and at a modest interval.

As an example, such changes will cause voice assistant integrations to resynchronize with the supporting cloud service.

Can you point out which integration that change supported_features?

Supported features are also used in service actions. By doing this, you won't be able to create a automation that change the target humidity if the entity is not in dry mode when you're building your automation for example.

mill1000 commented 2 months ago

Can you point out which integration that change supported_features?

Sure. Here's a few I found.

Aprilaire https://github.com/home-assistant/core/blob/72d37036b9c6a70fee4540b32bbbd0a76aa94319/homeassistant/components/aprilaire/climate.py#L96-L110

    def supported_features(self) -> ClimateEntityFeature:
        """Get supported features."""
        features = 0

        if self.coordinator.data.get(Attribute.MODE) == 5:
            features = features | ClimateEntityFeature.TARGET_TEMPERATURE_RANGE
        else:
            features = features | ClimateEntityFeature.TARGET_TEMPERATURE

        if self.coordinator.data.get(Attribute.HUMIDIFICATION_AVAILABLE) == 2:
            features = features | ClimateEntityFeature.TARGET_HUMIDITY

        features = features | ClimateEntityFeature.PRESET_MODE

        return features | ClimateEntityFeature.FAN_MODE

Coolmaster https://github.com/home-assistant/core/blob/72d37036b9c6a70fee4540b32bbbd0a76aa94319/homeassistant/components/coolmaster/climate.py#L67-L77

    def supported_features(self) -> ClimateEntityFeature:
        """Return the list of supported features."""
        supported_features = (
            ClimateEntityFeature.TARGET_TEMPERATURE
            | ClimateEntityFeature.FAN_MODE
            | ClimateEntityFeature.TURN_OFF
            | ClimateEntityFeature.TURN_ON
        )
        if self.swing_mode:
            supported_features |= ClimateEntityFeature.SWING_MODE
        return supported_features

iZone https://github.com/home-assistant/core/blob/12ec66c2c293a080dc43048782a15f6de3892116/homeassistant/components/izone/climate.py#L512-L516

    def supported_features(self) -> ClimateEntityFeature:
        """Return the list of supported features."""
        if self._zone.mode == Zone.Mode.AUTO:
            return self._attr_supported_features
        return self._attr_supported_features & ~ClimateEntityFeature.TARGET_TEMPERATURE

Ecoobee (Maybe)

Unsure about this one, has_humidifier_control might be a static value in which case the supported features are static.

https://github.com/home-assistant/core/blob/12ec66c2c293a080dc43048782a15f6de3892116/homeassistant/components/ecobee/climate.py#L385-L396

piitaya commented 2 months ago

We discussed with core team, it's not recommended to change features depending on the state. However, we can understand the use-case and we already do it for media player so we can add front-end support for that 🙂