mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-08-08 03:34:02 +00:00
move get_time{zone} out from smartdevice + some minor cleanups
This commit is contained in:
@@ -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)
|
||||
|
@@ -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
|
||||
|
||||
|
||||
|
@@ -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")
|
||||
|
Reference in New Issue
Block a user