Closed mill1000 closed 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.
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.
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.
Can you point out which integration that change
supported_features
?
Sure. Here's a few I found.
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
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
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.
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 🙂
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
tosupported_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.
Describe the behavior you expected
The view should fallback to the temperature setpoint.
Steps to reproduce the issue
TARGET_HUMIDITY
.TARGET_HUMIDITY
from supported features.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
Attributes in cool mode
Problem-relevant frontend configuration
Javascript errors shown in your browser console/inspector
Additional information
No response