8000 Update interfaces so they all inherit from Device (#893) · python-kasa/python-kasa@28d4109 · GitHub
[go: up one dir, main page]

Skip to content

Commit 28d4109

Browse files
authored
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).
1 parent b2194a1 commit 28d4109

File tree

4 files changed

+14
-8
lines changed

4 files changed

+14
-8
lines changed

kasa/bulb.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
from pydantic.v1 import BaseModel
99

10+
from .device import Device
11+
1012

1113
class ColorTempRange(NamedTuple):
1214
"""Color temperature range."""
@@ -40,7 +42,7 @@ class BulbPreset(BaseModel):
4042
mode: Optional[int] # noqa: UP007
4143

4244

43-
class Bulb(ABC):
45+
class Bulb(Device, ABC):
4446
"""Base class for TP-Link Bulb."""
4547

4648
def _raise_for_invalid_brightness(self, value):

kasa/device.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,11 @@ def is_dimmable(self) -> bool:
245245
"""Return True if the device is dimmable."""
246246
return False
247247

248+
@property
249+
def is_fan(self) -> bool:
250+
"""Return True if the device is a fan."""
251+
return self.device_type == DeviceType.Fan
252+
248253
@property
249254
def is_variable_color_temp(self) -> bool:
250255
"""Return True if the device supports color temperature."""

kasa/fan.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,11 @@
44

55
from abc import ABC, abstractmethod
66

7+
from .device import Device
78

8-
class Fan(ABC):
9-
"""Interface for a Fan."""
109

11-
@property
12-
@abstractmethod
13-
def is_fan(self) -> bool:
14-
"""Return True if the device is a fan."""
10+
class Fan(Device, ABC):
11+
"""Interface for a Fan."""
1512

1613
@property
1714
@abstractmethod

kasa/smart/smartdevice.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@
4646
}
4747

4848

49-
class SmartDevice(Device, Bulb, Fan):
49+
# Device must go last as the other interfaces also inherit Device
50+
# and python needs a consistent method resolution order.
51+
class SmartDevice(Bulb, Fan, Device):
5052
"""Base class to represent a SMART protocol based device."""
5153

5254
def __init__(

0 commit comments

Comments
 (0)
0