Skip to content

Commit db747b7

Browse files
committed
✨ Add consumption breakdown
1 parent 28422ba commit db747b7

2 files changed

Lines changed: 74 additions & 34 deletions

File tree

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ 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_site_networks_ts_time_ago(self, site_id, measure_kind = "VIRTUAL_QUANTITY", aggregation_level = "HOUR", aggregation_type = "SUM", time_ago_unit = "DAY", time_ago_value = 1)`: Retrieves the time series data for the networks of a specific site, based on the provided parameters.
13+
- `get_site_consumption_breakdown_time_ago(self, site_id, aggregation_level = "HOUR", time_ago_unit = "DAY", time_ago_value = 1)` Retrieves the consumption breakdown data for a specific site, based on the provided parameters.
1314
- `get_devices(self, site_id)`: Retrieves a list of devices for the specified site.
1415
- `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.
1516

17+
1618
## Installation
1719
You can install the Comwatt Python Client using pip. Run the following command:
1820

@@ -47,6 +49,10 @@ print(sites)
4749
networks_time_series_data = client.get_site_networks_ts_time_ago(sites[0]['id'])
4850
print(networks_time_series_data)
4951

52+
# Get the consumption breakdown data for a specific site, based on the provided parameters.
53+
consumption_breakdown_data = client.get_site_consumption_breakdown_time_ago(sites[0]['id'])
54+
print(consumption_breakdown_data)
55+
5056
# Get a list of devices for a specific site
5157
devices = client.get_devices(sites[0]['id'])
5258
print(devices)

src/client.py

Lines changed: 68 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -89,84 +89,118 @@ def get_sites(self):
8989
else:
9090
raise Exception(f'Error retrieving sites: {response.sttaus_code}')
9191

92-
def get_devices(self, site_id):
92+
93+
def get_site_networks_ts_time_ago(self, site_id,
94+
measure_kind = "VIRTUAL_QUANTITY",
95+
aggregation_level = "HOUR",
96+
aggregation_type = "SUM",
97+
time_ago_unit = "DAY",
98+
time_ago_value = 1):
9399
"""
94-
Retrieves a list of devices for the specified site.
100+
Retrieves the time series data for the networks of a specific site, based on the provided parameters.
95101
96102
Args:
97103
site_id (str): The ID of the site.
104+
measure_kind (str): The kind of measure (default: "VIRTUAL_QUANTITY").
105+
aggregation_level (str): The aggregation level (default: "HOUR").
106+
aggregation_type (str): The aggregation type (default: "SUM").
107+
time_ago_unit (str): The unit of time ago (default: "DAY").
108+
time_ago_value (int): The value of time ago (default: 1).
98109
99110
Returns:
100-
list: A list of devices.
111+
dict: The time series data.
101112
102113
Raises:
103-
Exception: If an error occurs while retrieving the devices.
114+
Exception: If an error occurs while retrieving the data.
104115
105116
"""
106117

107-
url = f'{self.base_url}/devices?siteId={site_id}'
118+
url = (f'{self.base_url}/aggregations/site-networks-ts-time-ago?'
119+
f'siteId={site_id}&'
120+
f'measureKind={measure_kind}&'
121+
f'aggregationLevel={aggregation_level}&'
122+
f'aggregationType={aggregation_type}&'
123+
f'timeAgoUnit={time_ago_unit}&'
124+
f'timeAgoValue={time_ago_value}')
108125

109126
response = self.session.get(url)
110127
if response.status_code == 200:
111128
return response.json()
112129
else:
113-
raise Exception(f'Error retrieving sites: {response.sttaus_code}')
130+
raise Exception(f'Error retrieving aggregations: {response.status_code}')
114131

