mirror of
https://github.com/home-assistant/core.git
synced 2025-07-15 17:27:10 +00:00
Fix fan speed in auto mode in ViCare integration (#134256)
This commit is contained in:
parent
9d5fe77b71
commit
654e111c23
@ -28,7 +28,7 @@ from homeassistant.util.percentage import (
|
||||
|
||||
from .entity import ViCareEntity
|
||||
from .types import ViCareConfigEntry, ViCareDevice
|
||||
from .utils import get_device_serial
|
||||
from .utils import filter_state, get_device_serial
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
@ -143,15 +143,20 @@ class ViCareFan(ViCareEntity, FanEntity):
|
||||
|
||||
def update(self) -> None:
|
||||
"""Update state of fan."""
|
||||
level: str | None = None
|
||||
try:
|
||||
with suppress(PyViCareNotSupportedFeatureError):
|
||||
self._attr_preset_mode = VentilationMode.from_vicare_mode(
|
||||
self._api.getActiveMode()
|
||||
)
|
||||
with suppress(PyViCareNotSupportedFeatureError):
|
||||
level = filter_state(self._api.getVentilationLevel())
|
||||
if level is not None and level in ORDERED_NAMED_FAN_SPEEDS:
|
||||
self._attr_percentage = ordered_list_item_to_percentage(
|
||||
ORDERED_NAMED_FAN_SPEEDS, self._api.getActiveProgram()
|
||||
ORDERED_NAMED_FAN_SPEEDS, VentilationProgram(level)
|
||||
)
|
||||
else:
|
||||
self._attr_percentage = 0
|
||||
except RequestConnectionError:
|
||||
_LOGGER.error("Unable to retrieve data from ViCare server")
|
||||
except ValueError:
|
||||
|
@ -49,6 +49,7 @@ from .const import (
|
||||
from .entity import ViCareEntity
|
||||
from .types import ViCareConfigEntry, ViCareDevice, ViCareRequiredKeysMixin
|
||||
from .utils import (
|
||||
filter_state,
|
||||
get_burners,
|
||||
get_circuits,
|
||||
get_compressors,
|
||||
@ -796,7 +797,7 @@ GLOBAL_SENSORS: tuple[ViCareSensorEntityDescription, ...] = (
|
||||
translation_key="photovoltaic_status",
|
||||
device_class=SensorDeviceClass.ENUM,
|
||||
options=["ready", "production"],
|
||||
value_getter=lambda api: _filter_states(api.getPhotovoltaicStatus()),
|
||||
value_getter=lambda api: filter_state(api.getPhotovoltaicStatus()),
|
||||
),
|
||||
ViCareSensorEntityDescription(
|
||||
key="room_temperature",
|
||||
@ -815,7 +816,7 @@ GLOBAL_SENSORS: tuple[ViCareSensorEntityDescription, ...] = (
|
||||
ViCareSensorEntityDescription(
|
||||
key="ventilation_level",
|
||||
translation_key="ventilation_level",
|
||||
value_getter=lambda api: _filter_states(api.getVentilationLevel().lower()),
|
||||
value_getter=lambda api: filter_state(api.getVentilationLevel().lower()),
|
||||
device_class=SensorDeviceClass.ENUM,
|
||||
options=["standby", "levelone", "leveltwo", "levelthree", "levelfour"],
|
||||
),
|
||||
@ -943,10 +944,6 @@ COMPRESSOR_SENSORS: tuple[ViCareSensorEntityDescription, ...] = (
|
||||
)
|
||||
|
||||
|
||||
def _filter_states(state: str) -> str | None:
|
||||
return None if state in ("nothing", "unknown") else state
|
||||
|
||||
|
||||
def _build_entities(
|
||||
device_list: list[ViCareDevice],
|
||||
) -> list[ViCareSensor]:
|
||||
|
@ -128,3 +128,8 @@ def get_compressors(device: PyViCareDevice) -> list[PyViCareHeatingDeviceCompone
|
||||
except AttributeError as error:
|
||||
_LOGGER.debug("No compressors found: %s", error)
|
||||
return []
|
||||
|
||||
|
||||
def filter_state(state: str) -> str | None:
|
||||
"""Remove invalid states."""
|
||||
return None if state in ("nothing", "unknown") else state
|
||||
|
23
tests/components/vicare/test_utils.py
Normal file
23
tests/components/vicare/test_utils.py
Normal file
@ -0,0 +1,23 @@
|
||||
"""Test ViCare utils."""
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.vicare.utils import filter_state
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("state", "expected_result"),
|
||||
[
|
||||
(None, None),
|
||||
("unknown", None),
|
||||
("nothing", None),
|
||||
("levelOne", "levelOne"),
|
||||
],
|
||||
)
|
||||
async def test_filter_state(
|
||||
state: str | None,
|
||||
expected_result: str | None,
|
||||
) -> None:
|
||||
"""Test filter_state."""
|
||||
|
||||
assert filter_state(state) == expected_result
|
Loading…
x
Reference in New Issue
Block a user