MadPatrick / somfy

Tahoma/Conexoon plugin for IO blinds, this plugin require internet connexion and a Somfy account
GNU General Public License v3.0
14 stars 3 forks source link

Create access to local API #15

Closed JanJaapKo closed 1 year ago

JanJaapKo commented 1 year ago

The Somfy box offers also a local API, which will replace at some point the web based API. With this improvement we will add support from the plugin to the local API.

API description: https://github.com/Somfy-Developer/Somfy-TaHoma-Developer-Mode

ab10002 commented 1 year ago

I'v allready started with this. First thing needed, is readout the paramaters from the local box

MadPatrick commented 1 year ago

How can you read out the parameters form the local Box ? Have you a small detailed instruction

ab10002 commented 1 year ago

Not yet, Somfy having issue on this

JanJaapKo commented 1 year ago

@ab10002 Can you create a branch and push it? I've got a branch ready to be merged on the new extended framework (allowing more than 1 action on a somfy device, like up/down+orientation for venetian blinds). The local API needs to moved there too.

ab10002 commented 1 year ago

I'm not really familiar with github

MadPatrick commented 1 year ago

Where do you have the script located. Maybe i can help

ab10002 commented 1 year ago

Where do you have the script located. Maybe i can help

import requests
import json

MY_EMAIL = "some@domain.com"
MY_PASSWORD = "Xxxxx"
MY_PIN = "0000-0000-0000"

s = requests.Session()

## Login
headers = {"Content-Type": "application/x-www-form-urlencoded"}
data = {"userId": MY_EMAIL, "userPassword": MY_PASSWORD}
url = "https://ha101-1.overkiz.com/enduser-mobile-web/enduserAPI/login"
r = s.post(url, headers=headers, data=data)
print (r)
r.status_code
200

## Generate a token
url_gen = "https://ha101-1.overkiz.com/enduser-mobile-web/enduserAPI/config/MY_PIN/local/tokens/generate"
headers_gen = {"Content-Type": "application/json"}
r_gen = s.get(url_gen, headers=headers_gen)
print (r_gen)
r_gen.status_code
200
r_gen.text
'{"token":"XXXXXXXXXXXXXXXX"}'

## Activate your token
url_act = "https://ha101-1.overkiz.com/enduser-mobile-web/enduserAPI/config/MY_PIN/local/tokens"
headers_act = {"Content-Type": "application/json"}
data_act = {"label": "My token", "token": r_gen.json()['token'], "scope": "devmode"}
r_act = s.post(url_act, headers=headers_act, json=data_act)

r_act.status_code
200
ab10002 commented 1 year ago

Working script:

import requests
import json

MY_EMAIL = {"some@domain.com"}
MY_PASSWORD = {"abcdef"}
MY_PIN = {"0000-0000-0000"}

s = requests.Session()

## Login
headers = {"Content-Type": "application/x-www-form-urlencoded"}
data = {"userId": MY_EMAIL, "userPassword": MY_PASSWORD}
url = "https://ha101-1.overkiz.com/enduser-mobile-web/enduserAPI/login"
r = s.post(url, headers=headers, data=data)

r.status_code

## Generate a token
url_gen = "https://ha101-1.overkiz.com/enduser-mobile-web/enduserAPI/config/MY_PIN/local/tokens/generate"
headers_gen = {"Content-Type": "application/json"}
#r_gen = s.get(url_gen, headers=headers_gen)
r_gen = requests.get(url_gen, headers=headers_gen, cookies=r.cookies)

r_gen.status_code

r_gen.text
'{"token":"XXXXXXXXXXXXXXXX"}'

## Activate your token
url_act = "https://ha101-1.overkiz.com/enduser-mobile-web/enduserAPI/config/MY_PIN/local/tokens"
headers_act = {"Content-Type": "application/json"}
data_act = {"label": "My token", "token": r_gen.json()['token'], "scope": "devmode"}
r_act = s.post(url_act, headers=headers_act, json=data_act)

r_act.status_code
JanJaapKo commented 1 year ago

