├── .github └── workflows │ └── python-publish.yml ├── .gitignore ├── LICENSE ├── README.md ├── Tami4EdgeAPI ├── Tami4EdgeAPI.py ├── __init__.py ├── device.py ├── device_metadata.py ├── drink.py ├── exceptions.py ├── token.py └── water_quality.py └── setup.py /.github/workflows/python-publish.yml: -------------------------------------------------------------------------------- 1 | # This workflow will upload a Python Package using Twine when a release is created 2 | # For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries 3 | 4 | # This workflow uses actions that are not certified by GitHub. 5 | # They are provided by a third-party and are governed by 6 | # separate terms of service, privacy policy, and support 7 | # documentation. 8 | 9 | name: Upload Python Package 10 | 11 | on: 12 | release: 13 | types: [published] 14 | 15 | permissions: 16 | contents: read 17 | 18 | jobs: 19 | deploy: 20 | 21 | runs-on: ubuntu-latest 22 | 23 | steps: 24 | - uses: actions/checkout@v4 25 | - name: Set up Python 3.10 26 | uses: actions/setup-python@v3 27 | with: 28 | python-version: '3.10' 29 | - name: Install dependencies 30 | run: | 31 | python -m pip install --upgrade pip 32 | pip install build 33 | - name: Build package 34 | run: python -m build 35 | - name: Publish package 36 | uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29 37 | with: 38 | user: __token__ 39 | password: ${{ secrets.PYPI_API_TOKEN }} 40 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 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 | share/python-wheels/ 24 | *.egg-info/ 25 | .installed.cfg 26 | *.egg 27 | MANIFEST 28 | 29 | # PyInstaller 30 | # Usually these files are written by a python script from a template 31 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 32 | *.manifest 33 | *.spec 34 | 35 | # Installer logs 36 | pip-log.txt 37 | pip-delete-this-directory.txt 38 | 39 | # Unit test / coverage reports 40 | htmlcov/ 41 | .tox/ 42 | .nox/ 43 | .coverage 44 | .coverage.* 45 | .cache 46 | nosetests.xml 47 | coverage.xml 48 | *.cover 49 | *.py,cover 50 | .hypothesis/ 51 | .pytest_cache/ 52 | cover/ 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 | .pybuilder/ 76 | target/ 77 | 78 | # Jupyter Notebook 79 | .ipynb_checkpoints 80 | 81 | # IPython 82 | profile_default/ 83 | ipython_config.py 84 | 85 | # pyenv 86 | # For a library or package, you might want to ignore these files since the code is 87 | # intended to run in multiple environments; otherwise, check them in: 88 | # .python-version 89 | 90 | # pipenv 91 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 92 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 93 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 94 | # install all needed dependencies. 95 | #Pipfile.lock 96 | 97 | # poetry 98 | # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. 99 | # This is especially recommended for binary packages to ensure reproducibility, and is more 100 | # commonly ignored for libraries. 101 | # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control 102 | #poetry.lock 103 | 104 | # pdm 105 | # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. 106 | #pdm.lock 107 | # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it 108 | # in version control. 109 | # https://pdm.fming.dev/#use-with-ide 110 | .pdm.toml 111 | 112 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm 113 | __pypackages__/ 114 | 115 | # Celery stuff 116 | celerybeat-schedule 117 | celerybeat.pid 118 | 119 | # SageMath parsed files 120 | *.sage.py 121 | 122 | # Environments 123 | .env 124 | .venv 125 | env/ 126 | venv/ 127 | ENV/ 128 | env.bak/ 129 | venv.bak/ 130 | 131 | # Spyder project settings 132 | .spyderproject 133 | .spyproject 134 | 135 | # Rope project settings 136 | .ropeproject 137 | 138 | # mkdocs documentation 139 | /site 140 | 141 | # mypy 142 | .mypy_cache/ 143 | .dmypy.json 144 | dmypy.json 145 | 146 | # Pyre type checker 147 | .pyre/ 148 | 149 | # pytype static type analyzer 150 | .pytype/ 151 | 152 | # Cython debug symbols 153 | cython_debug/ 154 | 155 | .vscode 156 | 157 | # PyCharm 158 | # JetBrains specific template is maintained in a separate JetBrains.gitignore that can 159 | # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore 160 | # and can be added to the global gitignore or merged into this file. For a more nuclear 161 | # option (not recommended) you can uncomment the following to ignore the entire idea folder. 162 | #.idea/ 163 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Guy Shefer 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. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Tami 4 Edge / Edge+ API in Python 2 | ![GitHub release](https://img.shields.io/github/v/release/Guy293/Tami4EdgeAPI) 3 | ![workflow](https://github.com/Guy293/Tami4EdgeAPI/actions/workflows/python-publish.yml/badge.svg) 4 | 5 | ### **Available as a native integration in Home Assistant!** 6 | 7 | [![tami4.png](https://i.postimg.cc/GhywJQDz/tami4.png)](https://postimg.cc/Tpf4TnCW) 8 | 9 | Tami4EdgeAPI can be used to control Strauss'es Tami4 Edge / Edge+ devices. 10 | You can boil the water, prepare drinks, get information about the filter or UV light and other information about the device. 11 | 12 | ## Installing 13 | 14 | ```sh 15 | pip install Tami4EdgeAPI 16 | ``` 17 | 18 | ## Authenticating 19 | 20 | You first need to obtain a ``refresh_token`` by requesting an sms code to the phone you registered to the app with. 21 | ```py 22 | from Tami4EdgeAPI import Tami4EdgeAPI 23 | 24 | # You must add the country code! 25 | phone_number = "+972xxxxxxxxx" 26 | 27 | Tami4EdgeAPI.request_otp(phone_number) 28 | otp_code = input("Enter OTP: ") 29 | refresh_token = Tami4EdgeAPI.submit_otp(phone_number, otp_code) 30 | ``` 31 | Store the ``refresh_token`` somewhere safe, you will use it to authenticate with the API. 32 | 33 | ## Usage 34 | 35 | ```py 36 | edge = Tami4EdgeAPI(refresh_token) 37 | print(f"Bar Name: {edge.device_metadata.name}, Firmware Version: {edge.device_metadata.device_firmware}") 38 | ``` 39 | 40 | ### Boil Water 41 | ```py 42 | edge.boil_water() 43 | ``` 44 | 45 | ### Get User Drinks 46 | ```py 47 | device = edge.get_device() 48 | for drink in device.drinks: 49 | print(drink.name) 50 | ``` 51 | 52 | ### Prepare A Drink 53 | ```py 54 | edge.prepare_drink(drink) 55 | ``` 56 | 57 | ### Get Filter / UV Information 58 | ```py 59 | water_quality = device.water_quality 60 | water_quality.uv.last_replacement 61 | water_quality.uv.upcoming_replacement 62 | water_quality.uv.installed 63 | water_quality.filter.milli_litters_passed 64 | ``` 65 | -------------------------------------------------------------------------------- /Tami4EdgeAPI/Tami4EdgeAPI.py: -------------------------------------------------------------------------------- 1 | import datetime 2 | import json 3 | import logging 4 | from json import JSONDecodeError 5 | from typing import Callable, Optional 6 | 7 | import jwt 8 | import requests 9 | from pypasser import reCaptchaV3 10 | from requests.auth import AuthBase 11 | from requests.exceptions import RequestException 12 | from requests.models import PreparedRequest 13 | 14 | from Tami4EdgeAPI import exceptions 15 | from Tami4EdgeAPI.device import Device 16 | from Tami4EdgeAPI.device_metadata import DeviceMetadata 17 | from Tami4EdgeAPI.drink import Drink 18 | from Tami4EdgeAPI.token import Token 19 | from Tami4EdgeAPI.water_quality import UV, Filter, WaterQuality 20 | 21 | 22 | class _Auth(AuthBase): 23 | def __init__(self, get_access_token: Callable) -> None: 24 | self.get_access_token = get_access_token 25 | 26 | def __call__(self, r: PreparedRequest) -> PreparedRequest: 27 | r.headers["authorization"] = "Bearer " + self.get_access_token() 28 | return r 29 | 30 | 31 | def request_wrapper( 32 | method: str, 33 | url: str, 34 | *args, 35 | session: Optional[requests.Session] = None, 36 | exception: Exception, 37 | **kwargs, 38 | ) -> requests.models.Response: 39 | try: 40 | if session: 41 | return session.request(method, url, *args, timeout=10, **kwargs) 42 | else: 43 | return requests.request(method, url, *args, timeout=10, **kwargs) 44 | except RequestException as ex: 45 | raise exception from ex 46 | 47 | 48 | class Tami4EdgeAPI: 49 | """Tami4Edge API Interface.""" 50 | 51 | ENDPOINT = "https://swelcustomers.strauss-water.com" 52 | AUTH_ENDPOINT = "https://authentication-prod.strauss-group.com" 53 | ANCHOR_URL = "https://www.google.com/recaptcha/enterprise/anchor?ar=1&k=6Lf-jYgUAAAAAEQiRRXezC9dfIQoxofIhqBnGisq&co=aHR0cHM6Ly93d3cudGFtaTQuY28uaWw6NDQz&hl=en&v=gWN_U6xTIPevg0vuq7g1hct0&size=invisible&cb=ji0lh9higcza" 54 | 55 | def __init__(self, refresh_token: str) -> None: 56 | logging.basicConfig(level=logging.INFO) 57 | 58 | self._token = Token(refresh_token=refresh_token) 59 | 60 | self._session = requests.Session() 61 | self._session.auth = _Auth(self.get_access_token) 62 | 63 | # As of date of writing, /v1/ seems to suppose to support multiple devices, 64 | # but /v2/ only supports one device. 65 | # Also, the app doesn't seem to support multiple devices at all. 66 | # So for now, we'll use the first device we get from the API. 67 | self.device_metadata = self._get_devices_metadata()[0] 68 | 69 | def get_access_token(self) -> str: 70 | """Get the access token, refreshing it if necessary.""" 71 | 72 | if not self._token.is_valid: 73 | logging.debug("Token is invalid, refreshing Token") 74 | self._request_new_token() 75 | 76 | return self._token.access_token 77 | 78 | def _request_new_token(self): 79 | response = request_wrapper( 80 | "POST", 81 | f"{Tami4EdgeAPI.AUTH_ENDPOINT}/api/v1/auth/token/refresh", 82 | headers={"X-Api-Key": "96787682-rrzh-0995-v9sz-cfdad9ac7072"}, 83 | json={"refreshToken": self._token.refresh_token}, 84 | exception=exceptions.TokenRefreshFailedException("Token Refresh Failed"), 85 | ) 86 | 87 | if "Invalid refresh token (expired)" in response.text: 88 | raise exceptions.RefreshTokenExpiredException("Refresh token has expired") 89 | 90 | try: 91 | response_json = response.json() 92 | except JSONDecodeError as ex: 93 | raise exceptions.TokenRefreshFailedException("Token Refresh Failed") from ex 94 | 95 | if "accessToken" not in response_json or "refreshToken" not in response_json: 96 | logging.error("Token Refresh Failed, response: %s", response_json) 97 | raise exceptions.TokenRefreshFailedException( 98 | "Token Refresh Failed: No accessToken key" 99 | ) 100 | 101 | access_token = jwt.decode( 102 | response_json["accessToken"], options={"verify_signature": False} 103 | ) 104 | 105 | logging.debug("Token Refresh Successful") 106 | 107 | self._token = Token( 108 | # Replace refresh token only if we get a new one 109 | refresh_token=( 110 | response_json["refreshToken"] 111 | if response_json["refreshToken"] is not None 112 | else self._token.refresh_token 113 | ), 114 | access_token=response_json["accessToken"], 115 | expires_at=datetime.datetime.fromtimestamp(access_token["exp"]), 116 | ) 117 | 118 | def _get_devices_metadata(self) -> list[DeviceMetadata]: 119 | response = request_wrapper( 120 | "GET", 121 | f"{self.ENDPOINT}/api/v1/device", 122 | session=self._session, 123 | exception=exceptions.APIRequestFailedException("Device Request Failed"), 124 | ) 125 | 126 | return [ 127 | DeviceMetadata( 128 | id=d["id"], 129 | name=d["name"], 130 | connected=d["connected"], 131 | psn=d["psn"], 132 | type=d["type"], 133 | device_firmware=d["deviceFirmware"], 134 | ) 135 | for d in response.json() 136 | ] 137 | 138 | def get_device(self) -> Device: 139 | """Fetch device data.""" 140 | 141 | response = request_wrapper( 142 | "GET", 143 | f"{self.ENDPOINT}/api/v3/customer/mainPage/{self.device_metadata.psn}", 144 | session=self._session, 145 | exception=exceptions.APIRequestFailedException( 146 | "Water Quality Request Failed" 147 | ), 148 | ).json() 149 | 150 | drinks = [ 151 | Drink( 152 | id=d["id"], 153 | name=d["name"], 154 | settings=d["settings"], 155 | vessel=d["vessel"], 156 | include_in_customer_statistics=d["includeInCustomerStatistics"], 157 | default_drink=d["defaultDrink"], 158 | ) 159 | for d in response["drinks"] 160 | ] 161 | 162 | dynamic_data = response["dynamicData"] 163 | _filter = dynamic_data["filterInfo"] 164 | uv = dynamic_data["uvInfo"] 165 | 166 | return Device( 167 | device_metadata=self.device_metadata, 168 | drinks=drinks, 169 | water_quality=WaterQuality( 170 | uv=UV( 171 | # last_replacement=uv["lastReplacement"], 172 | upcoming_replacement=uv["upcomingReplacement"], 173 | installed=uv["installed"], 174 | ), 175 | filter=Filter( 176 | # last_replacement=_filter["lastReplacement"], 177 | upcoming_replacement=_filter["upcomingReplacement"], 178 | milli_litters_passed=_filter["milliLittersPassed"], 179 | installed=_filter["installed"], 180 | ), 181 | ), 182 | ) 183 | 184 | def prepare_drink(self, drink: Drink) -> None: 185 | """Prepare a drink.""" 186 | 187 | request_wrapper( 188 | "POST", 189 | f"{self.ENDPOINT}/api/v1/device/{self.device_metadata.id}/prepareDrink/{drink.id}", 190 | session=self._session, 191 | exception=exceptions.APIRequestFailedException( 192 | "Drink Prepare Request Failed" 193 | ), 194 | ) 195 | 196 | def boil_water(self) -> None: 197 | """Boil water.""" 198 | 199 | response = request_wrapper( 200 | "POST", 201 | f"{self.ENDPOINT}/api/v1/device/{self.device_metadata.id}/startBoiling", 202 | session=self._session, 203 | exception=exceptions.APIRequestFailedException("Boil Water Request Failed"), 204 | ) 205 | 206 | if response.status_code == 502: 207 | logging.info("Water is already boiling") 208 | 209 | @staticmethod 210 | def _get_recaptcha_token() -> str: 211 | return reCaptchaV3(Tami4EdgeAPI.ANCHOR_URL) 212 | 213 | @staticmethod 214 | def request_otp(phone_number: str) -> None: 215 | """Request an OTP code.""" 216 | 217 | response = request_wrapper( 218 | "POST", 219 | f"{Tami4EdgeAPI.AUTH_ENDPOINT}/api/v1/auth/otp/request", 220 | headers={"X-Api-Key": "96787682-rrzh-0995-v9sz-cfdad9ac7072"}, 221 | json={ 222 | "phone": phone_number, 223 | "reCaptchaToken": Tami4EdgeAPI._get_recaptcha_token(), 224 | }, 225 | exception=exceptions.OTPFailedException("OTP Request Failed"), 226 | ) 227 | 228 | if response.status_code != 200: 229 | logging.error("OTP Request Failed, response: %s", response.content) 230 | raise exceptions.OTPFailedException("OTP Request Failed") 231 | 232 | logging.info("OTP Request Successful") 233 | 234 | @staticmethod 235 | def submit_otp(phone_number: str, otp: int) -> str: 236 | """Submit an OTP code.""" 237 | 238 | response = request_wrapper( 239 | "POST", 240 | f"{Tami4EdgeAPI.AUTH_ENDPOINT}/api/v1/auth/otp/submit", 241 | headers={"X-Api-Key": "96787682-rrzh-0995-v9sz-cfdad9ac7072"}, 242 | json={ 243 | "phone": phone_number, 244 | "otp": otp, 245 | "reCaptchaToken": Tami4EdgeAPI._get_recaptcha_token(), 246 | }, 247 | exception=exceptions.OTPFailedException("OTP Submission Failed"), 248 | ).json() 249 | 250 | if "accessToken" not in response: 251 | logging.error("OTP Submission Failed, response: %s", response) 252 | raise exceptions.OTPFailedException("OTP Submission Failed") 253 | 254 | logging.info("OTP Submission Successful") 255 | 256 | return response["refreshToken"] 257 | -------------------------------------------------------------------------------- /Tami4EdgeAPI/__init__.py: -------------------------------------------------------------------------------- 1 | from .Tami4EdgeAPI import Tami4EdgeAPI 2 | from .Tami4EdgeAPI import exceptions 3 | -------------------------------------------------------------------------------- /Tami4EdgeAPI/device.py: -------------------------------------------------------------------------------- 1 | from dataclasses import dataclass 2 | 3 | from Tami4EdgeAPI import device_metadata, water_quality 4 | from Tami4EdgeAPI.drink import Drink 5 | 6 | 7 | @dataclass 8 | class Device(object): 9 | device_metadata: device_metadata.DeviceMetadata 10 | water_quality: water_quality.WaterQuality 11 | drinks: list[Drink] 12 | -------------------------------------------------------------------------------- /Tami4EdgeAPI/device_metadata.py: -------------------------------------------------------------------------------- 1 | from dataclasses import dataclass 2 | 3 | 4 | @dataclass 5 | class DeviceMetadata(object): 6 | id: int 7 | name: str 8 | connected: bool 9 | psn: str 10 | type: str 11 | device_firmware: str 12 | -------------------------------------------------------------------------------- /Tami4EdgeAPI/drink.py: -------------------------------------------------------------------------------- 1 | from dataclasses import dataclass 2 | 3 | 4 | @dataclass 5 | class Drink(object): 6 | id: str 7 | name: str 8 | settings: list[str] 9 | vessel: str 10 | include_in_customer_statistics: bool 11 | default_drink: bool 12 | -------------------------------------------------------------------------------- /Tami4EdgeAPI/exceptions.py: -------------------------------------------------------------------------------- 1 | class Tami4EdgeAPIException(Exception): 2 | pass 3 | 4 | 5 | class TokenRefreshFailedException(Tami4EdgeAPIException): 6 | pass 7 | 8 | 9 | class RefreshTokenExpiredException(TokenRefreshFailedException): 10 | pass 11 | 12 | 13 | class APIRequestFailedException(Tami4EdgeAPIException): 14 | pass 15 | 16 | 17 | class OTPFailedException(Tami4EdgeAPIException): 18 | pass 19 | -------------------------------------------------------------------------------- /Tami4EdgeAPI/token.py: -------------------------------------------------------------------------------- 1 | from datetime import datetime, timedelta 2 | from typing import Optional 3 | 4 | 5 | class Token(object): 6 | refresh_token: str 7 | access_token: str 8 | expires_at: Optional[datetime] 9 | 10 | def __init__( 11 | self, 12 | refresh_token: str, 13 | access_token: Optional[str] = None, 14 | expires_at: Optional[datetime] = None, 15 | ): 16 | self.refresh_token = refresh_token 17 | self.access_token = access_token if access_token else None 18 | self.expires_at = expires_at 19 | 20 | @property 21 | def is_valid(self): 22 | return ( 23 | self.access_token is not None 24 | and self.expires_at is not None 25 | and self.expires_at > datetime.now() 26 | ) 27 | -------------------------------------------------------------------------------- /Tami4EdgeAPI/water_quality.py: -------------------------------------------------------------------------------- 1 | from dataclasses import dataclass 2 | from datetime import date 3 | 4 | 5 | @dataclass 6 | class QualityInfo: 7 | # last_replacement: date 8 | upcoming_replacement: date 9 | installed: bool 10 | 11 | def __post_init__(self) -> None: 12 | # self.last_replacement = date.fromtimestamp(self.last_replacement / 1000) 13 | self.upcoming_replacement = date.fromtimestamp(self.upcoming_replacement / 1000) 14 | 15 | 16 | @dataclass 17 | class UV(QualityInfo): 18 | pass 19 | 20 | 21 | @dataclass 22 | class Filter(QualityInfo): 23 | milli_litters_passed: int 24 | 25 | 26 | @dataclass 27 | class WaterQuality(object): 28 | uv: UV 29 | filter: Filter 30 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | import setuptools 2 | 3 | with open("README.md", "r") as f: 4 | long_description = f.read() 5 | 6 | setuptools.setup( 7 | name="Tami4EdgeAPI", 8 | version="3.0", 9 | author="Guy Shefer", 10 | license="MIT", 11 | long_description=long_description, 12 | long_description_content_type="text/markdown", 13 | url="https://github.com/Guy293/Tami4EdgeAPI", 14 | packages=setuptools.find_packages(), 15 | install_requires=["requests", "pypasser", "pyjwt"], 16 | ) 17 | --------------------------------------------------------------------------------