Skip to content

Commit

Permalink
Fix api_call and modify get_all_usage_data (#52)
Browse files Browse the repository at this point in the history
* fix get wtih params

* modify get_all_usage_data to accept payload
  • Loading branch information
benbogart authored Nov 8, 2021
1 parent ef57e03 commit 0b0ce27
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions sense_energy/senseable.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def api_call(self, url, payload={}):
return self.s.get(API_URL + url,
headers=self.headers,
timeout=self.api_timeout,
data=payload).json()
params=payload).json()
except ReadTimeout:
raise SenseAPITimeoutException("API call timed out")

Expand Down Expand Up @@ -114,8 +114,21 @@ def get_device_info(self, device_id):
return self.api_call('app/monitors/%s/devices/%s' %
(self.sense_monitor_id, device_id))

def get_all_usage_data(self):
payload = {'n_items': 30}
def get_all_usage_data(self, payload = {'n_items': 30}):
"""Gets usage data by device
Args:
payload (dict, optional): known params are:
n_items: the number of items to return
device_id: limit results to a specific device_id
prior_to_item:. date in format YYYY-MM-DDTHH:MM:SS.mmmZ
rollup: ?
Defaults to {'n_items': 30}.
Returns:
dict: usage data
"""
# lots of info in here to be parsed out
return self.api_call('users/%s/timeline' %
(self.sense_user_id), payload)
Expand Down

0 comments on commit 0b0ce27

Please sign in to comment.