Skip to content

Commit 28456b7

Browse files
committed
Add initial version
0 parents  commit 28456b7

9 files changed

Lines changed: 306 additions & 0 deletions

File tree

.gitignore

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
pip-wheel-metadata/
24+
share/python-wheels/
25+
*.egg-info/
26+
.installed.cfg
27+
*.egg
28+
MANIFEST
29+
30+
# PyInstaller
31+
# Usually these files are written by a python script from a template
32+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
33+
*.manifest
34+
*.spec
35+
36+
# Installer logs
37+
pip-log.txt
38+
pip-delete-this-directory.txt
39+
40+
# Unit test / coverage reports
41+
htmlcov/
42+
.tox/
43+
.nox/
44+
.coverage
45+
.coverage.*
46+
.cache
47+
nosetests.xml
48+
coverage.xml
49+
*.cover
50+
*.py,cover
51+
.hypothesis/
52+
.pytest_cache/
53+
54+
# Translations
55+
*.mo
56+
*.pot
57+
58+
# Django stuff:
59+
*.log
60+
local_settings.py
61+
db.sqlite3
62+
db.sqlite3-journal
63+
64+
# Flask stuff:
65+
instance/
66+
.webassets-cache
67+
68+
# Scrapy stuff:
69+
.scrapy
70+
71+
# Sphinx documentation
72+
docs/_build/
73+
74+
# PyBuilder
75+
target/
76+
77+
# Jupyter Notebook
78+
.ipynb_checkpoints
79+
80+
# IPython
81+
profile_default/
82+
ipython_config.py
83+
84+
# pyenv
85+
.python-version
86+
87+
# pipenv
88+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
89+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
90+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
91+
# install all needed dependencies.
92+
#Pipfile.lock
93+
94+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
95+
__pypackages__/
96+
97+
# Celery stuff
98+
celerybeat-schedule
99+
celerybeat.pid
100+
101+
# SageMath parsed files
102+
*.sage.py
103+
104+
# Environments
105+
.env
106+
.venv
107+
env/
108+
venv/
109+
ENV/
110+
env.bak/
111+
venv.bak/
112+
113+
# Spyder project settings
114+
.spyderproject
115+
.spyproject
116+
117+
# Rope project settings
118+
.ropeproject
119+
120+
# mkdocs documentation
121+
/site
122+
123+
# mypy
124+
.mypy_cache/
125+
.dmypy.json
126+
dmypy.json
127+
128+
# Pyre type checker
129+
.pyre/

.vscode/settings.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"python.pythonPath": "/Users/mick/Projects/personal-projects/python-tahoma-api/.venv/bin/python3",
3+
"files.associations": {
4+
"*.yaml": "home-assistant"
5+
}
6+
}

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2020 Mick Vleeshouwer
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# python-tahoma-api

setup.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from setuptools import setup, find_packages
2+
3+
with open("README.md", "r") as fh:
4+
long_description = fh.read()
5+
6+
setup(
7+
name="tahoma_api",
8+
version="0.1.0",
9+
author="Mick Vleeshouwer",
10+
author_email="mick@imick.nl",
11+
description="Python wrapper to interact with SagemCom F@st routers via internal API's.",
12+
long_description=long_description,
13+
long_description_content_type="text/markdown",
14+
url="https://github.com/iMicknl/python-tahoma-api",
15+
classifiers=(
16+
'Development Status :: 3 - Alpha',
17+
"Programming Language :: Python :: 3",
18+
"License :: OSI Approved :: MIT License",
19+
"Operating System :: OS Independent",
20+
),
21+
packages=find_packages(),
22+
install_requires=['aiohttp==3.6.1'],
23+
)

tahoma_api/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from .client import *
2+
from .exceptions import *
3+
4+
__version__ = '0.1.0'

tahoma_api/client.py

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
""" Python wrapper for the Tahoma API """
2+
import aiohttp
3+
4+
import asyncio
5+
import logging
6+
import time
7+
import hashlib
8+
import math
9+
import random
10+
import json
11+
12+
from .exceptions import *
13+
14+
API_URL = 'https://tahomalink.com/enduser-mobile-web/enduserAPI/' # /doc for API doc
15+
16+
class TahomaClient(object):
17+
""" Interface class for the Tahoma API """
18+
19+
def __init__(self, username, password):
20+
"""
21+
Constructor
22+
23+
:param username: the username for Tahomalink.com
24+
:param password: the password for Tahomalink.com
25+
"""
26+
27+
self.username = username
28+
self.password = password
29+
30+
self.__roles = []
31+
32+
async def login(self):
33+
34+
payload = {
35+
'userId': self.username,
36+
'userPassword': self.password
37+
}
38+
39+
async with aiohttp.ClientSession() as session:
40+
async with session.post(API_URL + 'login', data=payload) as response:
41+
42+
result = await response.json()
43+
44+
# 401
45+
# {'errorCode': 'AUTHENTICATION_ERROR', 'error': 'Bad credentials'}
46+
47+
# 401
48+
# {'errorCode': 'AUTHENTICATION_ERROR', 'error': 'Too many requests, try again later : login with xxx@xxx.tld'}
49+
# TODO Add retry logic on too many requests + for debug, log requests + timespans
50+
51+
# 200
52+
# {'success': True, 'roles': [{'name': 'ENDUSER'}]}
53+
if (response.status is 200):
54+
if result['success'] == True:
55+
self.__roles = result['roles']
56+
self.__cookies = response.cookies
57+
58+
return True
59+
60+
print(response.status)
61+
print(result)
62+
63+
async def get_devices(self):
64+
65+
cookies = self.__cookies
66+
67+
async with aiohttp.ClientSession() as session:
68+
async with session.get(API_URL + 'setup/devices', cookies=cookies) as response:
69+
70+
print(response.status)
71+
print(response)
72+
73+
result = await response.json()
74+
75+
print(result)
76+
# 401
77+
# {'errorCode': 'AUTHENTICATION_ERROR', 'error': 'Bad credentials'}
78+
79+
# {'success': True, 'roles': [{'name': 'ENDUSER'}]}
80+
if (response.status is 200):
81+
if result["success"] == True:
82+
print(result)
83+
84+
# TODO Save cookies
85+
86+
async def get_states(self):
87+
88+
cookies = self.__cookies
89+
90+
async with aiohttp.ClientSession() as session:
91+
async with session.get(API_URL + 'setup/devices/states', cookies=cookies) as response:
92+
93+
print(response.status)
94+
result = await response.json()
95+
96+
print(result)
97+
98+
99+
100+
101+
102+

tahoma_api/exceptions.py

Whitespace-only changes.

test.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import asyncio
2+
from tahoma_api import TahomaClient
3+
4+
username = ""
5+
password = ""
6+
7+
async def main():
8+
client = TahomaClient(username, password)
9+
10+
try:
11+
login = await client.login()
12+
devices = await client.get_states()
13+
14+
print(devices)
15+
16+
17+
except Exception as exception:
18+
print(exception)
19+
20+
asyncio.run(main())

0 commit comments

Comments
 (0)