Repository: home-assistant/core
Pull request: Fix Quickmode handling in ViCare integration
<!--
  You are amazing! Thanks for contributing to our project!
  Please, DO NOT DELETE ANY TEXT from this template! (unless instructed).
-->
## Proposed change
<!--
  Describe the big picture of your changes here to communicate to the
  maintainers why we should accept this pull request. If it fixes a bug
  or resolves a feature request, be sure to link to that issue in the
  additional information section.
-->
Only check the Quickmode *standby* if Quickmodes are supported.


## Type of change
<!--
  What type of change does your PR introduce to Home Assistant?
  NOTE: Please, check only 1! box!
  If your PR requires multiple boxes to be checked, you'll most likely need to
  split it into multiple PRs. This makes things easier and faster to code review.
-->

- [ ] Dependency upgrade
- [x] Bugfix (non-breaking change which fixes an issue)
- [ ] New integration (thank you!)
- [ ] New feature (which adds functionality to an existing integration)
- [ ] Deprecation (breaking change to happen in the future)
- [ ] Breaking change (fix/feature causing existing functionality to break)
- [ ] Code quality improvements to existing code or addition of tests

## Additional information
<!--
  Details are important, and help maintainers processing your PR.
  Please be sure to fill out additional details, if applicable.
-->

- This PR fixes or closes issue: fixes #139998
- This PR is related to issue: 
- Link to documentation pull request: 
- Link to developer documentation pull request: 
- Link to frontend pull request: 

## Checklist
<!--
  Put an `x` in the boxes that apply. You can also fill these out after
  creating the PR. If you're unsure about any of them, don't hesitate to ask.
  We're here to help! This is simply a reminder of what we are going to look
  for before merging your code.
-->

- [ ] The code change is tested and works locally.
- [ ] Local tests pass. **Your PR cannot be merged unless tests pass**
- [x] There is no commented out code in this PR.
- [x] I have followed the [development checklist][dev-checklist]
- [x] I have followed the [perfect PR recommendations][perfect-pr]
- [x] The code has been formatted using Ruff (`ruff format homeassistant tests`)
- [ ] Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

- [ ] Documentation added/updated for [www.home-assistant.io][docs-repository]

If the code communicates with devices, web services, or third-party tools:

- [ ] The [manifest file][manifest-docs] has all fields filled out correctly.  
      Updated and included derived files by running: `python3 -m script.hassfest`.
- [ ] New or updated dependencies have been added to `requirements_all.txt`.  
      Updated by running `python3 -m script.gen_requirements_all`.
- [ ] For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.

<!--
  This project is very active and we have a high turnover of pull requests.

  Unfortunately, the number of incoming pull requests is higher than what our
  reviewers can review and merge so there is a long backlog of pull requests
  waiting for review. You can help here!
  
  By reviewing another pull request, you will help raise the code quality of
  that pull request and the final review will be faster. This way the general
  pace of pull request reviews will go up and your wait time will go down.
  
  When picking a pull request to review, try to choose one that hasn't yet
  been reviewed.

  Thanks for helping out!
-->

To help with the load of incoming pull requests:

- [ ] I have reviewed two other [open pull requests][prs] in this repository.

[prs]: https://github.com/home-assistant/core/pulls?q=is%3Aopen+is%3Apr+-author%3A%40me+-draft%3Atrue+-label%3Awaiting-for-upstream+sort%3Acreated-desc+review%3Anone+-status%3Afailure

<!--
  Thank you for contributing <3

  Below, some useful links you could explore:
-->
[dev-checklist]: https://developers.home-assistant.io/docs/development_checklist/
[manifest-docs]: https://developers.home-assistant.io/docs/creating_integration_manifest/
[quality-scale]: https://developers.home-assistant.io/docs/integration_quality_scale_index/
[docs-repository]: https://github.com/home-assistant/home-assistant.io
[perfect-pr]: https://developers.home-assistant.io/docs/review-process/#creating-the-perfect-pr


Problem statement:
No longer able to set fan speed starting with Home Assistant 2025.3.0 (vitovent 300-W, but most likely this is the same for all)
### The problem

Since home assistant version 2025.3, setting the fan speed throws an error

### What version of Home Assistant Core has the issue?

core-2025.3.0

### What was the last working version of Home Assistant Core?

core-2025.2.4

### What type of installation are you running?

Home Assistant OS

### Integration causing the issue

vicare

### Link to integration documentation on our website

_No response_

### Diagnostics information

_No response_

### Example YAML snippet

```yaml

```

### Anything in the logs that might be useful for us?

