move get_time{zone} out from smartdevice + some minor cleanups

This commit is contained in:
Teemu Rytilahti
2022-01-29 20:36:08 +01:00
committed by Teemu R
parent c8ad99abcb
commit f0d66e4195
5 changed files with 35 additions and 46 deletions

View File

@@ -39,6 +39,10 @@ class Emeter(Usage):
"""
return await self.call("erase_emeter_stat")
async def get_realtime(self):
"""Return real-time statistics."""
return await self.call("get_realtime")
async def get_daystat(self, *, year, month, kwh=True):
"""Return daily stats for the given year & month."""
raw_data = await super().get_daystat(year=year, month=month)

View File

@@ -2,8 +2,7 @@
from enum import Enum
from typing import Optional
from kasa.smartdevice import SmartDeviceException
from ..exceptions import SmartDeviceException
from .module import Module

View File

@@ -1,6 +1,7 @@
"""Provides the current time and timezone information."""
from datetime import datetime
from ..exceptions import SmartDeviceException
from .module import Module, merge
@@ -32,3 +33,22 @@ class Time(Module):
"""Return current timezone."""
res = self.data["get_timezone"]
return res
async def get_time(self):
"""Return current device time."""
try:
res = await self.call("get_time")
return datetime(
res["year"],
res["month"],
res["mday"],
res["hour"],
res["min"],
res["sec"],
)
except SmartDeviceException:
return None
async def get_timezone(self):
"""Request timezone information from the device."""
return await self.call("get_timezone")