Skip to content

Commit

Permalink
Fix modelling additionals
Browse files Browse the repository at this point in the history
  • Loading branch information
gjohansson-ST committed Jun 4, 2022
1 parent a43417b commit 1d61aef
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
31 changes: 24 additions & 7 deletions pysensibo/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Python API for Sensibo."""
from __future__ import annotations
import asyncio
from datetime import datetime, timezone

import json
from typing import Any
Expand Down Expand Up @@ -179,8 +180,13 @@ async def async_get_devices_data(self) -> SensiboData:
)
filter_clean: bool = filters.get("shouldCleanFilters", False)
clean_time: dict[str, Any] = filters.get("lastFiltersCleanTime") or {}
filter_last_reset: str | None = (
clean_time.get("time") if clean_time else None
clean_time_str: str | None = clean_time.get("time")
filter_last_reset: datetime | None = (
datetime.strptime(clean_time_str, "%Y-%m-%dT%H:%M:%SZ").replace(
tzinfo=timezone.utc
)
if clean_time_str
else None
)

# Timer
Expand All @@ -191,10 +197,17 @@ async def async_get_devices_data(self) -> SensiboData:
timer_time = None
if dev["productModel"] != "pure":
timer_on = timer.get("isEnabled", False)
timer_id = timer.get("id")
timer_state: dict[str, Any] | None = timer.get("acState")
timer_state_on = timer_state.get("on") if timer_state else None
timer_time = timer.get("targetTime")
timer_id = timer.get("id")
timer_state: dict[str, Any] | None = timer.get("acState")
timer_state_on = timer_state.get("on") if timer_state else None
timer_time_str: str | None = timer.get("targetTime")
timer_time = (
datetime.strptime(timer_time_str, "%Y-%m-%dT%H:%M:%S").replace(
tzinfo=timezone.utc
)
if timer_time_str
else None
)

# Smartmode
smart: dict[str, Any] = dev["smartMode"] if dev["smartMode"] else {}
Expand All @@ -212,14 +225,18 @@ async def async_get_devices_data(self) -> SensiboData:
schedules: dict[str, Schedules] = {}
if schedule_list:
for schedule in schedule_list:
next_utc_str: str = schedule["nextTime"]
next_utc = datetime.strptime(
next_utc_str, "%Y-%m-%dT%H:%M:%S"
).replace(tzinfo=timezone.utc)
schedules[schedule["id"]] = Schedules(
id=schedule["id"],
enabled=schedule["isEnabled"],
state_on=schedule["acState"].get("on"),
state_full=schedule["acState"],
days=schedule["recurringDays"],
time=schedule["targetTimeLocal"],
next_utc=schedule["nextTime"],
next_utc=next_utc,
)

device_data[unique_id] = SensiboDevice(
Expand Down
7 changes: 4 additions & 3 deletions pysensibo/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from __future__ import annotations

from dataclasses import dataclass
from datetime import datetime
from typing import Any


Expand Down Expand Up @@ -62,15 +63,15 @@ class SensiboDevice:
timer_on: bool | None
timer_id: str | None
timer_state_on: bool | None
timer_time: str | None
timer_time: datetime | None
smart_on: bool | None
smart_type: str | None
smart_low_temp_threshold: float | None
smart_high_temp_threshold: float | None
smart_low_state: dict[str, Any] | None
smart_high_state: dict[str, Any] | None
filter_clean: bool
filter_last_reset: str | None
filter_last_reset: datetime | None


@dataclass
Expand Down Expand Up @@ -100,4 +101,4 @@ class Schedules:
state_full: dict[str, Any]
days: list[str]
time: str
next_utc: str
next_utc: datetime
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
print(find_packages())
setup(
name="pysensibo",
version="1.0.15",
version="1.0.16",
description="asyncio-friendly python API for Sensibo",
long_description="asyncio-friendly python API for Sensibo"
"(https://sensibo.com). Requires Python 3.4+",
Expand Down

0 comments on commit 1d61aef

Please sign in to comment.