Add tolo light platform (#60305)

This commit is contained in:
Matthias Lohr 2021-11-24 22:26:08 +01:00 committed by GitHub
parent 37219e8d04
commit 5853d81944
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 53 additions and 1 deletions

View File

@ -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

View File

@ -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__)

View File

@ -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)