Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define ViCare fan entity presets based on the actual by the device supported presets #130886

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions homeassistant/components/vicare/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,23 +104,17 @@ async def async_setup_entry(
ViCareFan(get_device_serial(device.api), device.config, device.api)
for device in device_list
if isinstance(device.api, PyViCareVentilationDevice)
]
],
True,
)


class ViCareFan(ViCareEntity, FanEntity):
"""Representation of the ViCare ventilation device."""

_attr_preset_modes = list[str](
[
VentilationMode.PERMANENT,
VentilationMode.VENTILATION,
VentilationMode.SENSOR_DRIVEN,
VentilationMode.SENSOR_OVERRIDE,
]
)
_attr_preset_modes: list[str] | None = None
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we set the default in FanEntity?

_attr_speed_count = len(ORDERED_NAMED_FAN_SPEEDS)
_attr_supported_features = FanEntityFeature.SET_SPEED | FanEntityFeature.PRESET_MODE
_attr_supported_features = FanEntityFeature.SET_SPEED
_attr_translation_key = "ventilation"
_enable_turn_on_off_backwards_compatibility = False

Expand All @@ -137,6 +131,18 @@ def __init__(

def update(self) -> None:
"""Update state of fan."""

# init presets
if self._attr_preset_modes is None:
supported_modes = list[str](self._api.getAvailableModes())
self._attr_preset_modes = [
mode
for mode in VentilationMode
if VentilationMode.to_vicare_mode(mode) in supported_modes
]
if len(self._attr_preset_modes) > 0:
self._attr_supported_features |= FanEntityFeature.PRESET_MODE

try:
with suppress(PyViCareNotSupportedFeatureError):
self._attr_preset_mode = VentilationMode.from_vicare_mode(
Expand Down
4 changes: 2 additions & 2 deletions tests/components/vicare/snapshots/test_fan.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@
StateSnapshot({
'attributes': ReadOnlyDict({
'friendly_name': 'model0 Ventilation',
'percentage': 0,
'percentage': 25,
'percentage_step': 25.0,
'preset_mode': None,
'preset_mode': <VentilationMode.PERMANENT: 'permanent'>,
'preset_modes': list([
<VentilationMode.PERMANENT: 'permanent'>,
<VentilationMode.VENTILATION: 'ventilation'>,
Expand Down