Skip to content

Commit

Permalink
adding tz back in
Browse files Browse the repository at this point in the history
  • Loading branch information
jeeftor committed Jan 28, 2024
1 parent 0011404 commit b64c31c
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 14 deletions.
14 changes: 10 additions & 4 deletions example_cloud_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from intellifire4py import UnifiedFireplace # type: ignore[import-not-found]
from intellifire4py.cloud_interface import IntelliFireCloudInterface # type: ignore[import-not-found]
from intellifire4py.const import IntelliFireApiMode

FORMAT = "%(message)s"
logging.basicConfig(
Expand Down Expand Up @@ -76,9 +77,7 @@ async def main() -> None:
"""Define main function."""
username, password = get_creds()

cloud_api_interface = (
IntelliFireCloudInterface()
) # use_http=True, verify_ssl=False)
cloud_api_interface = IntelliFireCloudInterface(use_http=True, verify_ssl=False)

# await cloud_api_interface.login_with_cookie(cookie=Cookies())
user_json: str = os.getenv("USER_JSON") # type: ignore
Expand All @@ -95,7 +94,9 @@ async def main() -> None:
#
fireplaces: list[
UnifiedFireplace
] = await UnifiedFireplace.build_fireplaces_from_user_data(user_data)
] = await UnifiedFireplace.build_fireplaces_from_user_data(
user_data, use_http=True, verify_ssl=False
)

fireplace = fireplaces[0] # type: ignore

Expand All @@ -104,6 +105,11 @@ async def main() -> None:
local, cloud = await _async_validate_connectivity(fireplace)

print(local, cloud)

# Set Cloud Mode
await fireplace.set_read_mode(IntelliFireApiMode.CLOUD)
await asyncio.sleep(60)

#
# await fireplace.set_read_mode(IntelliFireApiMode.LOCAL)
# await fireplace.set_control_mode(IntelliFireApiMode.CLOUD)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "intellifire4py"
version = "4.1.8"
version = "4.1.9"
description = "Intellifire4Py"
authors = ["Jeff Stein <[email protected]>"]
license = "MIT"
Expand Down
10 changes: 5 additions & 5 deletions src/intellifire4py/cloud_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from __future__ import annotations
import time
import asyncio
from datetime import datetime
from datetime import datetime, timezone

from asyncio import Task
from typing import Any
Expand Down Expand Up @@ -148,7 +148,7 @@ async def _send_cloud_command(
422 Invalid Parameter (invalid command id or command value)
"""
if response.status == 204:
self._last_send = datetime.now()
self._last_send = datetime.now(timezone.utc)
return
# elif (
# response.status == 403
Expand Down Expand Up @@ -207,11 +207,11 @@ async def long_poll(self) -> bool:
self._data = IntelliFirePollData(**json_data)
self._log.debug(f"poll() complete: {self._data}")

self._last_poll = datetime.now()
self._last_poll = datetime.now(timezone.utc)
return True
elif response.status == 408:
self._log.debug("Long poll: 408 - No Data changed")
self._last_poll = datetime.now()
self._last_poll = datetime.now(timezone.utc)
return False
except aiohttp.ClientResponseError as e:
if e.status == 403:
Expand Down Expand Up @@ -288,7 +288,7 @@ async def poll(self, timeout_seconds: float = 10.0) -> None:
self._data = IntelliFirePollData(**json_data)
self._log.debug(f"poll() complete: {self._data}")

self._last_poll = datetime.now()
self._last_poll = datetime.now(timezone.utc)

except aiohttp.ClientResponseError as e:
if e.status == 403:
Expand Down
6 changes: 3 additions & 3 deletions src/intellifire4py/local_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from .utils import _range_check
import aiohttp

from datetime import datetime
from datetime import datetime, timezone


class IntelliFireAPILocal(IntelliFireController, IntelliFireDataProvider):
Expand Down Expand Up @@ -205,7 +205,7 @@ async def poll(
json_data = await response.json(content_type=None)
self._data = IntelliFirePollData(**json_data)
self._log.debug(f"poll() complete: {self._data}")
self._last_poll = datetime.now()
self._last_poll = datetime.now(timezone.utc)
except JSONDecodeError as error:
if not suppress_warnings:
self._log.warning("Error decoding JSON: [%s]", response.text)
Expand Down Expand Up @@ -339,7 +339,7 @@ async def _send_local_command(
self._log.debug(
"_send_local_command:: Response Code [%d]", resp.status
)
self._last_send = datetime.now()
self._last_send = datetime.now(timezone.utc)
except asyncio.TimeoutError as error:
self._log.warning("Control Endpoint Timeout Error %s", error)
continue
Expand Down
2 changes: 1 addition & 1 deletion src/intellifire4py/read.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def __init__(self) -> None:
pass

@property
def last_poll(self) -> datetime | None:
def last_poll_utc(self) -> datetime | None:
"""Return the last poll time."""
return self._last_poll

Expand Down

0 comments on commit b64c31c

Please sign in to comment.