From 5853d819440f62dda96947240e577fb5a33fcb1e Mon Sep 17 00:00:00 2001 From: Matthias Lohr Date: Wed, 24 Nov 2021 22:26:08 +0100 Subject: [PATCH] Add tolo light platform (#60305) --- .coveragerc | 1 + homeassistant/components/tolo/__init__.py | 2 +- homeassistant/components/tolo/light.py | 51 +++++++++++++++++++++++ 3 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 homeassistant/components/tolo/light.py diff --git a/.coveragerc b/.coveragerc index 6dfca6f7acc..619b8468a07 100644 --- a/.coveragerc +++ b/.coveragerc @@ -1093,6 +1093,7 @@ omit = homeassistant/components/tof/sensor.py homeassistant/components/tolo/__init__.py homeassistant/components/tolo/climate.py + homeassistant/components/tolo/light.py homeassistant/components/tomato/device_tracker.py homeassistant/components/toon/__init__.py homeassistant/components/toon/binary_sensor.py diff --git a/homeassistant/components/tolo/__init__.py b/homeassistant/components/tolo/__init__.py index d4b182061c3..5151449f1fd 100644 --- a/homeassistant/components/tolo/__init__.py +++ b/homeassistant/components/tolo/__init__.py @@ -22,7 +22,7 @@ from homeassistant.helpers.update_coordinator import ( from .const import DEFAULT_RETRY_COUNT, DEFAULT_RETRY_TIMEOUT, DOMAIN -PLATFORMS = ["climate"] +PLATFORMS = ["climate", "light"] _LOGGER = logging.getLogger(__name__) diff --git a/homeassistant/components/tolo/light.py b/homeassistant/components/tolo/light.py new file mode 100644 index 00000000000..f58f7e7b8c9 --- /dev/null +++ b/homeassistant/components/tolo/light.py @@ -0,0 +1,51 @@ +"""TOLO Sauna light controls.""" + +from __future__ import annotations + +from typing import Any + +from homeassistant.components.light import COLOR_MODE_ONOFF, LightEntity +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 light controls for TOLO Sauna.""" + coordinator = hass.data[DOMAIN][entry.entry_id] + async_add_entities([ToloLight(coordinator, entry)]) + + +class ToloLight(ToloSaunaCoordinatorEntity, LightEntity): + """Sauna light control.""" + + _attr_name = "Sauna Light" + _attr_supported_color_modes = {COLOR_MODE_ONOFF} + + def __init__( + self, coordinator: ToloSaunaUpdateCoordinator, entry: ConfigEntry + ) -> None: + """Initialize TOLO Sauna Light entity.""" + super().__init__(coordinator, entry) + + self._attr_unique_id = f"{entry.entry_id}_light" + + @property + def is_on(self) -> bool: + """Return current lamp status.""" + return self.coordinator.data.status.lamp_on + + def turn_on(self, **kwargs: Any) -> None: + """Turn on TOLO Sauna lamp.""" + self.coordinator.client.set_lamp_on(True) + + def turn_off(self, **kwargs: Any) -> None: + """Turn off TOLO Sauna lamp.""" + self.coordinator.client.set_lamp_on(False)