From 7b81185d2afff5081eacca33a422dde3cd3a3a67 Mon Sep 17 00:00:00 2001 From: Matthias Lohr Date: Mon, 29 Nov 2021 17:15:38 +0100 Subject: [PATCH] Add tolo fan platform (#60502) --- .coveragerc | 1 + homeassistant/components/tolo/__init__.py | 10 +++- homeassistant/components/tolo/fan.py | 56 +++++++++++++++++++++++ 3 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 homeassistant/components/tolo/fan.py diff --git a/.coveragerc b/.coveragerc index 519fa1b3937..beb7719db44 100644 --- a/.coveragerc +++ b/.coveragerc @@ -1098,6 +1098,7 @@ omit = homeassistant/components/tolo/binary_sensor.py homeassistant/components/tolo/button.py homeassistant/components/tolo/climate.py + homeassistant/components/tolo/fan.py homeassistant/components/tolo/light.py homeassistant/components/tolo/select.py homeassistant/components/tolo/sensor.py diff --git a/homeassistant/components/tolo/__init__.py b/homeassistant/components/tolo/__init__.py index 666e86c951b..4f41303c8f8 100644 --- a/homeassistant/components/tolo/__init__.py +++ b/homeassistant/components/tolo/__init__.py @@ -22,7 +22,15 @@ from homeassistant.helpers.update_coordinator import ( from .const import DEFAULT_RETRY_COUNT, DEFAULT_RETRY_TIMEOUT, DOMAIN -PLATFORMS = ["binary_sensor", "button", "climate", "light", "select", "sensor"] +PLATFORMS = [ + "binary_sensor", + "button", + "climate", + "fan", + "light", + "select", + "sensor", +] _LOGGER = logging.getLogger(__name__) diff --git a/homeassistant/components/tolo/fan.py b/homeassistant/components/tolo/fan.py new file mode 100644 index 00000000000..499a348bd0b --- /dev/null +++ b/homeassistant/components/tolo/fan.py @@ -0,0 +1,56 @@ +"""TOLO Sauna fan controls.""" + +from __future__ import annotations + +from typing import Any + +from homeassistant.components.fan import FanEntity +from homeassistant.config_entries import ConfigEntry +from homeassistant.core import HomeAssistant +from homeassistant.helpers.entity_platform import AddEntitiesCallback + +from . import ToloSaunaCoordinatorEntity, ToloSaunaUpdateCoordinator +from .const import DOMAIN + + +async def async_setup_entry( + hass: HomeAssistant, + entry: ConfigEntry, + async_add_entities: AddEntitiesCallback, +) -> None: + """Set up fan controls for TOLO Sauna.""" + coordinator = hass.data[DOMAIN][entry.entry_id] + async_add_entities([ToloFan(coordinator, entry)]) + + +class ToloFan(ToloSaunaCoordinatorEntity, FanEntity): + """Sauna fan control.""" + + _attr_name = "Fan" + + def __init__( + self, coordinator: ToloSaunaUpdateCoordinator, entry: ConfigEntry + ) -> None: + """Initialize TOLO fan entity.""" + super().__init__(coordinator, entry) + + self._attr_unique_id = f"{entry.entry_id}_fan" + + @property + def is_on(self) -> bool: + """Return if sauna fan is running.""" + return self.coordinator.data.status.fan_on + + def turn_on( + self, + speed: str | None = None, + percentage: int | None = None, + preset_mode: str | None = None, + **kwargs: Any, + ) -> None: + """Turn on sauna fan.""" + self.coordinator.client.set_fan_on(True) + + def turn_off(self, **kwargs: Any) -> None: + """Turn off sauna fan.""" + self.coordinator.client.set_fan_on(False)