mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-01-09 06:17:08 +00:00
Use device time for on_since for smartstripplugs
This commit is contained in:
parent
bb013e75da
commit
c8ad99abcb
@ -13,7 +13,7 @@ from kasa.smartdevice import (
|
|||||||
)
|
)
|
||||||
from kasa.smartplug import SmartPlug
|
from kasa.smartplug import SmartPlug
|
||||||
|
|
||||||
from .modules import Antitheft, Countdown, Schedule, Time, Usage
|
from .modules import Antitheft, Countdown, Emeter, Schedule, Time, Usage
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -87,6 +87,7 @@ class SmartStrip(SmartDevice):
|
|||||||
self.add_module("usage", Usage(self, "schedule"))
|
self.add_module("usage", Usage(self, "schedule"))
|
||||||
self.add_module("time", Time(self, "time"))
|
self.add_module("time", Time(self, "time"))
|
||||||
self.add_module("countdown", Countdown(self, "countdown"))
|
self.add_module("countdown", Countdown(self, "countdown"))
|
||||||
|
self.add_module("emeter", Emeter(self, "emeter"))
|
||||||
|
|
||||||
@property # type: ignore
|
@property # type: ignore
|
||||||
@requires_update
|
@requires_update
|
||||||
@ -255,10 +256,32 @@ class SmartStripPlug(SmartPlug):
|
|||||||
|
|
||||||
Needed for properties that are decorated with `requires_update`.
|
Needed for properties that are decorated with `requires_update`.
|
||||||
"""
|
"""
|
||||||
|
# TODO: it needs to be checked if this still works after modularization
|
||||||
self._last_update = await self.parent.protocol.query(
|
self._last_update = await self.parent.protocol.query(
|
||||||
self._create_emeter_request()
|
self._create_emeter_request()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def _create_emeter_request(self, year: int = None, month: int = None):
|
||||||
|
"""Create a request for requesting all emeter statistics at once."""
|
||||||
|
if year is None:
|
||||||
|
year = datetime.now().year
|
||||||
|
if month is None:
|
||||||
|
month = datetime.now().month
|
||||||
|
|
||||||
|
req: Dict[str, Any] = {}
|
||||||
|
from .smartdevice import merge
|
||||||
|
|
||||||
|
merge(req, self._create_request("emeter", "get_realtime"))
|
||||||
|
merge(req, self._create_request("emeter", "get_monthstat", {"year": year}))
|
||||||
|
merge(
|
||||||
|
req,
|
||||||
|
self._create_request(
|
||||||
|
"emeter", "get_daystat", {"month": month, "year": year}
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
return req
|
||||||
|
|
||||||
def _create_request(
|
def _create_request(
|
||||||
self, target: str, cmd: str, arg: Optional[Dict] = None, child_ids=None
|
self, target: str, cmd: str, arg: Optional[Dict] = None, child_ids=None
|
||||||
):
|
):
|
||||||
@ -325,7 +348,7 @@ class SmartStripPlug(SmartPlug):
|
|||||||
info = self._get_child_info()
|
info = self._get_child_info()
|
||||||
on_time = info["on_time"]
|
on_time = info["on_time"]
|
||||||
|
|
||||||
return datetime.now() - timedelta(seconds=on_time)
|
return self.time - timedelta(seconds=on_time)
|
||||||
|
|
||||||
@property # type: ignore
|
@property # type: ignore
|
||||||
@requires_update
|
@requires_update
|
||||||
|
Loading…
Reference in New Issue
Block a user