diff --git a/CHANGELOG.md b/CHANGELOG.md index 681dfc2..e6d9230 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Change Log +## 1.10.3 +- Added the ability to send a POST to the session endpoint for PubNub fix + ## 1.10.2 - Added get_eggs which returns the times of each egg in an eggminder diff --git a/src/pywink/__init__.py b/src/pywink/__init__.py index 5389198..403f4e6 100644 --- a/src/pywink/__init__.py +++ b/src/pywink/__init__.py @@ -6,7 +6,7 @@ set_wink_credentials, set_user_agent, wink_api_fetch, get_devices, \ get_subscription_key, get_user, get_authorization_url, \ request_token, legacy_set_wink_credentials, get_current_oauth_credentials, \ - disable_local_control + disable_local_control, post_session from pywink.api import get_light_bulbs, get_garage_doors, get_locks, \ get_powerstrips, get_shades, get_sirens, \ diff --git a/src/pywink/api.py b/src/pywink/api.py index 152a64b..d57f7b0 100644 --- a/src/pywink/api.py +++ b/src/pywink/api.py @@ -2,6 +2,7 @@ import time import logging import urllib.parse +import random import requests @@ -329,13 +330,11 @@ def piggy_bank_deposit(self, device, _json): url_string = "{}/{}s/{}/deposits".format(self.BASE_URL, device.object_type(), device.object_id()) - print(url_string) try: arequest = requests.post(url_string, data=json.dumps(_json), headers=API_HEADERS) response_json = arequest.json() - print(json.dumps(response_json, indent=4, sort_keys=True)) return response_json except requests.exceptions.RequestException: return None @@ -462,6 +461,28 @@ def get_user(): return arequest.json() +def post_session(): + """ + This endpoint appears to be required in order to keep pubnub updates flowing for some user. + + This just posts a random nonce to the /users/me/session endpoint and returns the result. + """ + + url_string = "{}/users/me/session".format(WinkApiInterface.BASE_URL) + + nonce = ''.join([str(random.randint(0, 9)) for i in range(9)]) + _json = {"nonce": str(nonce)} + + try: + arequest = requests.post(url_string, + data=json.dumps(_json), + headers=API_HEADERS) + response_json = arequest.json() + return response_json + except requests.exceptions.RequestException: + return None + + def get_local_control_access_token(local_control_id): _LOGGER.debug("Local_control_id: %s", local_control_id) if CLIENT_ID and CLIENT_SECRET and REFRESH_TOKEN: diff --git a/src/setup.py b/src/setup.py index d4ba04c..4e2fbdc 100644 --- a/src/setup.py +++ b/src/setup.py @@ -1,7 +1,7 @@ from setuptools import setup, find_packages setup(name='python-wink', - version='1.10.2', + version='1.10.3', description='Access Wink devices via the Wink API', url='http://github.com/python-wink/python-wink', author='Brad Johnson, William Scanlon',