@ab10002 , As soon as the other branch is merged (#7 ) I will prepare a branch to do this work on. If you want to know more on the use of github, I always use this link for basic commands: Git on the command line

ab10002 commented 1 year ago

Did you look into this? I'v stuck on authorization to localbox. Overkiz issues? Tried a lot of things..

And the certificate didn't accept gateway before the host. But that can be solved by adding into host file

UPDATE: create your token https://dev.duboc.pro/overkiz And this is working!

curl GET 'https://yourpin.local:8443/enduser-mobile-web/1/enduserAPI/setup' \
-H 'accept: application/json' \
-H 'Authorization: Bearer yourtoken'
ab10002 commented 1 year ago

I'm local connected, Domoticz/plugin <> tahomabox

JanJaapKo commented 1 year ago

Hi @ab10002 , @MadPatrick ,

I put the work of Ab into a structure to take it further. can you please test it in command line mode by: cd domoticz/plugins/somfy python3 test_tahoma.py you should go about items 1, (optionally 3), 4, 5, 6 and let me know what happens?

Oh btw, you need to enter your credentials and pin in the file params.py. Results will be logged to a local file called somfy_test.log. Your credentials will be exposed in the logging.

ab10002 commented 1 year ago

pi@vm-domoticz:~/domoticz/plugins/somfy$ python3 test_tahoma.py Traceback (most recent call last): File "test_tahoma.py", line 4, in import consolemenu ModuleNotFoundError: No module named 'consolemenu'

After pip3 install consolemenu: Successfully installed consolemenu-1.0.1 pi@vm-domoticz:~/domoticz/plugins/somfy$ python3 test_tahoma.py Traceback (most recent call last): File "test_tahoma.py", line 15, in mymenu = consolemenu.SelectionMenu(menuoptions) AttributeError: module 'consolemenu' has no attribute 'SelectionMenu'

MadPatrick commented 1 year ago

`python3 test_tahoma.py 0 exit 1 log in 2 register 3 check log in 4 generate toke 5 activate token 6 get tokes 7 get devices 8 get events 9 send command Please Select:1

Traceback (most recent call last): File "/usr/lib/python3.6/site-packages/requests/packages/urllib3/connectionpool.py", line 376, in _make_request self._validate_conn(conn) File "/usr/lib/python3.6/site-packages/requests/packages/urllib3/connectionpool.py", line 994, in _validate_conn conn.connect() File "/usr/lib/python3.6/site-packages/requests/packages/urllib3/connection.py", line 408, in connect sslcontext=context, File "/usr/lib/python3.6/site-packages/requests/packages/urllib3/util/ssl.py", line 370, in ssl_wrap_socket return context.wrap_socket(sock, server_hostname=server_hostname) File "/usr/lib64/python3.6/ssl.py", line 365, in wrap_socket _context=self, _session=session) File "/usr/lib64/python3.6/ssl.py", line 776, in init self.do_handshake() File "/usr/lib64/python3.6/ssl.py", line 1036, in do_handshake self._sslobj.do_handshake() File "/usr/lib64/python3.6/ssl.py", line 648, in do_handshake self._sslobj.do_handshake() socket.timeout: _ssl.c:860: The handshake operation timed out `

The Somfy site looks offline, so i'll try later again

MadPatrick commented 1 year ago

Somfy website is working again

` python3 test_tahoma.py 0 exit 1 log in 2 register 3 check log in 4 generate toke 5 activate token 6 get tokes 7 get devices 8 get events 9 send command Please Select:1 1 Press Enter to continue...

0 exit 1 log in 2 register 3 check log in 4 generate toke 5 activate token 6 get tokes 7 get devices 8 get events 9 send command Please Select:3 3 True Press Enter to continue...

0 exit 1 log in 2 register 3 check log in 4 generate toke 5 activate token 6 get tokes 7 get devices 8 get events 9 send command Please Select:4 4 None

Press Enter to continue... 0 exit 1 log in 2 register 3 check log in 4 generate toke 5 activate token 6 get tokes 7 get devices 8 get events 9 send command Please Select:5 5 Press Enter to continue...

0 exit 1 log in 2 register 3 check log in 4 generate toke 5 activate token 6 get tokes 7 get devices 8 get events 9 send command Please Select: `

2022-09-21 08:35:01,164 - INFO - test_tahoma.py - === starting test run === 2022-09-21 08:35:38,937 - DEBUG - connectionpool.py - Starting new HTTPS connection (1): ha101-1.overkiz.com:443 2022-09-21 10:32:20,072 - INFO - test_tahoma.py - === starting test run === 2022-09-21 10:32:23,422 - DEBUG - connectionpool.py - Starting new HTTPS connection (1): ha101-1.overkiz.com:443 2022-09-21 10:32:24,056 - DEBUG - connectionpool.py - https://ha101-1.overkiz.com:443 "POST /enduser-mobile-web/enduserAPI/login HTTP/1.1" 200 None 2022-09-21 10:32:24,059 - DEBUG - tahoma_local.py - Login respone: status_code: '200' reponse body: '{'success': True, 'roles': [{'name': 'ENDUSER'}]}' 2022-09-21 10:32:24,059 - INFO - tahoma_local.py - Tahoma authentication succeeded, login valid until 2022-09-27 10:32:24 2022-09-21 10:32:24,060 - DEBUG - tahoma_local.py - login: cookies: '<RequestsCookieJar[<Cookie JSESSIONID=XXXXXXXXXXXXXXXXXXXX for ha101-1.overkiz.com/enduser-mobile-web>]>', headers: '{'Date': 'Wed, 21 Sep 2022 08:32:21 GMT', 'Server': 'overkiz', 'Strict-Transport-Security': 'max-age=31536000; includeSubDomains, max-age=31536000 ; includeSubDomains', 'Cache-Control': 'no-cache, no-store, max-age=0, must-revalidate', 'Pragma': 'no-cache', 'Expires': '0', 'X-XSS-Protection': '1; mode=block', 'X-Frame-Options': 'DENY', 'X-Content-Type-Options': 'nosniff', 'Content-Type': 'application/json;charset=UTF-8', 'Set-Cookie': 'JSESSIONID=XXXXXXXXXXXXXXXXXXXXXXXXXXX; Path=/enduser-mobile-web; Secure; HttpOnly; SameSite=None', 'Keep-Alive': 'timeout=5, max=50', 'Connection': 'Keep-Alive', 'Transfer-Encoding': 'chunked'}' 2022-09-21 10:32:37,175 - DEBUG - tahoma_local.py - checking logged in status: self.__logged_in = True and self.__expiry_date >= datetime.datetime.now() = True 2022-09-21 10:32:42,617 - DEBUG - tahoma_local.py - generate token: url_gen = '/enduser-mobile-web/enduserAPI/config/1237-xxxx-xxxx/local/tokens/generate' 2022-09-21 10:32:42,618 - DEBUG - tahoma_local.py - generate token: headers_gen = '{'Content-Type': 'application/json'}' 2022-09-21 10:32:42,618 - DEBUG - tahoma_local.py - generate token: cookie = '<RequestsCookieJar[<Cookie JSESSIONID=XXXXXXXXXXXXXXXXXXXXX for ha101-1.overkiz.com/enduser-mobile-web>]>' 2022-09-21 10:32:42,622 - DEBUG - connectionpool.py - Starting new HTTPS connection (1): ha101-1.overkiz.com:443 2022-09-21 10:32:42,731 - DEBUG - connectionpool.py - https://ha101-1.overkiz.com:443 "GET /enduser-mobile-web/enduserAPI/config/1237-xxxx-xxxx/local/tokens/generate HTTP/1.1" 200 None 2022-09-21 10:32:42,733 - DEBUG - tahoma_local.py - succeeded to activate token: None

ab10002 commented 1 year ago

A bit furter; Installing collected packages: textwrap3, ansiwrap, console-menu Successfully installed ansiwrap-0.8.4 console-menu-0.7.1 textwrap3-0.9.2 pi@vm-domoticz:~/domoticz/plugins/somfy$ python3 test_tahoma.py 0 exit 1 log in 2 register 3 check log in 4 generate toke 5 activate token 6 get tokes 7 get devices 8 get events 9 send command Please Select:1 1 Press Enter to continue... 0 exit 1 log in 2 register 3 check log in 4 generate toke 5 activate token 6 get tokes 7 get devices 8 get events 9 send command Please Select:2 2 Traceback (most recent call last): File "test_tahoma.py", line 40, in tahoma.register_listener() AttributeError: 'Tahoma' object has no attribute 'register_listener'

2022-09-21 10:29:51,785 - INFO     - test_tahoma.py     - === starting test run ===
2022-09-21 10:39:28,845 - INFO     - test_tahoma.py     - === starting test run ===
2022-09-21 10:41:43,816 - INFO     - test_tahoma.py     - === starting test run ===
2022-09-21 10:41:53,381 - DEBUG    - connectionpool.py  - Starting new HTTPS connection (1): ha101-1.overkiz.com:443
2022-09-21 10:41:53,904 - DEBUG    - connectionpool.py  - https://ha101-1.overkiz.com:443 "POST /enduser-mobile-web/enduserAPI/login HTTP/1.1" 200 None
2022-09-21 10:41:53,905 - DEBUG    - tahoma_local.py    - Login respone: status_code: '200' reponse body: '{'success': True, 'roles': [{'name': 'ENDUSER'}]}'
2022-09-21 10:41:53,905 - INFO     - tahoma_local.py    - Tahoma authentication succeeded, login valid until 2022-09-27 10:41:53
2022-09-21 10:41:53,905 - DEBUG    - tahoma_local.py    - login: cookies: '<RequestsCookieJar[<Cookie JSESSIONID=XXXXXXXXXXXXXXXXXX for ha101-1.overkiz.com/enduser-mobile-web>]>', headers: '{'Date': 'Wed, 21 Sep 2022 08:41:53 GMT', 'Server': 'overkiz', 'Strict-Transport-Security': 'max-age=31536000; includeSubDomains, max-age=31536000 ; includeSubDomains', 'Cache-Control': 'no-cache, no-store, max-age=0, must-revalidate', 'Pragma': 'no-cache', 'Expires': '0', 'X-XSS-Protection': '1; mode=block', 'X-Frame-Options': 'DENY', 'X-Content-Type-Options': 'nosniff', 'Content-Type': 'application/json;charset=UTF-8', 'Set-Cookie': 'JSESSIONID=XXXXXXXXXXXXXXXXXXXXX; Path=/enduser-mobile-web; Secure; HttpOnly; SameSite=None', 'Keep-Alive': 'timeout=5, max=50', 'Connection': 'Keep-Alive', 'Transfer-Encoding': 'chunked'}'
ab10002 commented 1 year ago

1; 1 3; true 4; nothing 5; nothing 6; nothing

JanJaapKo commented 1 year ago

Ok, so options 5 and 6 were not implemented yet (they are now)....... 2 doesn't work here so can be skipped. I modified the script so it will spit out more data. Can you have another go?

MadPatrick commented 1 year ago

python3 test_tahoma.py

1 Press Enter to continue...

3 True Press Enter to continue...

4 { "token": "xxxxxxxxxxxxxxxx" } Press Enter to continue...

5 Traceback (most recent call last): File "test_tahoma.py", line 48, in repsonse = tahoma.activate_token(p_pin) File "/var/domoticz/plugins/somfy/tahoma_local.py", line 105, in activate_token raise exceptions.LoginFailure("failed to generate token") exceptions.LoginFailure: failed to generate token

JanJaapKo commented 1 year ago

would need to see the logfile......

MadPatrick commented 1 year ago

2022-09-21 19:24:59,018 - INFO - test_tahoma.py - === starting test run === 2022-09-21 19:25:03,715 - DEBUG - connectionpool.py - Starting new HTTPS connection (1): ha101-1.overkiz.com:443 2022-09-21 19:25:04,335 - DEBUG - connectionpool.py - https://ha101-1.overkiz.com:443 "POST /enduser-mobile-web/enduserAPI/login HTTP/1.1" 200 None 2022-09-21 19:25:04,340 - DEBUG - tahoma_local.py - Login respone: status_code: '200' reponse body: '{'success': True, 'roles': [{'name': 'ENDUSER'}]}' 2022-09-21 19:25:04,340 - INFO - tahoma_local.py - Tahoma authentication succeeded, login valid until 2022-09-27 19:25:04 2022-09-21 19:25:04,340 - DEBUG - tahoma_local.py - login: cookies: '<RequestsCookieJar[<Cookie JSESSIONID=xxxxxxxxxxxxxxfor ha101-1.overkiz.com/enduser-mobile-web>]>', headers: '{'Date': 'Wed, 21 Sep 2022 17:25:00 GMT', 'Server': 'overkiz', 'Strict-Transport-Security': 'max-age=31536000; includeSubDomains, max-age=31536000 ; includeSubDomains', 'Cache-Control': 'no-cache, no-store, max-age=0, must-revalidate', 'Pragma': 'no-cache', 'Expires': '0', 'X-XSS-Protection': '1; mode=block', 'X-Frame-Options': 'DENY', 'X-Content-Type-Options': 'nosniff', 'Content-Type': 'application/json;charset=UTF-8', 'Set-Cookie': 'JSESSIONID=xxxxxxxxxxxxxxxxxxx; Path=/enduser-mobile-web; Secure; HttpOnly; SameSite=None', 'Keep-Alive': 'timeout=5, max=50', 'Connection': 'Keep-Alive', 'Transfer-Encoding': 'chunked'}' 2022-09-21 19:25:14,678 - DEBUG - tahoma_local.py - checking logged in status: self.__logged_in = True and self.__expiry_date >= datetime.datetime.now() = True 2022-09-21 19:25:18,296 - DEBUG - tahoma_local.py - generate token: url_gen = '/enduser-mobile-web/enduserAPI/config/1237-xxxxx-xxxx/local/tokens/generate' 2022-09-21 19:25:18,296 - DEBUG - tahoma_local.py - generate token: headers_gen = '{'Content-Type': 'application/json'}' 2022-09-21 19:25:18,297 - DEBUG - tahoma_local.py - generate token: cookie = '<RequestsCookieJar[<Cookie JSESSIONID=xxxxxxxxxxxxx for ha101-1.overkiz.com/enduser-mobile-web>]>' 2022-09-21 19:25:18,298 - DEBUG - connectionpool.py - Starting new HTTPS connection (1): ha101-1.overkiz.com:443 2022-09-21 19:25:18,384 - DEBUG - connectionpool.py - https://ha101-1.overkiz.com:443 "GET /enduser-mobile-web/enduserAPI/config/1237-xxxx-xxxx/local/tokens/generate HTTP/1.1" 200 None 2022-09-21 19:25:18,386 - DEBUG - tahoma_local.py - succeeded to activate token: None 2022-09-21 19:25:22,073 - DEBUG - connectionpool.py - Starting new HTTPS connection (1): ha101-1.overkiz.com:443 2022-09-21 19:25:22,169 - DEBUG - connectionpool.py - https://ha101-1.overkiz.com:443 "POST /enduser-mobile-web/enduserAPI/config/1237-xxxx-xxxx/local/tokens HTTP/1.1" 400 None 2022-09-21 19:25:22,173 - ERROR - tahoma_local.py - failed to generate token

JanJaapKo commented 1 year ago

the above contains your pin + session id, propose you remove that....... I'll have a look later this evening, first cycling.....

ab10002 commented 1 year ago

1 login status: True 3 False 4 { "token": "XXXXXXXXXXXXXX" } 5 Traceback (most recent call last): File "test_tahoma.py", line 50, in repsonse = tahoma.activate_token(p_pin) File "/home/pi/domoticz/plugins/somfy/tahoma_local.py", line 105, in activate_token raise exceptions.LoginFailure("failed to generate token") exceptions.LoginFailure: failed to generate token


2022-09-21 20:21:46,284 - INFO     - test_tahoma.py     - === starting test run ===
2022-09-21 20:21:52,440 - DEBUG    - connectionpool.py  - Starting new HTTPS connection (1): ha101-1.overkiz.com:443
2022-09-21 20:21:52,972 - DEBUG    - connectionpool.py  - https://ha101-1.overkiz.com:443 "POST /enduser-mobile-web/enduserAPI/login HTTP/1.1" 200 None
2022-09-21 20:21:52,974 - DEBUG    - tahoma_local.py    - Login respone: status_code: '200' reponse body: '{'success': True, 'roles': [{'name': 'ENDUSER'}]}'
2022-09-21 20:21:52,974 - INFO     - tahoma_local.py    - Tahoma authentication succeeded, login valid until 2022-09-27 20:21:52
2022-09-21 20:21:52,974 - DEBUG    - tahoma_local.py    - login: cookies: '<RequestsCookieJar[<Cookie JSESSIONID=XXXXXXXXXXXXXXXXXX for ha101-1.overkiz.com/enduser-mobile-web>]>', headers: '{'Date': 'Wed, 21 Sep 2022 18:21:52 GMT', 'Server': 'overkiz', 'Strict-Transport-Security': 'max-age=31536000; includeSubDomains, max-age=31536000 ; includeSubDomains', 'Cache-Control': 'no-cache, no-store, max-age=0, must-revalidate', 'Pragma': 'no-cache', 'Expires': '0', 'X-XSS-Protection': '1; mode=block', 'X-Frame-Options': 'DENY', 'X-Content-Type-Options': 'nosniff', 'Content-Type': 'application/json;charset=UTF-8', 'Set-Cookie': 'JSESSIONID=XXXXXXXXXXXXX; Path=/enduser-mobile-web; Secure; HttpOnly; SameSite=None', 'Keep-Alive': 'timeout=5, max=50', 'Connection': 'Keep-Alive', 'Transfer-Encoding': 'chunked'}'
2022-09-21 20:22:12,158 - DEBUG    - tahoma_local.py    - generate token: url_gen = '/enduser-mobile-web/enduserAPI/config/XXXX-XXXX-XXXX/local/tokens/generate'
2022-09-21 20:22:12,158 - DEBUG    - tahoma_local.py    - generate token: headers_gen = '{'Content-Type': 'application/json'}'
2022-09-21 20:22:12,158 - DEBUG    - tahoma_local.py    - generate token: cookie = '<RequestsCookieJar[<Cookie JSESSIONID=XXXXXXXXXXXXXXXXXXXXX for ha101-1.overkiz.com/enduser-mobile-web>]>'
2022-09-21 20:22:12,159 - DEBUG    - connectionpool.py  - Starting new HTTPS connection (1): ha101-1.overkiz.com:443
2022-09-21 20:22:12,196 - DEBUG    - connectionpool.py  - https://ha101-1.overkiz.com:443 "GET /enduser-mobile-web/enduserAPI/config/XXXX-XXXX-XXXX/local/tokens/generate HTTP/1.1" 200 None
2022-09-21 20:22:12,197 - DEBUG    - tahoma_local.py    - succeeded to activate token: None
2022-09-21 20:22:19,214 - DEBUG    - connectionpool.py  - Starting new HTTPS connection (1): ha101-1.overkiz.com:443
2022-09-21 20:22:19,254 - DEBUG    - connectionpool.py  - https://ha101-1.overkiz.com:443 "POST /enduser-mobile-web/enduserAPI/config/XXXX-XXXX-XXXX/local/tokens HTTP/1.1" 400 None
2022-09-21 20:22:19,255 - ERROR    - tahoma_local.py    - failed to generate token
JanJaapKo commented 1 year ago

ok my bad, forgot store the token...... Retry?

ab10002 commented 1 year ago

It's stuck on #5: 5 Traceback (most recent call last): File "test_tahoma.py", line 50, in repsonse = tahoma.activate_token(p_pin) File "/home/pi/domoticz/plugins/somfy/tahoma_local.py", line 100, in activate_token self.token = response.json()['token'] KeyError: 'token'

MadPatrick commented 1 year ago

Traceback (most recent call last): File "test_tahoma.py", line 50, in <module> repsonse = tahoma.activate_token(p_pin) File "/var/domoticz/plugins/somfy/tahoma_local.py", line 100, in activate_token self.token = response.json()['token'] KeyError: 'token'

2022-09-21 21:26:26,760 - INFO - test_tahoma.py - === starting test run === 2022-09-21 21:26:30,477 - DEBUG - connectionpool.py - Starting new HTTPS connection (1): ha101-1.overkiz.com:443 2022-09-21 21:26:31,101 - DEBUG - connectionpool.py - https://ha101-1.overkiz.com:443 "POST /enduser-mobile-web/enduserAPI/login HTTP/1.1" 200 None 2022-09-21 21:26:31,104 - DEBUG - tahoma_local.py - Login respone: status_code: '200' reponse body: '{'success': True, 'roles': [{'name': 'ENDUSER'}]}' 2022-09-21 21:26:31,104 - INFO - tahoma_local.py - Tahoma authentication succeeded, login valid until 2022-09-27 21:26:31 2022-09-21 21:26:31,104 - DEBUG - tahoma_local.py - login: cookies: '<RequestsCookieJar[<Cookie JSESSIONID=xxxxxxxxxxxxxx for ha101-1.overkiz.com/enduser-mobile-web>]>', headers: '{'Date': 'Wed, 21 Sep 2022 19:26:29 GMT', 'Server': 'overkiz', 'Strict-Transport-Security': 'max-age=31536000; includeSubDomains, max-age=31536000 ; includeSubDomains', 'Cache-Control': 'no-cache, no-store, max-age=0, must-revalidate', 'Pragma': 'no-cache', 'Expires': '0', 'X-XSS-Protection': '1; mode=block', 'X-Frame-Options': 'DENY', 'X-Content-Type-Options': 'nosniff', 'Content-Type': 'application/json;charset=UTF-8', 'Set-Cookie': 'JSESSIONID=xxxxxxxxxxx ; Path=/enduser-mobile-web; Secure; HttpOnly; SameSite=None', 'Keep-Alive': 'timeout=5, max=50', 'Connection': 'Keep-Alive', 'Transfer-Encoding': 'chunked'}' 2022-09-21 21:26:42,452 - DEBUG - tahoma_local.py - checking logged in status: self.__logged_in = True and self.__expiry_date >= datetime.datetime.now() = True 2022-09-21 21:26:45,674 - DEBUG - tahoma_local.py - generate token: url_gen = '/enduser-mobile-web/enduserAPI/config/xxxx-xxxx-xxxx/local/tokens/generate' 2022-09-21 21:26:45,674 - DEBUG - tahoma_local.py - generate token: headers_gen = '{'Content-Type': 'application/json'}' 2022-09-21 21:26:45,674 - DEBUG - tahoma_local.py - generate token: cookie = '<RequestsCookieJar[<Cookie JSESSIONID=xxxxxxxxxx for ha101-1.overkiz.com/enduser-mobile-web>]>' 2022-09-21 21:26:45,676 - DEBUG - connectionpool.py - Starting new HTTPS connection (1): ha101-1.overkiz.com:443 2022-09-21 21:26:45,760 - DEBUG - connectionpool.py - https://ha101-1.overkiz.com:443 "GET /enduser-mobile-web/enduserAPI/config/xxxx-xxxx-xxxx/local/tokens/generate HTTP/1.1" 200 None 2022-09-21 21:26:45,762 - DEBUG - tahoma_local.py - succeeded to activate token: xxxxxxxxxxxxxx 2022-09-21 21:26:47,862 - DEBUG - connectionpool.py - Starting new HTTPS connection (1): ha101-1.overkiz.com:443 2022-09-21 21:26:47,947 - DEBUG - connectionpool.py - https://ha101-1.overkiz.com:443 "POST /enduser-mobile-web/enduserAPI/config/xxxx-xxxx-xxxx/local/tokens HTTP/1.1" 200 None

JanJaapKo commented 1 year ago

pff now stored it too often.....

MadPatrick commented 1 year ago

option 5 works now 5 { "token": "xxxxxxxxxx" } Press Enter to continue...

MadPatrick commented 1 year ago

option 6:

{ "token": "xxxxxxxxxx" }

option 7:

Traceback (most recent call last): File "test_tahoma.py", line 55, in if x == 7: print(tahoma.get_devices(device_list)) AttributeError: 'Tahoma' object has no attribute 'get_devices'

ab10002 commented 1 year ago

Yes here too, till #6

ab10002 commented 1 year ago

Maybe it's time for a delete tokens option... think i'v a lot..

FAIK, only the token is needed for local connection (cloud jsonid) And i had one line in my host file; ipaddress hostname(pin.local) With gateway into, there a error in the certification For getting version #, no token is needed

JanJaapKo commented 1 year ago

Right there was still a mistake in 'get tokens' as it returns only 1. Can you give it another try?

ab10002 commented 1 year ago

Till #7 is working and can see the token

JanJaapKo commented 1 year ago

to make the delete work, I need the output of option 6. To be able to build the delete command....

ab10002 commented 1 year ago

Please Select:6 6 { "token": "XXXXXXXXXXX" } Press Enter to continue...

XXXX = my token..

MadPatrick commented 1 year ago

6 is working

7

Traceback (most recent call last): File "test_tahoma.py", line 55, in if x == 7: print(tahoma.get_devices(device_list)) AttributeError: 'Tahoma' object has no attribute 'get_devices'

2022-09-21 22:04:33,087 - INFO - test_tahoma.py - === starting test run === 2022-09-21 22:04:35,119 - DEBUG - connectionpool.py - Starting new HTTPS connection (1): ha101-1.overkiz.com:443 2022-09-21 22:04:35,714 - DEBUG - connectionpool.py - https://ha101-1.overkiz.com:443 "POST /enduser-mobile-web/enduserAPI/login HTTP/1.1" 200 None 2022-09-21 22:04:35,718 - DEBUG - tahoma_local.py - Login respone: status_code: '200' reponse body: '{'success': True, 'roles': [{'name': 'ENDUSER'}]}' 2022-09-21 22:04:35,718 - INFO - tahoma_local.py - Tahoma authentication succeeded, login valid until 2022-09-27 22:04:35 2022-09-21 22:04:35,718 - DEBUG - tahoma_local.py - login: cookies: '<RequestsCookieJar[<Cookie JSESSIONID=13AF2F87605B0C7355987D2E608B5A38 for ha101-1.overkiz.com/enduser-mobile-web>]>', headers: '{'Date': 'Wed, 21 Sep 2022 20:04:35 GMT', 'Server': 'overkiz', 'Strict-Transport-Security': 'max-age=31536000; includeSubDomains, max-age=31536000 ; includeSubDomains', 'Cache-Control': 'no-cache, no-store, max-age=0, must-revalidate', 'Pragma': 'no-cache', 'Expires': '0', 'X-XSS-Protection': '1; mode=block', 'X-Frame-Options': 'DENY', 'X-Content-Type-Options': 'nosniff', 'Content-Type': 'application/json;charset=UTF-8', 'Set-Cookie': 'JSESSIONID=13AF2F87605B0C7355987D2E608B5A38; Path=/enduser-mobile-web; Secure; HttpOnly; SameSite=None', 'Keep-Alive': 'timeout=5, max=50', 'Connection': 'Keep-Alive', 'Transfer-Encoding': 'chunked'}' 2022-09-21 22:04:39,393 - DEBUG - tahoma_local.py - checking logged in status: self.__logged_in = True and self.__expiry_date >= datetime.datetime.now() = True 2022-09-21 22:04:41,723 - DEBUG - tahoma_local.py - generate token: url_gen = '/enduser-mobile-web/enduserAPI/config/xxxx-xxxx-xxxx/local/tokens/generate' 2022-09-21 22:04:41,723 - DEBUG - tahoma_local.py - generate token: cookie = '<RequestsCookieJar[<Cookie JSESSIONID=13AF2F87605B0C7355987D2E608B5A38 for ha101-1.overkiz.com/enduser-mobile-web>]>' 2022-09-21 22:04:41,725 - DEBUG - connectionpool.py - Starting new HTTPS connection (1): ha101-1.overkiz.com:443 2022-09-21 22:04:41,815 - DEBUG - connectionpool.py - https://ha101-1.overkiz.com:443 "GET /enduser-mobile-web/enduserAPI/config/xxxx-xxxx-xxxx/local/tokens/generate HTTP/1.1" 200 None 2022-09-21 22:04:41,818 - DEBUG - tahoma_local.py - succeeded to activate token: xxxxxxxxxxxxxxxx 2022-09-21 22:04:46,790 - DEBUG - connectionpool.py - Starting new HTTPS connection (1): ha101-1.overkiz.com:443 2022-09-21 22:04:46,887 - DEBUG - connectionpool.py - https://ha101-1.overkiz.com:443 "POST /enduser-mobile-web/enduserAPI/config/xxxx-xxxx-xxxx/local/tokens HTTP/1.1" 200 None 2022-09-21 22:04:46,888 - DEBUG - tahoma_local.py - succeeded to activate token: xxxxxxxxxxxxxxx 2022-09-21 22:04:50,163 - DEBUG - connectionpool.py - Starting new HTTPS connection (1): ha101-1.overkiz.com:443 2022-09-21 22:04:50,250 - DEBUG - connectionpool.py - https://ha101-1.overkiz.com:443 "GET /enduser-mobile-web/enduserAPI/config/xxxx-xxxx-xxxx/local/tokens/devmode HTTP/1.1" 200 None 2022-09-21 22:04:50,253 - DEBUG - tahoma_local.py - succeeded to get tokens: [{'label': 'Toto token', 'gatewayId': 'xxxx-xxxx-xxxx', 'expirationTime': 1679558686000, 'gatewayCreationTime': 1663790686000, 'uuid': '2f8abea8-d228-4ad8-b57a-4cf7e9647ed3', 'scope': 'devmode'}, {'label': 'Toto token', 'gatewayId': 'xxxx-xxxx-xxxx', 'expirationTime': 1679556407000, 'gatewayCreationTime': 1663788407000, 'uuid': '8233505d-45fd-4d0a-bf95-fb63e8e5f889', 'scope': 'devmode'}, {'label': 'HomebridgeTahoma', 'gatewayId': 'xxxx-xxxx-xxxx', 'expirationTime': 1679250292000, 'gatewayCreationTime': 1663482292000, 'uuid': '8ff7d9a0-8190-40bf-b407-f2f51b82a505', 'scope': 'devmode'}, {'label': 'Toto token', 'gatewayId': 'xxxx-xxxx-xxxx', 'expirationTime': 1679556625000, 'gatewayCreationTime': 1663788625000, 'uuid': 'f52c1d61-6677-4bbf-9dbb-7e37af39960e', 'scope': 'devmode'}]

JanJaapKo commented 1 year ago

Aha ok, so there is only 1 token then. Because the delete command requires an uuid for the token you want to delete. But if you cannot find the uuid, that is going to be a bit difficult.... Anyhow, I'll continue with setting up the connection to the box

ab10002 commented 1 year ago

Last line log, with 3 tokens?:

succeeded to get tokens: [{'label': 'HomebridgeTahoma', 'gatewayId': '0000-0000-0000', 'expirationTime': 1679176134000, 'gatewayCreationTime': 1663408134000, 'uuid': '032feacc-a157-4ac7-a150-47729fb66324', 'scope': 'devmode'}, {'label': 'Toto token', 'gatewayId': '0000-0000-0000', 'expirationTime': 1679558395000, 'gatewayCreationTime': 1663790395000, 'uuid': '52a6ee1a-24aa-42c3-9bd6-05ee99a3563d', 'scope': 'devmode'}, {'label': 'Toto token', 'gatewayId': '0000-0000-0000', 'expirationTime': 1679556373000, 'gatewayCreationTime': 1663788373000, 'uuid': 'a491995d-790e-4f43-affd-283cf29070da', 'scope': 'devmode'}, {'label': 'Toto token', 'gatewayId': '0000-0000-0000', 'expirationTime': 1679556770000, 'gatewayCreationTime': 1663788770000, 'uuid': 'b9b73e99-aab6-431e-85ea-0639843733a1', 'scope': 'devmode'}]
JanJaapKo commented 1 year ago

ýes got it. Should be ok now. At option 6 at command line it should print the list of tokens nicely formatted. And then you should be able to delete it.

ab10002 commented 1 year ago

6 i see only 1 token.

Restart the script and login and then #6 6 Traceback (most recent call last): File "test_tahoma.py", line 54, in print(json.dumps(response, sort_keys = True, indent=4)) NameError: name 'response' is not defined

JanJaapKo commented 1 year ago

oh, typos...... Can you retry?

ab10002 commented 1 year ago

Nice, it's working!

JanJaapKo commented 1 year ago

OK, so I created the first attempt to connect to the box locally...... I'm relly curious if this works. It tries to connect to

https://gateway-<pin>.local:<port>/enduser-mobile-web/1/enduserAPI

Do you guys recognize this device on your local network? If not, I'll see if it also works by just entering IP adress

For the test to work, go over menu options: 1, 4, 5, 20

ab10002 commented 1 year ago

Error:

20
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/urllib3/connection.py", line 159, in _new_conn
    (self._dns_host, self.port), self.timeout, **extra_kw)
  File "/usr/lib/python3/dist-packages/urllib3/util/connection.py", line 57, in create_connection
    for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
  File "/usr/lib/python3.7/socket.py", line 748, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -2] Name or service not known

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 600, in urlopen
    chunked=chunked)
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 343, in _make_request
    self._validate_conn(conn)
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 841, in _validate_conn
    conn.connect()
  File "/usr/lib/python3/dist-packages/urllib3/connection.py", line 301, in connect
    conn = self._new_conn()
  File "/usr/lib/python3/dist-packages/urllib3/connection.py", line 168, in _new_conn
    self, "Failed to establish a new connection: %s" % e)
