GeezerVison is showing github.com — Update interfaces so they all inherit from Device (#893) · python-kasa/python-kasa@28d4109
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: kasa/bulb.py +3-1Lines changed: 3 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
|
7 | 7 |
|
8 | 8 | from pydantic.v1 import BaseModel |
9 | 9 |
|
| 10 | +from .device import Device |
| 11 | + |
10 | 12 |
|
11 | 13 | class ColorTempRange(NamedTuple): |
12 | 14 | """Color temperature range.""" |
@@ -40,7 +42,7 @@ class BulbPreset(BaseModel): |
40 | 42 | mode: Optional[int] # noqa: UP007 |
41 | 43 |
|
42 | 44 |
|
43 | | -class Bulb(ABC): |
| 45 | +class Bulb(Device, ABC): |
44 | 46 | """Base class for TP-Link Bulb.""" |
45 | 47 |
|
46 | 48 | def _raise_for_invalid_brightness(self, value): |
|
Collapse file
Copy file name to clipboardExpand all lines: kasa/device.py +5Lines changed: 5 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -245,6 +245,11 @@ def is_dimmable(self) -> bool: |
245 | 245 | """Return True if the device is dimmable.""" |
246 | 246 | return False |
247 | 247 |
|
| 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 | + |
248 | 253 | @property |
249 | 254 | def is_variable_color_temp(self) -> bool: |
250 | 255 | """Return True if the device supports color temperature.""" |
|
Collapse file
Copy file name to clipboardExpand all lines: kasa/fan.py +3-6Lines changed: 3 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
4 | 4 |
|
5 | 5 | from abc import ABC, abstractmethod |
6 | 6 |
|
| 7 | +from .device import Device |
7 | 8 |
|
8 | | -class Fan(ABC): |
9 | | - """Interface for a Fan.""" |
10 | 9 |
|
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.""" |
15 | 12 |
|
16 | 13 | @property |
17 | 14 | @abstractmethod |
|
Collapse file
Copy file name to clipboardExpand all lines: kasa/smart/smartdevice.py +3-1Lines changed: 3 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
|
46 | 46 | } |
47 | 47 |
|
48 | 48 |
|
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): |
50 | 52 | """Base class to represent a SMART protocol based device.""" |
51 | 53 |
|
52 | 54 | def __init__( |
|