115-
def get_device_ts_time_ago(self, device_id,
116-
measure_kind = "FLOW",
132+
def get_site_consumption_breakdown_time_ago(self, site_id,
117133
aggregation_level = "HOUR",
118-
aggregation_type = "MAX",
119134
time_ago_unit = "DAY",
120-
time_ago_value = "1"):
135+
time_ago_value = 1):
121136
"""
122-
Retrieves the time series data for a specific device, based on the provided parameters.
137+
Retrieves the consumption breakdown data for a specific site, based on the provided parameters.
123138
124139
Args:
125-
device_id (str): The ID of the device.
126-
measure_kind (str): The kind of measure (default: "FLOW").
140+
site_id (str): The ID of the site.
127141
aggregation_level (str): The aggregation level (default: "HOUR").
128-
aggregation_type (str): The aggregation type (default: "MAX").
129142
time_ago_unit (str): The unit of time ago (default: "DAY").
130-
time_ago_value (str): The value of time ago (default: "1").
143+
time_ago_value (int): The value of time ago (default: 1).
131144
132145
Returns:
133-
dict: The time series data.
146+
dict: The consumption breakdown data.
134147
135148
Raises:
136149
Exception: If an error occurs while retrieving the data.
137150
138151
"""
139152

140-
url = (f'{self.base_url}/aggregations/device-ts-time-ago?'
141-
f'deviceId={device_id}&'
142-
f'measureKind={measure_kind}&'
143-
f'aggregationLevel={aggregation_level}&'
144-
f'aggregationType={aggregation_type}&'
145-
f'timeAgoUnit={time_ago_unit}&'
146-
f'timeAgoValue={time_ago_value}')
153+
url = (f'{self.base_url}/aggregations/consumption-breakdown-time-ago?'
154+
f'siteId={site_id}&'
155+
f'aggregationLevel={aggregation_level}&'
156+
f'timeAgoUnit={time_ago_unit}&'
157+
f'timeAgoValue={time_ago_value}')
147158

148159
response = self.session.get(url)
149160
if response.status_code == 200:
150161
return response.json()
151162
else:
152163
raise Exception(f'Error retrieving aggregations: {response.status_code}')
153164

154-
def get_site_networks_ts_time_ago(self, site_id,
155-
measure_kind = "VIRTUAL_QUANTITY",
165+
def get_devices(self, site_id):
166+
"""
167+
Retrieves a list of devices for the specified site.
168+
169+
Args:
170+
site_id (str): The ID of the site.
171+
172+
Returns:
173+
list: A list of devices.
174+
175+
Raises:
176+
Exception: If an error occurs while retrieving the devices.
177+
178+
"""
179+
180+
url = f'{self.base_url}/devices?siteId={site_id}'
181+
182+
response = self.session.get(url)
183+
if response.status_code == 200:
184+
return response.json()
185+
else:
186+
raise Exception(f'Error retrieving sites: {response.sttaus_code}')
187+
188+
def get_device_ts_time_ago(self, device_id,
189+
measure_kind = "FLOW",
156190
aggregation_level = "HOUR",
157-
aggregation_type = "SUM",
191+
aggregation_type = "MAX",
158192
time_ago_unit = "DAY",
159-
time_ago_value = 1):
193+
time_ago_value = "1"):
160194
"""
161-
Retrieves the time series data for the networks of a specific site, based on the provided parameters.
195+
Retrieves the time series data for a specific device, based on the provided parameters.
162196
163197
Args:
164-
site_id (str): The ID of the site.
165-
measure_kind (str): The kind of measure (default: "VIRTUAL_QUANTITY").
198+
device_id (str): The ID of the device.
199+
measure_kind (str): The kind of measure (default: "FLOW").
166200
aggregation_level (str): The aggregation level (default: "HOUR").
167-
aggregation_type (str): The aggregation type (default: "SUM").
201+
aggregation_type (str): The aggregation type (default: "MAX").
168202
time_ago_unit (str): The unit of time ago (default: "DAY").
169-
time_ago_value (int): The value of time ago (default: 1).
203+
time_ago_value (str): The value of time ago (default: "1").
170204
171205
Returns:
172206
dict: The time series data.
@@ -176,8 +210,8 @@ def get_site_networks_ts_time_ago(self, site_id,
176210
177211
"""
178212

179-
url = (f'{self.base_url}/aggregations/site-networks-ts-time-ago?'
180-
f'siteId={site_id}&'
213+
url = (f'{self.base_url}/aggregations/device-ts-time-ago?'
214+
f'deviceId={device_id}&'
181215
f'measureKind={measure_kind}&'
182216
f'aggregationLevel={aggregation_level}&'
183217
f'aggregationType={aggregation_type}&'

0 commit comments

Comments
 (0)