Skip to content

Commit fa430e9

Browse files
committed
✨ Add switch_capacity
1 parent 882daec commit fa430e9

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,15 @@ print(time_series_data)
6464
device = client.get_device(devices[0]['id'])
6565
device['configuration']['controlMode'] = 'MANUAL'
6666
client.put_device(device['id'], device)
67+
68+
# Switch the POWER_SWITCH capacity
69+
for feature in device['features']:
70+
for capacity in feature['capacities']:
71+
if capacity.get('capacity', {}).get('nature') == "POWER_SWITCH":
72+
capacity_id = capacity['capacity']['id']
73+
client.switch_capacity(capacity_id, False)
74+
client.switch_capacity(capacity_id, True)
75+
6776
```
6877

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

comwatt_client/client.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,3 +265,23 @@ def get_device_ts_time_ago(self, device_id,
265265
return response.json()
266266
else:
267267
raise Exception(f'Error retrieving aggregations: {response.status_code}')
268+
269+
def switch_capacity(self, capacity_id, enable):
270+
"""
271+
Switch a specific capcaity to the enable value.
272+
273+
Args:
274+
capacity_id (str): The ID of the capacity.
275+
enable (bool): The target state.
276+
277+
Returns:
278+
dict: A dictionary containing the response from the API.
279+
280+
"""
281+
url = f'{self.base_url}/capacities/{capacity_id}/switch?enable={enable}'
282+
283+
response = self.session.put(url)
284+
if response.status_code == 200:
285+
return response.json()
286+
else:
287+
raise Exception(f'Error retrieving sites: {response.status_code}')

0 commit comments

Comments
 (0)