Skip to content

Commit

Permalink
cleaning up logging
Browse files Browse the repository at this point in the history
  • Loading branch information
jeeftor committed Oct 24, 2023
1 parent 0460811 commit 36d5c5e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 22 deletions.
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 = "3.1.14"
version = "3.1.15"
description = "Intellifire4Py"
authors = ["Jeff Stein <[email protected]>"]
license = "MIT"
Expand Down
22 changes: 10 additions & 12 deletions src/intellifire4py/cloud_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ def data(self) -> IntelliFirePollData:
if (
self._data.ipv4_address == "127.0.0.1"
): # pragma: no cover - the tests SHOULD be hitting this but dont appear to be
self._log.warning(
"CLOUD::Returning uninitialized poll data"
) # pragma: no cover
self._log.warning("Returning uninitialized poll data") # pragma: no cover
return self._data

@property
Expand Down Expand Up @@ -254,15 +252,15 @@ async def long_poll(self, fireplace: IntelliFireFireplace | None = None) -> bool
serial = self.default_fireplace.serial
else:
serial = fireplace.serial
self._log.debug("CLOUD::Long Poll: Start")
self._log.debug("Long Poll: Start")
response = await client.get(
f"{self.prefix}://iftapi.net/a/{serial}/applongpoll"
)
if response.status_code == 200:
self._log.debug("CLOUD::Long poll: 200 - Received data ")
self._log.debug("Long poll: 200 - Received data ")
return True
elif response.status_code == 408:
self._log.debug("CLOUD::Long poll: 408 - No Data changed")
self._log.debug("Long poll: 408 - No Data changed")
return False
elif (
response.status_code == 403
Expand Down Expand Up @@ -344,7 +342,7 @@ async def start_background_polling(self, minimum_wait_in_seconds: int = 10) -> N

if not self._should_poll_in_background:
self._should_poll_in_background = True
self._log.info("!! CLOUD::start_background_polling !!")
self._log.info("!! start_background_polling !!")

# Do an initial poll to set data first
await self.poll()
Expand All @@ -367,11 +365,11 @@ async def stop_background_polling(self) -> bool:

async def __background_poll(self, minimum_wait_in_seconds: int = 10) -> None:
"""Start a looping cloud background longpoll task."""
self._log.debug("CLOUD::__background_poll:: Function Called")
self._log.debug("__background_poll:: Function Called")
self._is_polling_in_background = True
while self._should_poll_in_background:
start = time.time()
self._log.debug("CLOUD::__background_poll:: Loop start time %f", start)
self._log.debug("__background_poll:: Loop start time %f", start)

try:
new_data = await self.long_poll()
Expand All @@ -382,12 +380,12 @@ async def __background_poll(self, minimum_wait_in_seconds: int = 10) -> None:
duration: float = end - start
sleep_time: float = minimum_wait_in_seconds - duration
self._log.debug(
"CLOUD::__background_poll:: [%f] Sleeping for [%fs]",
"__background_poll:: [%f] Sleeping for [%fs]",
duration,
sleep_time,
)
self._log.debug(
"CLOUD::__background_poll:: duration: %f, %f, %.2fs",
"__background_poll:: duration: %f, %f, %.2fs",
start,
end,
(end - start),
Expand All @@ -396,4 +394,4 @@ async def __background_poll(self, minimum_wait_in_seconds: int = 10) -> None:
except Exception as ex:
self._log.error(ex)
self._is_polling_in_background = False
self._log.info("CLOUD::__background_poll:: Background polling disabled.")
self._log.info("__background_poll:: Background polling disabled.")
18 changes: 9 additions & 9 deletions src/intellifire4py/local_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def _needs_login(self) -> bool:
def data(self) -> IntelliFirePollData:
"""Return data to the user."""
if self._data.serial == "unset":
self._log.warning("LOCAL::Returning uninitialized poll data")
self._log.warning("Returning uninitialized poll data")
return self._data

@property
Expand All @@ -106,7 +106,7 @@ async def start_background_polling(self, minimum_wait_in_seconds: int = 15) -> N

if not self._should_poll_in_background:
self._should_poll_in_background = True
self._log.info("!! LOCAL::start_background_polling !!")
self._log.info("!! start_background_polling !!")

self._bg_task = asyncio.create_task(
self.__background_poll(minimum_wait_in_seconds),
Expand All @@ -127,14 +127,14 @@ async def stop_background_polling(self) -> bool:

async def __background_poll(self, minimum_wait_in_seconds: int = 10) -> None:
"""Perform a polling loop."""
self._log.debug("LOCAL::__background_poll:: Function Called")
self._log.debug("__background_poll:: Function Called")

self.failed_poll_attempts = 0

self._is_polling_in_background = True
while self._should_poll_in_background:
start = time.time()
self._log.debug("LOCAL::__background_poll:: Loop start time %f", start)
self._log.debug("__background_poll:: Loop start time %f", start)

try:
await self.poll()
Expand All @@ -145,32 +145,32 @@ async def __background_poll(self, minimum_wait_in_seconds: int = 10) -> None:
sleep_time: float = minimum_wait_in_seconds - duration

self._log.debug(
"LOCAL::__background_poll:: [%f] Sleeping for [%fs]",
"__background_poll:: [%f] Sleeping for [%fs]",
duration,
sleep_time,
)

self._log.debug(
"LOCAL::__background_poll:: duration: %f, %f, %.2fs",
"__background_poll:: duration: %f, %f, %.2fs",
start,
end,
(end - start),
)
self._log.debug(
"LOCAL::__background_poll:: Should Sleep For: %f",
"__background_poll:: Should Sleep For: %f",
(minimum_wait_in_seconds - (end - start)),
)

await asyncio.sleep(minimum_wait_in_seconds - (end - start))
except httpx.ReadTimeout:
self.failed_poll_attempts += 1
self._log.info(
"LOCAL::__background_poll:: Polling error [x%d]",
"__background_poll:: Polling error [x%d]",
self.failed_poll_attempts,
)

self._is_polling_in_background = False
self._log.info("LOCAL::__background_poll:: Background polling disabled.")
self._log.info("__background_poll:: Background polling disabled.")

async def poll(self, suppress_warnings: bool = False) -> None:
"""Read the /poll endpoint.
Expand Down

0 comments on commit 36d5c5e

Please sign in to comment.