Return on_since only when its available and the device is on (#48)

* moves on_since property to smartdevice class, as it is not plug only
* returns None if the value is not available (some bulbs), or if the device is off
This commit is contained in:
Teemu R
2020-04-24 16:47:57 +02:00
committed by GitHub
parent fd560442a2
commit 0c71957aa8
5 changed files with 54 additions and 26 deletions

View File

@@ -1,5 +1,4 @@
"""Module for plugs."""
import datetime
import logging
from typing import Any, Dict
@@ -81,18 +80,6 @@ class SmartPlug(SmartDevice):
await self._query_helper("system", "set_led_off", {"off": int(not state)})
await self.update()
@property # type: ignore
@requires_update
def on_since(self) -> datetime.datetime:
"""Return pretty-printed on-time.
:return: datetime for on since
:rtype: datetime
"""
on_time = self.sys_info["on_time"]
return datetime.datetime.now() - datetime.timedelta(seconds=on_time)
@property # type: ignore
@requires_update
def state_information(self) -> Dict[str, Any]: