mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-08-09 20:24:02 +00:00
Add DeviceConfig to allow specifying configuration parameters (#569)
* Add DeviceConfig handling * Update post review * Further update post latest review * Update following latest review * Update docstrings and docs
This commit is contained in:
@@ -5,8 +5,9 @@ from datetime import datetime, timedelta, timezone
|
||||
from typing import Any, Dict, Optional, Set, cast
|
||||
|
||||
from ..aestransport import AesTransport
|
||||
from ..credentials import Credentials
|
||||
from ..deviceconfig import DeviceConfig
|
||||
from ..exceptions import AuthenticationException
|
||||
from ..protocol import TPLinkProtocol
|
||||
from ..smartdevice import SmartDevice
|
||||
from ..smartprotocol import SmartProtocol
|
||||
|
||||
@@ -20,20 +21,16 @@ class TapoDevice(SmartDevice):
|
||||
self,
|
||||
host: str,
|
||||
*,
|
||||
port: Optional[int] = None,
|
||||
credentials: Optional[Credentials] = None,
|
||||
timeout: Optional[int] = None,
|
||||
config: Optional[DeviceConfig] = None,
|
||||
protocol: Optional[TPLinkProtocol] = None,
|
||||
) -> None:
|
||||
super().__init__(host, port=port, credentials=credentials, timeout=timeout)
|
||||
_protocol = protocol or SmartProtocol(
|
||||
transport=AesTransport(config=config or DeviceConfig(host=host)),
|
||||
)
|
||||
super().__init__(host=host, config=config, protocol=_protocol)
|
||||
self._components: Optional[Dict[str, Any]] = None
|
||||
self._state_information: Dict[str, Any] = {}
|
||||
self._discovery_info: Optional[Dict[str, Any]] = None
|
||||
self.protocol = SmartProtocol(
|
||||
host,
|
||||
transport=AesTransport(
|
||||
host, credentials=credentials, timeout=timeout, port=port
|
||||
),
|
||||
)
|
||||
|
||||
async def update(self, update_children: bool = True):
|
||||
"""Update the device."""
|
||||
@@ -66,7 +63,7 @@ class TapoDevice(SmartDevice):
|
||||
@property
|
||||
def sys_info(self) -> Dict[str, Any]:
|
||||
"""Returns the device info."""
|
||||
return self._info
|
||||
return self._info # type: ignore
|
||||
|
||||
@property
|
||||
def model(self) -> str:
|
||||
@@ -180,3 +177,4 @@ class TapoDevice(SmartDevice):
|
||||
def update_from_discover_info(self, info):
|
||||
"""Update state from info from the discover call."""
|
||||
self._discovery_info = info
|
||||
self._info = info
|
||||
|
@@ -3,9 +3,10 @@ import logging
|
||||
from datetime import datetime, timedelta
|
||||
from typing import Any, Dict, Optional, cast
|
||||
|
||||
from ..credentials import Credentials
|
||||
from ..deviceconfig import DeviceConfig
|
||||
from ..emeterstatus import EmeterStatus
|
||||
from ..modules import Emeter
|
||||
from ..protocol import TPLinkProtocol
|
||||
from ..smartdevice import DeviceType, requires_update
|
||||
from .tapodevice import TapoDevice
|
||||
|
||||
@@ -19,11 +20,10 @@ class TapoPlug(TapoDevice):
|
||||
self,
|
||||
host: str,
|
||||
*,
|
||||
port: Optional[int] = None,
|
||||
credentials: Optional[Credentials] = None,
|
||||
timeout: Optional[int] = None,
|
||||
config: Optional[DeviceConfig] = None,
|
||||
protocol: Optional[TPLinkProtocol] = None,
|
||||
) -> None:
|
||||
super().__init__(host, port=port, credentials=credentials, timeout=timeout)
|
||||
super().__init__(host=host, config=config, protocol=protocol)
|
||||
self._device_type = DeviceType.Plug
|
||||
self.modules: Dict[str, Any] = {}
|
||||
self.emeter_type = "emeter"
|
||||
|
Reference in New Issue
Block a user