Update interfaces so they all inherit from Device ()

Brings consistency to the api across Smart and Iot so the interfaces can be used for their specialist methods as well as the device methods (e.g. turn_on/off).
This commit is contained in:
Steven B 2024-05-02 13:55:08 +01:00 committed by GitHub
parent b2194a1c62
commit 28d41092e5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 14 additions and 8 deletions

@ -7,6 +7,8 @@ from typing import NamedTuple, Optional
from pydantic.v1 import BaseModel from pydantic.v1 import BaseModel
from .device import Device
class ColorTempRange(NamedTuple): class ColorTempRange(NamedTuple):
"""Color temperature range.""" """Color temperature range."""
@ -40,7 +42,7 @@ class BulbPreset(BaseModel):
mode: Optional[int] # noqa: UP007 mode: Optional[int] # noqa: UP007
class Bulb(ABC): class Bulb(Device, ABC):
"""Base class for TP-Link Bulb.""" """Base class for TP-Link Bulb."""
def _raise_for_invalid_brightness(self, value): def _raise_for_invalid_brightness(self, value):

@ -245,6 +245,11 @@ class Device(ABC):
"""Return True if the device is dimmable.""" """Return True if the device is dimmable."""
return False return False
@property
def is_fan(self) -> bool:
"""Return True if the device is a fan."""
return self.device_type == DeviceType.Fan
@property @property
def is_variable_color_temp(self) -> bool: def is_variable_color_temp(self) -> bool:
"""Return True if the device supports color temperature.""" """Return True if the device supports color temperature."""

@ -4,15 +4,12 @@ from __future__ import annotations
from abc import ABC, abstractmethod from abc import ABC, abstractmethod
from .device import Device
class Fan(ABC):
class Fan(Device, ABC):
"""Interface for a Fan.""" """Interface for a Fan."""
@property
@abstractmethod
def is_fan(self) -> bool:
"""Return True if the device is a fan."""
@property @property
@abstractmethod @abstractmethod
def fan_speed_level(self) -> int: def fan_speed_level(self) -> int:

@ -46,7 +46,9 @@ AVAILABLE_BULB_EFFECTS = {
} }
class SmartDevice(Device, Bulb, Fan): # Device must go last as the other interfaces also inherit Device
# and python needs a consistent method resolution order.
class SmartDevice(Bulb, Fan, Device):
"""Base class to represent a SMART protocol based device.""" """Base class to represent a SMART protocol based device."""
def __init__( def __init__(