Fix Quickmode handling in ViCare integration (#142561)

* only check quickmode if supported

* update snapshot

* revert
This commit is contained in:
Christopher Fenner 2025-04-09 20:36:41 +02:00 committed by GitHub
parent 816edb66c7
commit 76015740f8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 33 additions and 13 deletions

View File

@ -127,6 +127,7 @@ class ViCareFan(ViCareEntity, FanEntity):
_attr_speed_count = len(ORDERED_NAMED_FAN_SPEEDS)
_attr_translation_key = "ventilation"
_attributes: dict[str, Any] = {}
def __init__(
self,
@ -155,7 +156,7 @@ class ViCareFan(ViCareEntity, FanEntity):
self._attr_supported_features |= FanEntityFeature.SET_SPEED
# evaluate quickmodes
quickmodes: list[str] = (
self._attributes["vicare_quickmodes"] = quickmodes = list[str](
device.getVentilationQuickmodes()
if is_supported(
"getVentilationQuickmodes",
@ -196,26 +197,23 @@ class ViCareFan(ViCareEntity, FanEntity):
@property
def is_on(self) -> bool | None:
"""Return true if the entity is on."""
if (
self._attr_supported_features & FanEntityFeature.TURN_OFF
and self._api.getVentilationQuickmode(VentilationQuickmode.STANDBY)
):
if VentilationQuickmode.STANDBY in self._attributes[
"vicare_quickmodes"
] and self._api.getVentilationQuickmode(VentilationQuickmode.STANDBY):
return False
return self.percentage is not None and self.percentage > 0
def turn_off(self, **kwargs: Any) -> None:
"""Turn the entity off."""
self._api.activateVentilationQuickmode(str(VentilationQuickmode.STANDBY))
@property
def icon(self) -> str | None:
"""Return the icon to use in the frontend."""
if (
self._attr_supported_features & FanEntityFeature.TURN_OFF
and self._api.getVentilationQuickmode(VentilationQuickmode.STANDBY)
):
if VentilationQuickmode.STANDBY in self._attributes[
"vicare_quickmodes"
] and self._api.getVentilationQuickmode(VentilationQuickmode.STANDBY):
return "mdi:fan-off"
if hasattr(self, "_attr_preset_mode"):
if self._attr_preset_mode == VentilationMode.VENTILATION:
@ -242,7 +240,9 @@ class ViCareFan(ViCareEntity, FanEntity):
"""Set the speed of the fan, as a percentage."""
if self._attr_preset_mode != str(VentilationMode.PERMANENT):
self.set_preset_mode(VentilationMode.PERMANENT)
elif self._api.getVentilationQuickmode(VentilationQuickmode.STANDBY):
elif VentilationQuickmode.STANDBY in self._attributes[
"vicare_quickmodes"
] and self._api.getVentilationQuickmode(VentilationQuickmode.STANDBY):
self._api.deactivateVentilationQuickmode(str(VentilationQuickmode.STANDBY))
level = percentage_to_ordered_list_item(ORDERED_NAMED_FAN_SPEEDS, percentage)
@ -254,3 +254,8 @@ class ViCareFan(ViCareEntity, FanEntity):
target_mode = VentilationMode.to_vicare_mode(preset_mode)
_LOGGER.debug("changing ventilation mode to %s", target_mode)
self._api.activateVentilationMode(target_mode)
@property
def extra_state_attributes(self) -> dict[str, Any]:
"""Show Device Attributes."""
return self._attributes

View File

@ -55,6 +55,11 @@
<VentilationMode.SENSOR_OVERRIDE: 'sensor_override'>,
]),
'supported_features': <FanEntityFeature: 9>,
'vicare_quickmodes': list([
'comfort',
'eco',
'holiday',
]),
}),
'context': <ANY>,
'entity_id': 'fan.model0_ventilation',
@ -94,7 +99,7 @@
'options': dict({
}),
'original_device_class': None,
'original_icon': 'mdi:fan-off',
'original_icon': 'mdi:fan',
'original_name': 'Ventilation',
'platform': 'vicare',
'previous_unique_id': None,
@ -108,7 +113,7 @@
StateSnapshot({
'attributes': ReadOnlyDict({
'friendly_name': 'model1 Ventilation',
'icon': 'mdi:fan-off',
'icon': 'mdi:fan',
'percentage': 0,
'percentage_step': 25.0,
'preset_mode': None,
@ -118,6 +123,11 @@
<VentilationMode.SENSOR_DRIVEN: 'sensor_driven'>,
]),
'supported_features': <FanEntityFeature: 25>,
'vicare_quickmodes': list([
'comfort',
'eco',
'holiday',
]),
}),
'context': <ANY>,
'entity_id': 'fan.model1_ventilation',
@ -179,6 +189,11 @@
<VentilationMode.STANDARD: 'standard'>,
]),
'supported_features': <FanEntityFeature: 8>,
'vicare_quickmodes': list([
'comfort',
'eco',
'holiday',
]),
}),
'context': <ANY>,
'entity_id': 'fan.model2_ventilation',