mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-02-02 10:07:03 +00:00
Update interfaces so they all inherit from Device (#893)
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:
parent
b2194a1c62
commit
28d41092e5
@ -7,6 +7,8 @@ from typing import NamedTuple, Optional
|
||||
|
||||
from pydantic.v1 import BaseModel
|
||||
|
||||
from .device import Device
|
||||
|
||||
|
||||
class ColorTempRange(NamedTuple):
|
||||
"""Color temperature range."""
|
||||
@ -40,7 +42,7 @@ class BulbPreset(BaseModel):
|
||||
mode: Optional[int] # noqa: UP007
|
||||
|
||||
|
||||
class Bulb(ABC):
|
||||
class Bulb(Device, ABC):
|
||||
"""Base class for TP-Link Bulb."""
|
||||
|
||||
def _raise_for_invalid_brightness(self, value):
|
||||
|
@ -245,6 +245,11 @@ class Device(ABC):
|
||||
"""Return True if the device is dimmable."""
|
||||
return False
|
||||
|
||||
@property
|
||||
def is_fan(self) -> bool:
|
||||
"""Return True if the device is a fan."""
|
||||
return self.device_type == DeviceType.Fan
|
||||
|
||||
@property
|
||||
def is_variable_color_temp(self) -> bool:
|
||||
"""Return True if the device supports color temperature."""
|
||||
|
@ -4,15 +4,12 @@ from __future__ import annotations
|
||||
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
from .device import Device
|
||||
|
||||
class Fan(ABC):
|
||||
|
||||
class Fan(Device, ABC):
|
||||
"""Interface for a Fan."""
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def is_fan(self) -> bool:
|
||||
"""Return True if the device is a fan."""
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
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."""
|
||||
|
||||
def __init__(
|
||||
|
Loading…
Reference in New Issue
Block a user