mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-10-11 09:58:01 +00:00
Create common interfaces for remaining device types (#895)
Introduce common module interfaces across smart and iot devices and provide better typing implementation for getting modules to support this.
This commit is contained in:
@@ -6,7 +6,7 @@ import logging
|
||||
from abc import ABC, abstractmethod
|
||||
from dataclasses import dataclass
|
||||
from datetime import datetime
|
||||
from typing import Any, Mapping, Sequence, overload
|
||||
from typing import TYPE_CHECKING, Any, Mapping, Sequence
|
||||
|
||||
from .credentials import Credentials
|
||||
from .device_type import DeviceType
|
||||
@@ -15,10 +15,13 @@ from .emeterstatus import EmeterStatus
|
||||
from .exceptions import KasaException
|
||||
from .feature import Feature
|
||||
from .iotprotocol import IotProtocol
|
||||
from .module import Module, ModuleT
|
||||
from .module import Module
|
||||
from .protocol import BaseProtocol
|
||||
from .xortransport import XorTransport
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from .modulemapping import ModuleMapping
|
||||
|
||||
|
||||
@dataclass
|
||||
class WifiNetwork:
|
||||
@@ -113,21 +116,9 @@ class Device(ABC):
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def modules(self) -> Mapping[str, Module]:
|
||||
def modules(self) -> ModuleMapping[Module]:
|
||||
"""Return the device modules."""
|
||||
|
||||
@overload
|
||||
@abstractmethod
|
||||
def get_module(self, module_type: type[ModuleT]) -> ModuleT | None: ...
|
||||
|
||||
@overload
|
||||
@abstractmethod
|
||||
def get_module(self, module_type: str) -> Module | None: ...
|
||||
|
||||
@abstractmethod
|
||||
def get_module(self, module_type: type[ModuleT] | str) -> ModuleT | Module | None:
|
||||
"""Return the module from the device modules or None if not present."""
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def is_on(self) -> bool:
|
||||
|
Reference in New Issue
Block a user