mirror of
https://github.com/home-assistant/core.git
synced 2025-08-04 13:15:18 +02:00
Define ViCare fan entity presets based on the actual by the device supported presets (#130886)
* only show supported presets
* update snapshot
* Apply suggestions from code review
* move code to init
* async executor
* Revert "update snapshot"
This reverts commit ca92b5ed27
.
* Update fan.py
This commit is contained in:
committed by
GitHub
parent
1dc99ebc05
commit
84630ef8cc
@@ -29,6 +29,7 @@ from homeassistant.util.percentage import (
|
|||||||
|
|
||||||
from .const import DEVICE_LIST, DOMAIN
|
from .const import DEVICE_LIST, DOMAIN
|
||||||
from .entity import ViCareEntity
|
from .entity import ViCareEntity
|
||||||
|
from .types import ViCareDevice
|
||||||
from .utils import get_device_serial
|
from .utils import get_device_serial
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
@@ -90,6 +91,17 @@ ORDERED_NAMED_FAN_SPEEDS = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
def _build_entities(
|
||||||
|
device_list: list[ViCareDevice],
|
||||||
|
) -> list[ViCareFan]:
|
||||||
|
"""Create ViCare climate entities for a device."""
|
||||||
|
return [
|
||||||
|
ViCareFan(get_device_serial(device.api), device.config, device.api)
|
||||||
|
for device in device_list
|
||||||
|
if isinstance(device.api, PyViCareVentilationDevice)
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
config_entry: ConfigEntry,
|
config_entry: ConfigEntry,
|
||||||
@@ -100,27 +112,18 @@ async def async_setup_entry(
|
|||||||
device_list = hass.data[DOMAIN][config_entry.entry_id][DEVICE_LIST]
|
device_list = hass.data[DOMAIN][config_entry.entry_id][DEVICE_LIST]
|
||||||
|
|
||||||
async_add_entities(
|
async_add_entities(
|
||||||
[
|
await hass.async_add_executor_job(
|
||||||
ViCareFan(get_device_serial(device.api), device.config, device.api)
|
_build_entities,
|
||||||
for device in device_list
|
device_list,
|
||||||
if isinstance(device.api, PyViCareVentilationDevice)
|
)
|
||||||
]
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class ViCareFan(ViCareEntity, FanEntity):
|
class ViCareFan(ViCareEntity, FanEntity):
|
||||||
"""Representation of the ViCare ventilation device."""
|
"""Representation of the ViCare ventilation device."""
|
||||||
|
|
||||||
_attr_preset_modes = list[str](
|
|
||||||
[
|
|
||||||
VentilationMode.PERMANENT,
|
|
||||||
VentilationMode.VENTILATION,
|
|
||||||
VentilationMode.SENSOR_DRIVEN,
|
|
||||||
VentilationMode.SENSOR_OVERRIDE,
|
|
||||||
]
|
|
||||||
)
|
|
||||||
_attr_speed_count = len(ORDERED_NAMED_FAN_SPEEDS)
|
_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"
|
_attr_translation_key = "ventilation"
|
||||||
_enable_turn_on_off_backwards_compatibility = False
|
_enable_turn_on_off_backwards_compatibility = False
|
||||||
|
|
||||||
@@ -134,6 +137,15 @@ class ViCareFan(ViCareEntity, FanEntity):
|
|||||||
super().__init__(
|
super().__init__(
|
||||||
self._attr_translation_key, device_serial, device_config, device
|
self._attr_translation_key, device_serial, device_config, device
|
||||||
)
|
)
|
||||||
|
# init presets
|
||||||
|
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
|
||||||
|
|
||||||
def update(self) -> None:
|
def update(self) -> None:
|
||||||
"""Update state of fan."""
|
"""Update state of fan."""
|
||||||
|
Reference in New Issue
Block a user