GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

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
Filter options
  • kasa
    • bulb.py
    • device.py
    • fan.py
    • smart
      • smartdevice.py
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎kasa/bulb.py‎

Copy file name to clipboardExpand all lines: kasa/bulb.py
+3-1Lines 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):
Collapse file

‎kasa/device.py‎

Copy file name to clipboardExpand all lines: kasa/device.py
+5Lines 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."""
Collapse file

‎kasa/fan.py‎

Copy file name to clipboardExpand all lines: kasa/fan.py
+3-6Lines 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
Collapse file

‎kasa/smart/smartdevice.py‎

Copy file name to clipboardExpand all lines: kasa/smart/smartdevice.py
+3-1Lines 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)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.