Skip to content

Commit

Permalink
Add support for time zone and trend start
Browse files Browse the repository at this point in the history
  • Loading branch information
kbickar committed Jan 17, 2022
1 parent a5d9135 commit be2ab87
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
9 changes: 8 additions & 1 deletion sense_energy/asyncsenseable.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import aiohttp
import websockets
from datetime import datetime, timezone, timedelta

from .sense_api import *
from .sense_exceptions import *
Expand Down Expand Up @@ -116,7 +117,7 @@ async def get_trend_data(self, scale, dt=None):
if scale.upper() not in valid_scales:
raise Exception("%s not a valid scale" % scale)
if not dt:
dt = datetime.now().replace(hour=12)
dt = datetime.now(timezone(timedelta(0))).astimezone()
json = self.api_call(
"app/history/trends?monitor_id=%s&scale=%s&start=%s"
% (self.sense_monitor_id, scale, dt.isoformat())
Expand All @@ -127,6 +128,12 @@ async def update_trend_data(self, dt=None):
for scale in valid_scales:
await self.get_trend_data(scale, dt)

async def get_monitor_data(self):
json = await self.api_call("app/monitors/%s/overview" % self.sense_monitor_id)
if 'monitor_overview' in json and 'monitor' in json['monitor_overview']:
self._monitor = json['monitor_overview']['monitor']
return self._monitor

async def get_discovered_device_names(self):
# lots more info in here to be parsed out
json = self.api_call("app/monitors/%s/devices" % self.sense_monitor_id)
Expand Down
9 changes: 8 additions & 1 deletion sense_energy/sense_api.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import json
import sys
from time import time
from datetime import datetime

from .sense_exceptions import *

Expand Down Expand Up @@ -29,6 +28,7 @@ def __init__(self, username=None, password=None,
self._realtime = {}
self._devices = []
self._trend_data = {}
self._monitor = {}
for scale in valid_scales: self._trend_data[scale] = {}

if username and password:
Expand Down Expand Up @@ -186,6 +186,13 @@ def yearly_solar_powered(self):
@property
def active_devices(self):
return [d['name'] for d in self._realtime.get('devices', {})]

@property
def time_zone(self):
return self._monitor.get('time_zone', '')

def trend_start(self, scale):
return self._trend_data[scale]['start']

def get_trend(self, scale, key):
if isinstance(key, bool):
Expand Down
9 changes: 8 additions & 1 deletion sense_energy/senseable.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def get_trend_data(self, scale, dt=None):
if scale.upper() not in valid_scales:
raise Exception("%s not a valid scale" % scale)
if not dt:
dt = datetime.now().replace(hour=12)
dt = datetime.now(timezone(timedelta(0))).astimezone()
self._trend_data[scale] = self.api_call(
'app/history/trends?monitor_id=%s&scale=%s&start=%s' %
(self.sense_monitor_id, scale, dt.isoformat()))
Expand Down Expand Up @@ -114,6 +114,13 @@ def get_device_info(self, device_id):
# Get specific informaton about a device
return self.api_call('app/monitors/%s/devices/%s' %
(self.sense_monitor_id, device_id))

def get_monitor_data(self):
# Get monitor overview info
json = self.api_call("app/monitors/%s/overview" % self.sense_monitor_id)
if 'monitor_overview' in json and 'monitor' in json['monitor_overview']:
self._monitor = json['monitor_overview']['monitor']
return self._monitor

def get_all_usage_data(self, payload = {'n_items': 30}):
"""Gets usage data by device
Expand Down

0 comments on commit be2ab87

Please sign in to comment.