```txt
Unexpected error for call_service at pos 3: ventilation.quickmodes.standby
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 524, in _async_step
    await getattr(self, handler)()
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1009, in _async_step_call_service
    response_data = await self._async_run_long_action(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ...<9 lines>...
    )
    ^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 624, in _async_run_long_action
    return await long_task
           ^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2794, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2837, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 1007, in entity_service_call
    single_response = await _handle_entity_call(
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^
        hass, entity, func, data, call.context
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 1079, in _handle_entity_call
    result = await task
             ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/fan/__init__.py", line 228, in async_set_percentage
    await self.hass.async_add_executor_job(self.set_percentage, percentage)
  File "/usr/local/lib/python3.13/concurrent/futures/thread.py", line 59, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/components/vicare/fan.py", line 245, in set_percentage
    elif self._api.getVentilationQuickmode(VentilationQuickmode.STANDBY):
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/site-packages/PyViCare/PyViCareUtils.py", line 55, in feature_flag_wrapper
    return wrapper(*args, **kwargs)
  File "/usr/local/lib/python3.13/site-packages/PyViCare/PyViCareUtils.py", line 48, in wrapper
    return func(*args, **kwargs)
  File "/usr/local/lib/python3.13/site-packages/PyViCare/PyViCareVentilationDevice.py", line 107, in getVentilationQuickmode
    return bool(self.service.getProperty(f"ventilation.quickmodes.{quickmode}")["properties"]["active"]["value"])
                ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/site-packages/PyViCare/PyViCareCachedService.py", line 26, in getProperty
    return readFeature(entities, property_name)
  File "/usr/local/lib/python3.13/site-packages/PyViCare/PyViCareService.py", line 16, in readFeature
    raise PyViCareNotSupportedFeatureError(property_name)
PyViCare.PyViCareUtils.PyViCareNotSupportedFeatureError: ventilation.quickmodes.standby
```

### Additional information

_No response_

Hints from issue discussion:
Hey there @cfenner, mind taking a look at this issue as it has been labeled with an integration (`vicare`) you are listed as a [code owner](https://github.com/home-assistant/core/blob/dev/CODEOWNERS#L1658) for? Thanks!

<details>
<summary>Code owner commands</summary>


Code owners of `vicare` can trigger bot actions by commenting:

- `@home-assistant close` Closes the issue.
- `@home-assistant rename Awesome new title` Renames the issue.
- `@home-assistant reopen` Reopen the issue.
- `@home-assistant unassign vicare` Removes the current integration label and assignees on the issue, add the integration domain after the command.
- `@home-assistant add-label needs-more-information` Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue.
- `@home-assistant remove-label needs-more-information` Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

</details>


<sub><sup>(message by CodeOwnersMention)</sup></sub>

---

[vicare documentation](https://www.home-assistant.io/integrations/vicare)
[vicare source](https://github.com/home-assistant/core/tree/dev/homeassistant/components/vicare)
<sub><sup>(message by IssueLinks)</sup></sub>
I have exactly the same problem. Thanks for help in advance.
Tell me if i can help for a solution.
Hi all, 
same problem here with our Vitoair FS 300E and HA 2025.3.3. 
 workaround: Change present mode to Schedule, adjusting fan speed in HA is then working for me.
I might have a look at the issue next weekend. 
Thanks to everyone who is having a look at this issue.
I am already very happy with the workaround. Thank you!
Raising my hand with the same finding today ;)
@gresie hi! Did you find some time to look into this already?

Hi @0BanZai0 
I had a look, but setting up the build environment took longer than expected. Not sure if I will find the time to work on this in the near future, sorry
@CFenner could you please have a look here and maybe help us :)? thanks!
Feel free to test!

Commit message: update snapshot

Patch to review:
diff --git a/homeassistant/components/vicare/fan.py b/homeassistant/components/vicare/fan.py
index d84b2038ddef58..d1d63b2c560f45 100644
--- a/homeassistant/components/vicare/fan.py
+++ b/homeassistant/components/vicare/fan.py
@@ -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 @@ def __init__(
             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,24 @@ def update(self) -> None:
     @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))
+        if VentilationQuickmode.STANDBY in self._attributes["vicare_quickmodes"]:
+            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 +241,9 @@ def set_percentage(self, percentage: int) -> None:
         """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 +255,8 @@ def set_preset_mode(self, preset_mode: str) -> None:
         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
diff --git a/tests/components/vicare/snapshots/test_fan.ambr b/tests/components/vicare/snapshots/test_fan.ambr
index 2c9e815f7bfc4e..2a44fb87b65084 100644
--- a/tests/components/vicare/snapshots/test_fan.ambr
+++ b/tests/components/vicare/snapshots/test_fan.ambr
@@ -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',


Code review comments:
diff_hunk: @@ -196,26 +197,24 @@ def update(self) -> None:
     @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))
+        if VentilationQuickmode.STANDBY in self._attributes["vicare_quickmodes"]:
+            self._api.activateVentilationQuickmode(str(VentilationQuickmode.STANDBY))
path: homeassistant/components/vicare/fan.py
text: @user1:
so now we cannot turn off the fan when the quickmode is not supported, but what does that mean for those fans in general? Should we not add fans supporting quickmodes? What exactly can you do with such a fan? Users will now just be suprised the switch is not doing anything. 

@author:
Actually the function should not be available as the `FanEntityFeature.TURN_OFF` is only applied once the `VentilationQuickmode.STANDBY` is available (l168).

Viessmann supports *quickmodes* and *modes*, and some appliances implement the one and some the other and they need to be handled differently. Probably this should be handled in the underlying library 🙄. 

@user1:
ah, but why do we need that check here then?

@author:
You're right. I'll remove it.