Skip to content

Commit

Permalink
Add backwards compatibility to get_trend(). (#48)
Browse files Browse the repository at this point in the history
* Add backwards compatibility to get_trend().

Add logic to handle prior boolean input to get_trend() to avoid breaking existing the existing HA sensor, as well as other users.

* Bump version up.
  • Loading branch information
crkochan authored Aug 17, 2021
1 parent 12c194d commit 8623ae3
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion sense_energy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
from .plug_instance import PlugInstance
from .sense_link import SenseLink

__version__ = "0.9.1"
__version__ = "0.9.2"
5 changes: 4 additions & 1 deletion sense_energy/sense_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,10 @@ def active_devices(self):
return [d['name'] for d in self._realtime.get('devices', {})]

def get_trend(self, scale, key):
key = 'consumption' if key == 'usage' else key
if isinstance(key, bool):
key = 'production' if key is True else 'consumption'
else:
key = 'consumption' if key == 'usage' else key
if key not in self._trend_data[scale]: return 0
# Perform a check for a valid type
if not isinstance(self._trend_data[scale][key], (dict, float, int)): return 0
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
'websockets;python_version>="3.5"',
'aiohttp;python_version>="3.5"',
],
version = '0.9.1',
version = '0.9.2',
description = 'API for the Sense Energy Monitor',
long_description=long_description,
long_description_content_type="text/markdown",
Expand Down

0 comments on commit 8623ae3

Please sign in to comment.