| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -39,6 +39,10 @@ async def erase_stats(self): | |||
| 39 | 39 | """ | |
| 40 | 40 | return await self.call("erase_emeter_stat") | |
| 41 | 41 | ||
| 42 | + async def get_realtime(self): | ||
| 43 | + """Return real-time statistics.""" | ||
| 44 | + return await self.call("get_realtime") | ||
| 45 | + | ||
| 42 | 46 | async def get_daystat(self, *, year, month, kwh=True): | |
| 43 | 47 | """Return daily stats for the given year & month.""" | |
| 44 | 48 | raw_data = await super().get_daystat(year=year, month=month) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,8 +2,7 @@ | |||
| 2 | 2 | from enum import Enum | |
| 3 | 3 | from typing import Optional | |
| 4 | 4 | ||
| 5 | - from kasa.smartdevice import SmartDeviceException | ||
| 6 | - | ||
| 5 | + from ..exceptions import SmartDeviceException | ||
| 7 | 6 | from .module import Module | |
| 8 | 7 | ||
| 9 | 8 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,6 +1,7 @@ | |||
| 1 | 1 | """Provides the current time and timezone information.""" | |
| 2 | 2 | from datetime import datetime | |
| 3 | 3 | ||
| 4 | + from ..exceptions import SmartDeviceException | ||
| 4 | 5 | from .module import Module, merge | |
| 5 | 6 | ||
| 6 | 7 | ||
@@ -32,3 +33,22 @@ def timezone(self): | |||
| 32 | 33 | """Return current timezone.""" | |
| 33 | 34 | res = self.data["get_timezone"] | |
| 34 | 35 | return res | |
| 36 | + | ||
| 37 | + async def get_time(self): | ||
| 38 | + """Return current device time.""" | ||
| 39 | + try: | ||
| 40 | + res = await self.call("get_time") | ||
| 41 | + return datetime( | ||
| 42 | + res["year"], | ||
| 43 | + res["month"], | ||
| 44 | + res["mday"], | ||
| 45 | + res["hour"], | ||
| 46 | + res["min"], | ||
| 47 | + res["sec"], | ||
| 48 | + ) | ||
| 49 | + except SmartDeviceException: | ||
| 50 | + return None | ||
| 51 | + | ||
| 52 | + async def get_timezone(self): | ||
| 53 | + """Request timezone information from the device.""" | ||
| 54 | + return await self.call("get_timezone") | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -186,7 +186,6 @@ class SmartDevice: | |||
| 186 | 186 | ||
| 187 | 187 | """ | |
| 188 | 188 | ||
| 189 | - TIME_SERVICE = "time" | ||
| 190 | 189 | emeter_type = "emeter" | |
| 191 | 190 | ||
| 192 | 191 | def __init__(self, host: str) -> None: | |
@@ -314,11 +313,6 @@ async def update(self, update_children: bool = True): | |||
| 314 | 313 | _LOGGER.debug("Performing the initial update to obtain sysinfo") | |
| 315 | 314 | self._last_update = await self.protocol.query(req) | |
| 316 | 315 | self._sys_info = self._last_update["system"]["get_sysinfo"] | |
| 317 | - # If the device has no emeter, we are done for the initial update | ||
| 318 | - # Otherwise we will follow the regular code path to also query | ||
| 319 | - # the emeter data also during the initial update | ||
| 320 | - if not self.has_emeter: | ||
| 321 | - return | ||
| 322 | 316 | ||
| 323 | 317 | if self.has_emeter: | |
| 324 | 318 | _LOGGER.debug( | |
@@ -380,22 +374,17 @@ def timezone(self) -> Dict: | |||
| 380 | 374 | ||
| 381 | 375 | async def get_time(self) -> Optional[datetime]: | |
| 382 | 376 | """Return current time from the device, if available.""" | |
| 383 | - try: | ||
| 384 | - res = await self._query_helper(self.TIME_SERVICE, "get_time") | ||
| 385 | - return datetime( | ||
| 386 | - res["year"], | ||
| 387 | - res["month"], | ||
| 388 | - res["mday"], | ||
| 389 | - res["hour"], | ||
| 390 | - res["min"], | ||
| 391 | - res["sec"], | ||
| 392 | - ) | ||
| 393 | - except SmartDeviceException: | ||
| 394 | - return None | ||
| 377 | + _LOGGER.warning( | ||
| 378 | + "Use `time` property instead, this call will be removed in the future." | ||
| 379 | + ) | ||
| 380 | + return await self.modules["time"].get_time() | ||
| 395 | 381 | ||
| 396 | 382 | async def get_timezone(self) -> Dict: | |
| 397 | 383 | """Return timezone information.""" | |
| 398 | - return await self._query_helper(self.TIME_SERVICE, "get_timezone") | ||
| 384 | + _LOGGER.warning( | ||
| 385 | + "Use `timezone` property instead, this call will be removed in the future." | ||
| 386 | + ) | ||
| 387 | + return await self.modules["time"].get_timezone() | ||
| 399 | 388 | ||
| 400 | 389 | @property # type: ignore | |
| 401 | 390 | @requires_update | |
@@ -433,7 +422,7 @@ def location(self) -> Dict: | |||
| 433 | 422 | loc["latitude"] = sys_info["latitude_i"] / 10000 | |
| 434 | 423 | loc["longitude"] = sys_info["longitude_i"] / 10000 | |
| 435 | 424 | else: | |
| 436 | - _LOGGER.warning("Unsupported device location.") | ||
| 425 | + _LOGGER.debug("Unsupported device location.") | ||
| 437 | 426 | ||
| 438 | 427 | return loc | |
| 439 | 428 | ||
@@ -481,29 +470,7 @@ def emeter_realtime(self) -> EmeterStatus: | |||
| 481 | 470 | async def get_emeter_realtime(self) -> EmeterStatus: | |
| 482 | 471 | """Retrieve current energy readings.""" | |
| 483 | 472 | self._verify_emeter() | |
| 484 | - return EmeterStatus(await self._query_helper(self.emeter_type, "get_realtime")) | ||
| 485 | - | ||
| 486 | - def _create_emeter_request(self, year: int = None, month: int = None): | ||
| 487 | - """Create a Internal method for building a request for all emeter statistics at once.""" | ||
| 488 | - # TODO: this is currently only here for smartstrip plug support, move it there? | ||
| 489 | - if year is None: | ||
| 490 | - year = datetime.now().year | ||
| 491 | - if month is None: | ||
| 492 | - month = datetime.now().month | ||
| 493 | - | ||
| 494 | - req: Dict[str, Any] = {} | ||
| 495 | - merge(req, self._create_request(self.emeter_type, "get_realtime")) | ||
| 496 | - merge( | ||
| 497 | - req, self._create_request(self.emeter_type, "get_monthstat", {"year": year}) | ||
| 498 | - ) | ||
| 499 | - merge( | ||
| 500 | - req, | ||
| 501 | - self._create_request( | ||
| 502 | - self.emeter_type, "get_daystat", {"month": month, "year": year} | ||
| 503 | - ), | ||
| 504 | - ) | ||
| 505 | - | ||
| 506 | - return req | ||
| 473 | + return EmeterStatus(await self.modules["emeter"].get_realtime()) | ||
| 507 | 474 | ||
| 508 | 475 | @property # type: ignore | |
| 509 | 476 | @requires_update | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -39,7 +39,6 @@ class SmartPlug(SmartDevice): | |||
| 39 | 39 | ||
| 40 | 40 | def __init__(self, host: str) -> None: | |
| 41 | 41 | super().__init__(host) | |
| 42 | - self.emeter_type = "emeter" | ||
| 43 | 42 | self._device_type = DeviceType.Plug | |
| 44 | 43 | self.add_module("schedule", Schedule(self, "schedule")) | |
| 45 | 44 | self.add_module("usage", Usage(self, "schedule")) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments