2024-02-04 15:20:08 +00:00
|
|
|
"""Module for Device base class."""
|
2024-04-16 18:21:20 +00:00
|
|
|
|
2024-04-17 13:39:24 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2024-02-04 15:20:08 +00:00
|
|
|
from abc import ABC, abstractmethod
|
2024-05-19 10:20:18 +00:00
|
|
|
from dataclasses import dataclass
|
|
|
|
from typing import NamedTuple
|
2024-02-04 15:20:08 +00:00
|
|
|
|
2024-05-13 16:34:44 +00:00
|
|
|
from ..module import Module
|
2024-05-02 12:55:08 +00:00
|
|
|
|
2024-02-04 15:20:08 +00:00
|
|
|
|
2024-05-19 10:20:18 +00:00
|
|
|
@dataclass
|
|
|
|
class LightState:
|
|
|
|
"""Class for smart light preset info."""
|
|
|
|
|
|
|
|
light_on: bool | None = None
|
|
|
|
brightness: int | None = None
|
|
|
|
hue: int | None = None
|
|
|
|
saturation: int | None = None
|
|
|
|
color_temp: int | None = None
|
2024-05-22 13:33:55 +00:00
|
|
|
transition: int | None = None
|
2024-05-19 10:20:18 +00:00
|
|
|
|
|
|
|
|
2024-02-04 15:20:08 +00:00
|
|
|
class ColorTempRange(NamedTuple):
|
|
|
|
"""Color temperature range."""
|
|
|
|
|
|
|
|
min: int
|
|
|
|
max: int
|
|
|
|
|
|
|
|
|
|
|
|
class HSV(NamedTuple):
|
|
|
|
"""Hue-saturation-value."""
|
|
|
|
|
|
|
|
hue: int
|
|
|
|
saturation: int
|
|
|
|
value: int
|
|
|
|
|
|
|
|
|
2024-05-13 16:34:44 +00:00
|
|
|
class Light(Module, ABC):
|
2024-05-11 18:40:08 +00:00
|
|
|
"""Base class for TP-Link Light."""
|
2024-02-04 15:20:08 +00:00
|
|
|
|
2024-05-13 16:34:44 +00:00
|
|
|
@property
|
|
|
|
@abstractmethod
|
|
|
|
def is_dimmable(self) -> bool:
|
|
|
|
"""Whether the light supports brightness changes."""
|
2024-02-04 15:20:08 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
@abstractmethod
|
|
|
|
def is_color(self) -> bool:
|
|
|
|
"""Whether the bulb supports color changes."""
|
|
|
|
|
|
|
|
@property
|
|
|
|
@abstractmethod
|
|
|
|
def is_variable_color_temp(self) -> bool:
|
|
|
|
"""Whether the bulb supports color temperature changes."""
|
|
|
|
|
|
|
|
@property
|
|
|
|
@abstractmethod
|
|
|
|
def valid_temperature_range(self) -> ColorTempRange:
|
|
|
|
"""Return the device-specific white temperature range (in Kelvin).
|
|
|
|
|
|
|
|
:return: White temperature range in Kelvin (minimum, maximum)
|
|
|
|
"""
|
|
|
|
|
|
|
|
@property
|
|
|
|
@abstractmethod
|
|
|
|
def has_effects(self) -> bool:
|
|
|
|
"""Return True if the device supports effects."""
|
|
|
|
|
|
|
|
@property
|
|
|
|
@abstractmethod
|
|
|
|
def hsv(self) -> HSV:
|
|
|
|
"""Return the current HSV state of the bulb.
|
|
|
|
|
|
|
|
:return: hue, saturation and value (degrees, %, %)
|
|
|
|
"""
|
|
|
|
|
|
|
|
@property
|
|
|
|
@abstractmethod
|
|
|
|
def color_temp(self) -> int:
|
|
|
|
"""Whether the bulb supports color temperature changes."""
|
|
|
|
|
|
|
|
@property
|
|
|
|
@abstractmethod
|
|
|
|
def brightness(self) -> int:
|
|
|
|
"""Return the current brightness in percentage."""
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
async def set_hsv(
|
|
|
|
self,
|
|
|
|
hue: int,
|
|
|
|
saturation: int,
|
2024-04-17 13:39:24 +00:00
|
|
|
value: int | None = None,
|
2024-02-04 15:20:08 +00:00
|
|
|
*,
|
2024-04-17 13:39:24 +00:00
|
|
|
transition: int | None = None,
|
|
|
|
) -> dict:
|
2024-02-04 15:20:08 +00:00
|
|
|
"""Set new HSV.
|
|
|
|
|
|
|
|
Note, transition is not supported and will be ignored.
|
|
|
|
|
|
|
|
:param int hue: hue in degrees
|
|
|
|
:param int saturation: saturation in percentage [0,100]
|
|
|
|
:param int value: value in percentage [0, 100]
|
|
|
|
:param int transition: transition in milliseconds.
|
|
|
|
"""
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
async def set_color_temp(
|
2024-04-17 13:39:24 +00:00
|
|
|
self, temp: int, *, brightness=None, transition: int | None = None
|
|
|
|
) -> dict:
|
2024-02-04 15:20:08 +00:00
|
|
|
"""Set the color temperature of the device in kelvin.
|
|
|
|
|
|
|
|
Note, transition is not supported and will be ignored.
|
|
|
|
|
|
|
|
:param int temp: The new color temperature, in Kelvin
|
|
|
|
:param int transition: transition in milliseconds.
|
|
|
|
"""
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
async def set_brightness(
|
2024-04-17 13:39:24 +00:00
|
|
|
self, brightness: int, *, transition: int | None = None
|
|
|
|
) -> dict:
|
2024-02-04 15:20:08 +00:00
|
|
|
"""Set the brightness in percentage.
|
|
|
|
|
|
|
|
Note, transition is not supported and will be ignored.
|
|
|
|
|
|
|
|
:param int brightness: brightness in percent
|
|
|
|
:param int transition: transition in milliseconds.
|
|
|
|
"""
|
2024-05-19 10:20:18 +00:00
|
|
|
|
2024-05-22 13:33:55 +00:00
|
|
|
@property
|
|
|
|
@abstractmethod
|
|
|
|
def state(self) -> LightState:
|
|
|
|
"""Return the current light state."""
|
|
|
|
|
2024-05-19 10:20:18 +00:00
|
|
|
@abstractmethod
|
|
|
|
async def set_state(self, state: LightState) -> dict:
|
|
|
|
"""Set the light state."""
|