Skip to content
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

Add type hints to smart_task.py #456

Merged
merged 15 commits into from
Mar 15, 2022
17 changes: 5 additions & 12 deletions pytradfri/smart_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def __init__(self, gateway: Gateway, raw: TypeRaw) -> None:
"""Initialize the class."""
super().__init__(raw)
self._gateway = gateway
self._delta_time_gateway_local: timedelta = timedelta(0)
self.delta_time_gateway_local: timedelta = timedelta(0)
MartinHjelmare marked this conversation as resolved.
Show resolved Hide resolved

@property
def path(self) -> list[str]:
Expand Down Expand Up @@ -180,15 +180,6 @@ def task_control(self) -> TaskControl:
"""Control a task."""
return TaskControl(self, self.state, self.path, self._gateway)

@property
def delta_time_gateway_local(self) -> timedelta:
"""Return difference between local time and time set on gateway."""
return self._delta_time_gateway_local

@delta_time_gateway_local.setter
def delta_time_gateway_local(self, value: timedelta) -> None:
self._delta_time_gateway_local = value

@property
def start_action(self) -> StartAction:
"""Return start action object."""
Expand Down Expand Up @@ -225,12 +216,14 @@ def calibrate_time(self) -> Command[None]:

def process_result(result: TypeRaw) -> None:
gateway_info: GatewayInfo = GatewayInfo(result)
if gateway_info.current_time is not None:
if gateway_info.current_time:
MartinHjelmare marked this conversation as resolved.
Show resolved Hide resolved
d_now: dt = gateway_info.current_time
d_utcnow: dt = dt.utcnow()
diff: timedelta = d_now - d_utcnow

self._task.delta_time_gateway_local = diff
setattr(self._task, "delta_time_gateway_local", diff)
ggravlingen marked this conversation as resolved.
Show resolved Hide resolved

return None
MartinHjelmare marked this conversation as resolved.
Show resolved Hide resolved

return Command(
"get", [ROOT_GATEWAY, ATTR_GATEWAY_INFO], process_result=process_result
Expand Down