urllib3.exceptions.NewConnectionError: <urllib3.connection.VerifiedHTTPSConnection object at 0x7f8fdcf9cb70>: Failed to establish a new connection: [Errno -2] Name or service not known

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/requests/adapters.py", line 449, in send
    timeout=timeout
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 638, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "/usr/lib/python3/dist-packages/urllib3/util/retry.py", line 398, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='gateway-0000-0000-0000.local', port=8443): Max retries exceeded with url: /enduser-mobile-web/1/enduserAPI/apiVersion (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f8fdcf9cb70>: Failed to establish a new connection: [Errno -2] Name or service not known'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "test_tahoma.py", line 70, in <module>
    response = theBox.get_version()
  File "/home/pi/domoticz/plugins/somfy/tahoma_local.py", line 141, in get_version
    response = requests.get(self.base_url + "/apiVersion", headers=self.headers_json)
  File "/usr/lib/python3/dist-packages/requests/api.py", line 75, in get
    return request('get', url, params=params, **kwargs)
  File "/usr/lib/python3/dist-packages/requests/api.py", line 60, in request
    return session.request(method=method, url=url, **kwargs)
  File "/usr/lib/python3/dist-packages/requests/sessions.py", line 533, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/lib/python3/dist-packages/requests/sessions.py", line 646, in send
    r = adapter.send(request, **kwargs)
  File "/usr/lib/python3/dist-packages/requests/adapters.py", line 516, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='gateway-0000-0000-0000.local', port=8443): Max retries exceeded with url: /enduser-mobile-web/1/enduserAPI/apiVersion (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f8fdcf9cb70>: Failed to establish a new connection: [Errno -2] Name or service not known'))
ab10002 commented 1 year ago

Try without GATEWAY- ??

ab10002 commented 1 year ago

I removed GATEWAY-..i'v got this: /usr/lib/python3/dist-packages/urllib3/connection.py:362: SubjectAltNameWarning: Certificate for 000-0000-0000.local has no subjectAltName, falling back to check for a commonName for now. This feature is being removed by major browsers and deprecated by RFC 2818. (See https://github.com/shazow/urllib3/issues/497 for details.) SubjectAltNameWarning { "protocolVersion": "2022.4.4-10" } Press Enter to continue...

What i'v mentiod before; there are issue with https://ca.overkiz.com/overkiz-root-ca-2048.crt

ab10002 commented 1 year ago

I'v got these in my network:

ab10002 commented 1 year ago

With ipaddress don''t work

MadPatrick commented 1 year ago

I've tried 1, 4, 5, 20

At #20

Traceback (most recent call last): File "/usr/lib/python3.6/site-packages/requests/packages/urllib3/connectionpool.py", line 672, in urlopen chunked=chunked, File "/usr/lib/python3.6/site-packages/requests/packages/urllib3/connectionpool.py", line 376, in _make_request self._validate_conn(conn) File "/usr/lib/python3.6/site-packages/requests/packages/urllib3/connectionpool.py", line 994, in _validate_conn conn.connect() File "/usr/lib/python3.6/site-packages/requests/packages/urllib3/connection.py", line 408, in connect sslcontext=context, File "/usr/lib/python3.6/site-packages/requests/packages/urllib3/util/ssl.py", line 370, in ssl_wrap_socket return context.wrap_socket(sock, server_hostname=server_hostname) File "/usr/lib64/python3.6/ssl.py", line 365, in wrap_socket _context=self, _session=session) File "/usr/lib64/python3.6/ssl.py", line 776, in init self.do_handshake() File "/usr/lib64/python3.6/ssl.py", line 1036, in do_handshake self._sslobj.do_handshake() File "/usr/lib64/python3.6/ssl.py", line 648, in do_handshake self._sslobj.do_handshake() ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:877)

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/usr/lib/python3.6/site-packages/requests/adapters.py", line 438, in send timeout=timeout File "/usr/lib/python3.6/site-packages/requests/packages/urllib3/connectionpool.py", line 720, in urlopen method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2] File "/usr/lib/python3.6/site-packages/requests/packages/urllib3/util/retry.py", line 436, in increment raise MaxRetryError(_pool, url, error or ResponseError(cause)) requests.packages.urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='gateway-xxxx-xxxx-xxxx.local', port=8443): Max retries exceeded with url: /enduser-mobile-web/1/enduserAPI/apiVersion (Caused by SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:877)'),))

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "test_tahoma.py", line 70, in response = theBox.get_version() File "/var/domoticz/plugins/somfy/tahoma_local.py", line 141, in get_version response = requests.get(self.base_url + "/apiVersion", headers=self.headers_json) File "/usr/lib/python3.6/site-packages/requests/api.py", line 72, in get return request('get', url, params=params, kwargs) File "/usr/lib/python3.6/site-packages/requests/api.py", line 58, in request return session.request(method=method, url=url, kwargs) File "/usr/lib/python3.6/site-packages/requests/sessions.py", line 530, in request resp = self.send(prep, send_kwargs) File "/usr/lib/python3.6/site-packages/requests/sessions.py", line 651, in send r = adapter.send(request, kwargs) File "/usr/lib/python3.6/site-packages/requests/adapters.py", line 502, in send raise ConnectionError(e, request=request) requests.exceptions.ConnectionError: HTTPSConnectionPool(host='gateway-xxxx-xxxx-xxxx.local', port=8443): Max retries exceeded with url: /enduser-mobile-web/1/enduserAPI/apiVersion (Caused by SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:877)'),))

My DHCP server identifies the box as : gateway-xxxx-xxxxx-xxxx

MadPatrick commented 1 year ago

Have you seen this website ?

https://somfy-developer.github.io/Somfy-TaHoma-Developer-Mode/#/

and the integration in Homeassistance

https://github.com/home-assistant/core/pull/71644/files

Maybe it helps