Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Update interfaces so they all inherit from Device #893

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion kasa/bulb.py
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
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
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
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