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

Fixes for home assistant #47

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,3 @@ coloredlogs = "~=10.0"
requests = "~=2.22.0"
cachetools = "~=3.1.1"
dateparser = "~=0.7.1"
backoff = "~=1.9.2"
8 changes: 0 additions & 8 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@
coloredlogs~=10.0
requests~=2.22.0
cachetools~=3.1.1
dateparser~=0.7.2
backoff~=1.9.2
dateparser~=0.7.2
8 changes: 2 additions & 6 deletions toonapilib/toonapilib.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@

import logging

import backoff
import coloredlogs
from cachetools import TTLCache, cached
from requests import Session
Expand Down Expand Up @@ -170,15 +169,14 @@ def _reset(self):

@property
@cached(STATE_CACHE)
@backoff.on_exception(backoff.expo, IncompleteStatus)
def status(self):
"""The status of toon, cached for 300 seconds."""
url = '{api_url}/status'.format(api_url=self._api_url)
response = self._session.get(url)
if response.status_code == 202:
self._logger.debug('Response accepted but no data yet, '
'trying one more time...')
response = self._session.get(url)
response = self._session.get(url)
try:
data = response.json()
except ValueError:
Expand All @@ -188,15 +186,14 @@ def status(self):

@property
@cached(THERMOSTAT_STATE_CACHE)
@backoff.on_exception(backoff.expo, IncompleteStatus)
def thermostat_states(self):
"""The thermostat states of toon, cached for 1 hour."""
url = '{api_url}/thermostat/states'.format(api_url=self._api_url)
response = self._session.get(url)
if response.status_code == 202:
self._logger.debug('Response accepted but no data yet, '
'trying one more time...')
response = self._session.get(url)
response = self._session.get(url)
try:
states = response.json().get('state', [])
except ValueError:
Expand Down Expand Up @@ -279,7 +276,6 @@ def get_smartplug_by_name(self, name):
return next((plug for plug in self.smartplugs
if plug.name.lower() == name.lower()), None)

@backoff.on_exception(backoff.expo, IncompleteStatus)
def _get_status_value(self, value):
try:
output = self.status[value]
Expand Down