Last active
May 11, 2026 11:09
-
-
Save miditkl/f44cd08bd0c47982fcdb67c7451a939a to your computer and use it in GitHub Desktop.
This script logs into your De'Longhi account, retrieves an authentication token, and then fetches information about your registered coffee machines or other De'Longhi comfort devices.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| """ | |
| De'Longhi Device Info Retriever | |
| This script logs into your De'Longhi account, retrieves an authentication token, | |
| and then fetches information about your registered coffee machines or other | |
| De'Longhi comfort devices. | |
| It's designed as a simple, command-line tool that leaves no trace on your system, | |
| as it cleans up the temporary token file it creates. | |
| --- | |
| Installation: | |
| You need to install two Python libraries. You can do this using pip: | |
| pip install requests cremalink | |
| --- | |
| How to run: | |
| Save this file (e.g., as `delonghi_device_info.py`) and run it from your terminal: | |
| python delonghi_device_info.py | |
| The script will then prompt you for your De'Longhi account email and password. | |
| """ | |
| import json | |
| import tempfile | |
| import os | |
| import sys | |
| import getpass | |
| from cremalink.resources.lang import load_lang_config | |
| from cremalink.clients.auth import authenticate_cloud | |
| from cremalink import Client | |
| def main(): | |
| """Main function to run the CLI application.""" | |
| print("De'Longhi Device Info Retriever") | |
| print("===============================\n") | |
| temp_token_path = None | |
| try: | |
| email = input("Email: ") | |
| if sys.stdin.isatty(): | |
| password = getpass.getpass("Password: ") | |
| else: | |
| print("Warning: Running in a non-interactive environment. Password will be visible.") | |
| password = input("Password: ") | |
| lang = input("Language: ") | |
| lang_conf = load_lang_config() | |
| available_langs = lang_conf.get('languages').keys() | |
| if not lang.lower() in available_langs: | |
| print("Language not supported. Please try again.") | |
| print("Available languages:") | |
| langs = "" | |
| for lang in available_langs: | |
| langs += lang + ", " | |
| print(f"{langs}") | |
| return | |
| print('\n Logging in...') | |
| refresh_token = authenticate_cloud(email=email, password=password, language=lang).refresh_token | |
| # Create a temporary file, write to it, and close it. | |
| # delete=False is important for Windows compatibility. | |
| with tempfile.NamedTemporaryFile(mode='w', delete=False, suffix='.json', encoding='utf-8') as temp_token_file: | |
| temp_token_path = temp_token_file.name | |
| json.dump({"refresh_token": refresh_token}, temp_token_file) | |
| print("\nFetching device information...") | |
| client = Client(token_path=temp_token_path) | |
| dsns = client.get_devices() | |
| if not dsns: | |
| print("No devices found.") | |
| return | |
| for dsn in dsns: | |
| device = client.get_device(dsn) | |
| print(f"---------------------------------") | |
| print(f" Model: {device.model}") | |
| print(f" DSN: {device.dsn}") | |
| print(f" Local IP address: {device.ip}") | |
| print(f" Lan Key: {device.lan_key}") | |
| print(f" Refresh Token: {refresh_token}") | |
| print(f"---------------------------------") | |
| except KeyError as e: | |
| print(f"\nAn error occurred: Could not find expected data in the response. {e}") | |
| except Exception as e: | |
| print(f"\nAn unexpected error occurred: {e}") | |
| finally: | |
| # Clean up the temporary file manually | |
| if temp_token_path and os.path.exists(temp_token_path): | |
| os.remove(temp_token_path) | |
| if __name__ == "__main__": | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment