From ae31d3b2e68a6d289891159ae6ec40247efb2b0b Mon Sep 17 00:00:00 2001 From: vlebourl Date: Wed, 3 Jun 2020 15:15:23 +0200 Subject: [PATCH 1/2] Removed submodule --- .gitignore | 2 ++ .gitmodules | 3 --- custom_components/tahoma_extended/pyhoma | 1 - custom_components/tahoma_extended/pyhoma.py | 0 4 files changed, 2 insertions(+), 4 deletions(-) delete mode 160000 custom_components/tahoma_extended/pyhoma create mode 100644 custom_components/tahoma_extended/pyhoma.py diff --git a/.gitignore b/.gitignore index bd7db93..49445a4 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,5 @@ /.idea/inspectionProfiles/Project_Default.xml /.idea/tahoma_extended.iml /.idea/vcs.xml + +devices.txt diff --git a/.gitmodules b/.gitmodules index e7098f3..e69de29 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +0,0 @@ -[submodule "custom_components/tahoma_extended/pyhoma"] - path = custom_components/tahoma_extended/pyhoma - url = https://github.com/vlebourl/pyhoma diff --git a/custom_components/tahoma_extended/pyhoma b/custom_components/tahoma_extended/pyhoma deleted file mode 160000 index 7f82d3d..0000000 --- a/custom_components/tahoma_extended/pyhoma +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 7f82d3da68f81141a6b065262d242db73fa297a1 diff --git a/custom_components/tahoma_extended/pyhoma.py b/custom_components/tahoma_extended/pyhoma.py new file mode 100644 index 0000000..e69de29 From f5a613bab723446d3fbfda2434d2113a2243e015 Mon Sep 17 00:00:00 2001 From: vlebourl Date: Wed, 3 Jun 2020 15:16:32 +0200 Subject: [PATCH 2/2] move custom component to pyhoma instead of tahoma-api --- custom_components/tahoma_extended/__init__.py | 2 +- custom_components/tahoma_extended/pyhoma.py | 1159 +++++++++++++++++ 2 files changed, 1160 insertions(+), 1 deletion(-) diff --git a/custom_components/tahoma_extended/__init__.py b/custom_components/tahoma_extended/__init__.py index a4509c5..bce9a16 100755 --- a/custom_components/tahoma_extended/__init__.py +++ b/custom_components/tahoma_extended/__init__.py @@ -3,7 +3,7 @@ import logging from requests.exceptions import RequestException -from .pyhoma.pyhoma import Action, PyHoma +from .pyhoma import Action, PyHoma import voluptuous as vol from homeassistant.const import CONF_EXCLUDE, CONF_PASSWORD, CONF_USERNAME diff --git a/custom_components/tahoma_extended/pyhoma.py b/custom_components/tahoma_extended/pyhoma.py index e69de29..f82a4dd 100644 --- a/custom_components/tahoma_extended/pyhoma.py +++ b/custom_components/tahoma_extended/pyhoma.py @@ -0,0 +1,1159 @@ +""" +Connection to Tahoma API. + +Connection to Somfy Tahoma REST API +""" + +import json +import requests +import urllib.parse + +BASE_URL = 'https://tahomalink.com/enduser-mobile-web/enduserAPI/' # /doc for API doc +BASE_HEADERS = {'User-Agent': 'mine'} + +class PyHoma: + """Connection to Tahoma API.""" + + def __init__(self, userName, userPassword, **kwargs): + """Initalize the Tahoma protocol. + + :param userName: Tahoma username + :param userPassword: Password + :param kwargs: Ignore, only for unit test reasons + """ + self.__devices = {} + self.__gateway = {} + self.__location = {} + self.__cookie = "" + self.__logged_in = False + self.__events_registration = None + self.__username = userName + self.__password = userPassword + self.__setup = None + self.login() + + def login(self): + """Login to Tahoma API.""" + if self.__logged_in: + return + login = {'userId': self.__username, 'userPassword': self.__password} + header = BASE_HEADERS.copy() + request = requests.post(BASE_URL + 'login', + data=login, + headers=header, + timeout=10) + + try: + result = request.json() + except ValueError as error: + raise Exception( + "Not a valid result for login, " + + "protocol error: " + request.status_code + ' - ' + + request.reason + "(" + error + ")") + + if 'error' in result.keys(): + raise Exception("Could not login: " + result['error']) + + if request.status_code != 200: + raise Exception( + "Could not login, HTTP code: " + + str(request.status_code) + ' - ' + request.reason) + + if 'success' not in result.keys() or not result['success']: + raise Exception("Could not login, no success") + + cookie = request.headers.get("set-cookie") + if cookie is None: + raise Exception("Could not login, no cookie set") + + self.__cookie = cookie + self.__logged_in = True + return self.__logged_in + + def get_user(self): + """Get the user informations from the server. + + :return: a dict with all the informations + :rtype: dict + + raises ValueError in case of protocol issues + + :Example: + + >>> "creationTime":