Skip to content

Commit bac1382

Browse files
committed
✨ Add device timeseries
1 parent e61b349 commit bac1382

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ The client currently supports the following methods:
1010
- `get_authenticated_user(self)`: Retrieves information about the authenticated user.
1111
- `get_sites(self)`: Retrieves a list of sites associated with the authenticated user.
1212
- `get_devices(self, site_id)`: Retrieves a list of devices for the specified site.
13+
- `get_device_ts_time_ago(self, device_id, measure_kind = "FLOW", aggregation_level = "HOUR", aggregation_type = "MAX", time_ago_unit = "DAY", time_ago_value = "1")`: Retrieves the time series data for a specific device, based on the provided parameters.
1314

1415
## Installation
1516
You can install the Comwatt Python Client using pip. Run the following command:
@@ -44,6 +45,10 @@ print(sites)
4445
# Get a list of devices for a specific site
4546
devices = client.get_devices(sites[0]['id'])
4647
print(devices)
48+
49+
# Get time series data for a specific device
50+
time_series_data = client.get_device_ts_time_ago(devices[0]['id'])
51+
print(time_series_data)
4752
```
4853

4954
Make sure to replace `'username'`, `'password'` with the actual values for your Comwatt account.

comwatt/client.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,12 @@ def get_devices(self, site_id):
4343
return response.json()
4444
else:
4545
raise Exception(f'Error retrieving sites: {response.sttaus_code}')
46+
47+
def get_device_ts_time_ago(self, device_id, measure_kind = "FLOW", aggregation_level = "HOUR", aggregation_type = "MAX", time_ago_unit = "DAY", time_ago_value = "1"):
48+
url = f'{self.base_url}/aggregations/device-ts-time-ago?deviceId={device_id}&measureKind={measure_kind}&aggregationLevel={aggregation_level}&aggregationType={aggregation_type}&timeAgoUnit={time_ago_unit}&timeAgoValue={time_ago_value}'
49+
50+
response = self.session.get(url)
51+
if response.status_code == 200:
52+
return response.json()
53+
else:
54+
raise Exception(f'Error retrieving aggregations: {response.status_code}')

0 commit comments

Comments
 (0)