Skip to content

Commit 13a0aa0

Browse files
committed
📝 Add functions docs
1 parent bd9136b commit 13a0aa0

1 file changed

Lines changed: 112 additions & 2 deletions

File tree

comwatt/client.py

Lines changed: 112 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,39 @@
22
import json
33

44
class ComwattClient:
5+
"""
6+
A client for interacting with the Comwatt API.
7+
8+
Args:
9+
None
10+
11+
Attributes:
12+
base_url (str): The base URL of the Comwatt API.
13+
session (requests.Session): The session object for making HTTP requests.
14+
15+
"""
516
def __init__(self):
617
self.base_url = 'https://energy.comwatt.com/api'
718
self.session = requests.Session()
819

920
# Password should be encrypted password, I don't know exactly what the encryption is for the
1021
# moment, so you will need to encrypt it from their webapp
1122
def authenticate(self, username, password):
23+
"""
24+
Authenticates a user with the provided username and password.
25+
26+
Args:
27+
username (str): The username of the user.
28+
password (str): The password of the user (encrypted).
29+
30+
Returns:
31+
None
32+
33+
Raises:
34+
Exception: If the authentication fails.
35+
36+
"""
37+
1238
url = f'{self.base_url}/v1/authent'
1339
data = {'username': username, 'password': password}
1440

@@ -18,6 +44,20 @@ def authenticate(self, username, password):
1844
raise Exception(f'Authentication failed: {response.status_code}')
1945

2046
def get_authenticated_user(self):
47+
"""
48+
Retrieves information about the authenticated user.
49+
50+
Args:
51+
None
52+
53+
Returns:
54+
dict: Information about the authenticated user.
55+
56+
Raises:
57+
Exception: If an error occurs while retrieving the information.
58+
59+
"""
60+
2161
url = f'{self.base_url}/users/authenticated'
2262

2363
response = self.session.get(url)
@@ -27,6 +67,20 @@ def get_authenticated_user(self):
2767
raise Exception(f'Error retrieving authenticated user: {response.sttaus_code}')
2868

2969
def get_sites(self):
70+
"""
71+
Retrieves a list of sites associated with the authenticated user.
72+
73+
Args:
74+
None
75+
76+
Returns:
77+
list: A list of sites.
78+
79+
Raises:
80+
Exception: If an error occurs while retrieving the sites.
81+
82+
"""
83+
3084
url = f'{self.base_url}/sites'
3185

3286
response = self.session.get(url)
@@ -36,6 +90,20 @@ def get_sites(self):
3690
raise Exception(f'Error retrieving sites: {response.sttaus_code}')
3791

3892
def get_devices(self, site_id):
93+
"""
94+
Retrieves a list of devices for the specified site.
95+
96+
Args:
97+
site_id (str): The ID of the site.
98+
99+
Returns:
100+
list: A list of devices.
101+
102+
Raises:
103+
Exception: If an error occurs while retrieving the devices.
104+
105+
"""
106+
39107
url = f'{self.base_url}/devices?siteId={site_id}'
40108

41109
response = self.session.get(url)
@@ -44,8 +112,31 @@ def get_devices(self, site_id):
44112
else:
45113
raise Exception(f'Error retrieving sites: {response.sttaus_code}')
46114

47-
def get_device_ts_time_ago(self, device_id, measure_kind = "FLOW", aggregation_level = "HOUR",
48-
aggregation_type = "MAX", time_ago_unit = "DAY", time_ago_value = "1"):
115+
def get_device_ts_time_ago(self, device_id,
116+
measure_kind = "FLOW",
117+
aggregation_level = "HOUR",
118+
aggregation_type = "MAX",
119+
time_ago_unit = "DAY",
120+
time_ago_value = "1"):
121+
"""
122+
Retrieves the time series data for a specific device, based on the provided parameters.
123+
124+
Args:
125+
device_id (str): The ID of the device.
126+
measure_kind (str): The kind of measure (default: "FLOW").
127+
aggregation_level (str): The aggregation level (default: "HOUR").
128+
aggregation_type (str): The aggregation type (default: "MAX").
129+
time_ago_unit (str): The unit of time ago (default: "DAY").
130+
time_ago_value (str): The value of time ago (default: "1").
131+
132+
Returns:
133+
dict: The time series data.
134+
135+
Raises:
136+
Exception: If an error occurs while retrieving the data.
137+
138+
"""
139+
49140
url = (f'{self.base_url}/aggregations/device-ts-time-ago?'
50141
f'deviceId={device_id}&'
51142
f'measureKind={measure_kind}&'
@@ -66,6 +157,25 @@ def get_site_networks_ts_time_ago(self, site_id,
66157
aggregation_type = "SUM",
67158
time_ago_unit = "DAY",
68159
time_ago_value = 1):
160+
"""
161+
Retrieves the time series data for the networks of a specific site, based on the provided parameters.
162+
163+
Args:
164+
site_id (str): The ID of the site.
165+
measure_kind (str): The kind of measure (default: "VIRTUAL_QUANTITY").
166+
aggregation_level (str): The aggregation level (default: "HOUR").
167+
aggregation_type (str): The aggregation type (default: "SUM").
168+
time_ago_unit (str): The unit of time ago (default: "DAY").
169+
time_ago_value (int): The value of time ago (default: 1).
170+
171+
Returns:
172+
dict: The time series data.
173+
174+
Raises:
175+
Exception: If an error occurs while retrieving the data.
176+
177+
"""
178+
69179
url = (f'{self.base_url}/aggregations/site-networks-ts-time-ago?'
70180
f'siteId={site_id}&'
71181
f'measureKind={measure_kind}&'

0 commit comments

Comments
 (0)