mirror of
https://github.com/python-kasa/python-kasa.git
synced 2024-12-23 11:43:34 +00:00
1ad2a05b65
* Add ChildDevice and ChildProtocolWrapper * Initialize & update children * Fix circular imports * Add dummy_protocol fixture and tests for unwrapping responseData * Use dummy_protocol for existing smartprotocol tests * Move _ChildProtocolWrapper to smartprotocol.py * Use dummy_protocol for test multiple requests * Use device_id instead of position for selecting the child * Fix wrapping for regular requests * Remove unused imports * tweak * rename child_device to childdevice * Fix import
46 lines
1.4 KiB
Python
46 lines
1.4 KiB
Python
"""Module for a TAPO Plug."""
|
|
import logging
|
|
from datetime import datetime, timedelta
|
|
from typing import Any, Dict, Optional, cast
|
|
|
|
from ..deviceconfig import DeviceConfig
|
|
from ..smartdevice import DeviceType
|
|
from ..smartprotocol import SmartProtocol
|
|
from .tapodevice import TapoDevice
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
class TapoPlug(TapoDevice):
|
|
"""Class to represent a TAPO Plug."""
|
|
|
|
def __init__(
|
|
self,
|
|
host: str,
|
|
*,
|
|
config: Optional[DeviceConfig] = None,
|
|
protocol: Optional[SmartProtocol] = None,
|
|
) -> None:
|
|
super().__init__(host=host, config=config, protocol=protocol)
|
|
self._device_type = DeviceType.Plug
|
|
|
|
@property
|
|
def state_information(self) -> Dict[str, Any]:
|
|
"""Return the key state information."""
|
|
return {
|
|
**super().state_information,
|
|
**{
|
|
"On since": self.on_since,
|
|
"auto_off_status": self._info.get("auto_off_status"),
|
|
"auto_off_remain_time": self._info.get("auto_off_remain_time"),
|
|
},
|
|
}
|
|
|
|
@property
|
|
def on_since(self) -> Optional[datetime]:
|
|
"""Return the time that the device was turned on or None if turned off."""
|
|
if not self._info.get("device_on"):
|
|
return None
|
|
on_time = cast(float, self._info.get("on_time"))
|
|
return datetime.now().replace(microsecond=0) - timedelta(seconds=on_time)
|