diff --git a/sense_energy/asyncsenseable.py b/sense_energy/asyncsenseable.py index 1044569..13f2b3c 100644 --- a/sense_energy/asyncsenseable.py +++ b/sense_energy/asyncsenseable.py @@ -4,6 +4,7 @@ import aiohttp import websockets +from datetime import datetime, timezone, timedelta from .sense_api import * from .sense_exceptions import * @@ -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()) @@ -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) diff --git a/sense_energy/sense_api.py b/sense_energy/sense_api.py index fa693d8..a6cafac 100644 --- a/sense_energy/sense_api.py +++ b/sense_energy/sense_api.py @@ -1,7 +1,6 @@ import json import sys from time import time -from datetime import datetime from .sense_exceptions import * @@ -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: @@ -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): diff --git a/sense_energy/senseable.py b/sense_energy/senseable.py index 410b067..48180f4 100644 --- a/sense_energy/senseable.py +++ b/sense_energy/senseable.py @@ -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())) @@ -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