2023-11-30 12:10:49 +00:00
|
|
|
"""Module for a TAPO Plug."""
|
|
|
|
import logging
|
|
|
|
from datetime import datetime, timedelta
|
|
|
|
from typing import Any, Dict, Optional, cast
|
|
|
|
|
2023-12-29 19:17:15 +00:00
|
|
|
from ..deviceconfig import DeviceConfig
|
2024-01-22 15:28:30 +00:00
|
|
|
from ..protocol import BaseProtocol
|
2024-01-03 18:04:34 +00:00
|
|
|
from ..smartdevice import DeviceType
|
2023-11-30 12:10:49 +00:00
|
|
|
from .tapodevice import TapoDevice
|
|
|
|
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
class TapoPlug(TapoDevice):
|
|
|
|
"""Class to represent a TAPO Plug."""
|
|
|
|
|
|
|
|
def __init__(
|
|
|
|
self,
|
|
|
|
host: str,
|
|
|
|
*,
|
2023-12-29 19:17:15 +00:00
|
|
|
config: Optional[DeviceConfig] = None,
|
2024-01-22 15:28:30 +00:00
|
|
|
protocol: Optional[BaseProtocol] = None,
|
2023-11-30 12:10:49 +00:00
|
|
|
) -> None:
|
2023-12-29 19:17:15 +00:00
|
|
|
super().__init__(host=host, config=config, protocol=protocol)
|
2023-11-30 12:10:49 +00:00
|
|
|
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)
|