FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Update interfaces so they all inherit from Device by sdb9696 · Pull Request #893 · python-kasa/python-kasa · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (4) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
4 changes: 3 additions & 1 deletion kasa/bulb.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

from pydantic.v1 import BaseModel

from .device import Device


class ColorTempRange(NamedTuple):
"""Color temperature range."""
Expand Down Expand Up @@ -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):
Expand Down
5 changes: 5 additions & 0 deletions kasa/device.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
9 changes: 3 additions & 6 deletions kasa/fan.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion kasa/smart/smartdevice.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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__(
Expand Down

Back | FazBrowse Home | New Git URL