diff --git a/kasa/bulb.py b/kasa/bulb.py index fd3aab666..01065dc09 100644 --- a/kasa/bulb.py +++ b/kasa/bulb.py @@ -7,6 +7,8 @@ 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): diff --git a/kasa/device.py b/kasa/device.py index 8a81030f8..4cb6bd989 100644 --- a/kasa/device.py +++ b/kasa/device.py @@ -245,6 +245,11 @@ def is_dimmable(self) -> bool: """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.""" diff --git a/kasa/fan.py b/kasa/fan.py index c9601b1b7..e881136e8 100644 --- a/kasa/fan.py +++ b/kasa/fan.py @@ -4,14 +4,11 @@ from abc import ABC, abstractmethod +from .device import Device -class Fan(ABC): - """Interface for a Fan.""" - @property - @abstractmethod - def is_fan(self) -> bool: - """Return True if the device is a fan.""" +class Fan(Device, ABC): + """Interface for a Fan.""" @property @abstractmethod diff --git a/kasa/smart/smartdevice.py b/kasa/smart/smartdevice.py index 7ee5ab0f2..733f3157d 100644 --- a/kasa/smart/smartdevice.py +++ b/kasa/smart/smartdevice.py @@ -46,7 +46,9 @@ } -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__(