-
-
Notifications
You must be signed in to change notification settings - Fork 223
Create common Time module and add time set cli command #1157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
52a2f44
fc6e004
c2c1217
da0361a
c7c618b
6f138f6
b975cef
18c39c7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,7 +51,7 @@ | |
schedule | ||
usage | ||
anti_theft | ||
time | ||
Time | ||
cloud | ||
Led | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
"""Module for time interface.""" | ||
|
||
from __future__ import annotations | ||
|
||
from abc import ABC, abstractmethod | ||
from datetime import datetime, tzinfo | ||
|
||
from ..module import Module | ||
|
||
|
||
class Time(Module, ABC): | ||
"""Base class for tplink time module.""" | ||
|
||
@property | ||
@abstractmethod | ||
def time(self) -> datetime: | ||
"""Return timezone aware current device time.""" | ||
|
||
@property | ||
@abstractmethod | ||
def timezone(self) -> tzinfo: | ||
"""Return current timezone.""" | ||
|
||
@abstractmethod | ||
async def set_time(self, dt: datetime) -> dict: | ||
"""Set the device time.""" | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ | |
from collections.abc import Mapping, Sequence | ||
from datetime import datetime, timedelta, tzinfo | ||
from typing import TYPE_CHECKING, Any, cast | ||
from warnings import warn | ||
|
||
from ..device import Device, WifiNetwork | ||
from ..deviceconfig import DeviceConfig | ||
|
@@ -460,27 +461,27 @@ | |
@requires_update | ||
def time(self) -> datetime: | ||
"""Return current time from the device.""" | ||
return self.modules[Module.IotTime].time | ||
return self.modules[Module.Time].time | ||
|
||
@property | ||
@requires_update | ||
def timezone(self) -> tzinfo: | ||
"""Return the current timezone.""" | ||
return self.modules[Module.IotTime].timezone | ||
return self.modules[Module.Time].timezone | ||
|
||
async def get_time(self) -> datetime | None: | ||
async def get_time(self) -> datetime: | ||
"""Return current time from the device, if available.""" | ||
_LOGGER.warning( | ||
"Use `time` property instead, this call will be removed in the future." | ||
) | ||
return await self.modules[Module.IotTime].get_time() | ||
msg = "Use `time` property instead, this call will be removed in the future." | ||
warn(msg, DeprecationWarning, stacklevel=1) | ||
return self.time | ||
Comment on lines
+472
to
+476
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should probably drop this and all other "this call will be removed in the future" marked functions, but that could be done in a separate PR. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was thinking it could be about time to drop all of the deprecated support and making the next release 0.8.0. What do you think? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It hasn't been that long since the large refactor, so I'd tend to say that we keep them for the time being. Or is there some specific reason we should already go for a 0.8 and break things right away? |
||
|
||
async def get_timezone(self) -> dict: | ||
async def get_timezone(self) -> tzinfo: | ||
"""Return timezone information.""" | ||
_LOGGER.warning( | ||
msg = ( | ||
"Use `timezone` property instead, this call will be removed in the future." | ||
) | ||
return await self.modules[Module.IotTime].get_timezone() | ||
warn(msg, DeprecationWarning, stacklevel=1) | ||
return self.timezone | ||
|
||
@property # type: ignore | ||
@requires_update | ||
|
Uh oh!
There was an error while loading. Please reload this page.