|
| 1 | +# Comwatt Python Client (Legacy) |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +The Comwatt Python Client (Legacy) is a Python library that provides a convenient way to interact with the legacy Comwatt API (`go.comwatt.com/api`). It allows you to authenticate users, retrieve authenticated user information, and access owner, box, product, device, and statistical data. |
| 6 | + |
| 7 | +Please note that this client is intended for devices below gen4 and uses the deprecated `go.comwatt.com`. If you're looking for the client compatible with gen4 devices and the `energy.comwatt.com`, please refer to the [python-comwatt-client](https://github.com/MateoGreil/python-comwatt-client). |
| 8 | + |
| 9 | +## Features |
| 10 | + |
| 11 | +The client currently supports the following methods: |
| 12 | + |
| 13 | +- `authenticate(self, username, password)`: Authenticates a user with the provided username and password. |
| 14 | +- `get_authenticated_user(self)`: Retrieves information about the authenticated user. |
| 15 | +- `get_owner_details(self, owner_id)`: Retrieves information about the owner's details. |
| 16 | +- `get_box_details(self, macAddress)`: Retrieves information about the box's details. |
| 17 | +- `get_products(self)`: Retrieves information about the products. |
| 18 | +- `get_devices(self, indepbox_id)`: Retrieves a list of devices for the specified box. |
| 19 | +- `get_networkstats(self, indepbox_id, level="HOUR", measure_kind="QUANTITY", start=datetime.now(), end=datetime.now())`: Retrieves a list of network statistics for the specified box. |
| 20 | +- `get_devices_stats(self, device_id, measure_kind="QUANTITY", measure_type_id="1", level="HOUR", start=datetime.now(), end=datetime.now())`: Retrieves a list of device statistics for the specified device. |
| 21 | + |
| 22 | +## Installation |
| 23 | + |
| 24 | +You can install the Comwatt Python Client (Legacy) using pip. Run the following command: |
| 25 | + |
| 26 | +``` |
| 27 | +pip install comwatt-client-legacy |
| 28 | +``` |
| 29 | + |
| 30 | +## Usage |
| 31 | + |
| 32 | +Here's a simple example of how to use the Comwatt Python Client (Legacy): |
| 33 | + |
| 34 | +```python |
| 35 | +from comwatt.client import ComwattClient |
| 36 | +from datetime import datetime, timedelta |
| 37 | + |
| 38 | +# Create a Comwatt client instance |
| 39 | +client = ComwattClient() |
| 40 | + |
| 41 | +# Authenticate the user |
| 42 | +client.authenticate('username', 'password') |
| 43 | + |
| 44 | +# Get information about the authenticated user |
| 45 | +user_info = client.get_authenticated_user() |
| 46 | +print(user_info) |
| 47 | + |
| 48 | +# Get owner details |
| 49 | +owner_id = user_info['id'] |
| 50 | +owner_details = client.get_owner_details(owner_id) |
| 51 | +print(owner_details) |
| 52 | + |
| 53 | +# Get box details |
| 54 | +macAddress = owner_details[0]['macAddress'] |
| 55 | +box_details = client.get_box_details(macAddress) |
| 56 | +print(box_details) |
| 57 | + |
| 58 | +# Get products |
| 59 | +products = client.get_products() |
| 60 | +print(products) |
| 61 | + |
| 62 | +# Get devices for a specific box |
| 63 | +indepbox_id = box_details['id'] |
| 64 | +devices = client.get_devices(indepbox_id) |
| 65 | +print(devices) |
| 66 | + |
| 67 | +# Get network statistics for a specific box |
| 68 | +start_date = datetime.now() - timedelta(days=7) |
| 69 | +end_date = datetime.now() |
| 70 | +networkstats = client.get_networkstats(indepbox_id, start=start_date, end=end_date) |
| 71 | +print(networkstats) |
| 72 | + |
| 73 | +# Get device statistics for a specific device |
| 74 | +device_id = devices[0]['id'] |
| 75 | +devices_stats = client.get_devices_stats(device_id, start=start_date, end=end_date) |
| 76 | +print(devices_stats) |
| 77 | +``` |
| 78 | + |
| 79 | +Make sure to replace `'username'` and `'password'` with the actual values for your Comwatt account. |
| 80 | + |
| 81 | +## Contributing |
| 82 | + |
| 83 | +Contributions to the Comwatt Python Client (Legacy) are welcome! If you find any issues or have suggestions for improvement, please open an issue or submit a pull request on the GitHub repository. |
0 commit comments