From 6ace05c1c8a72b34a0502e36223278f2621303fa Mon Sep 17 00:00:00 2001 From: Ian Richardson Date: Sat, 12 Jan 2019 00:14:24 -0600 Subject: [PATCH] fix accumulation of data --- README.md | 2 +- custom_components/sensor/personalcapital.py | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 1926592..915e29a 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![Version](https://img.shields.io/badge/version-0.0.7-green.svg?style=for-the-badge)](#) [![mantained](https://img.shields.io/maintenance/yes/2019.svg?style=for-the-badge)](#) +[![Version](https://img.shields.io/badge/version-0.0.8-green.svg?style=for-the-badge)](#) [![mantained](https://img.shields.io/maintenance/yes/2019.svg?style=for-the-badge)](#) [![maintainer](https://img.shields.io/badge/maintainer-Ian%20Richardson%20%40iantrich-blue.svg?style=for-the-badge)](#) diff --git a/custom_components/sensor/personalcapital.py b/custom_components/sensor/personalcapital.py index 501181e..431caab 100644 --- a/custom_components/sensor/personalcapital.py +++ b/custom_components/sensor/personalcapital.py @@ -15,7 +15,7 @@ from homeassistant.components.sensor import (PLATFORM_SCHEMA) from homeassistant.util import Throttle -__version__ = '0.0.7' +__version__ = '0.0.8' REQUIREMENTS = ['personalcapital==1.0.1'] @@ -248,7 +248,6 @@ def __init__(self, hass, rest, unit_of_measurement, sensor_type): self._balanceName = SENSOR_TYPES[sensor_type][2] self._state = None self._unit_of_measurement = unit_of_measurement - self.hass.data[self._productType] = {'accounts': []} def update(self): """Get the latest state of the sensor.""" @@ -256,6 +255,7 @@ def update(self): data = self._rest.data.json()['spData'] self._state = data.get(self._balanceName, 0.0) accounts = data.get('accounts') + self.hass.data[self._productType] = {'accounts': []} for account in accounts: if self._productType == account.get('productType') and account.get('closeDate', '') == '': @@ -267,7 +267,7 @@ def update(self): "account_type": account.get('accountType', ''), "url": account.get('homeUrl', ''), "currency": account.get('currency', ''), - "refreshed": how_long_ago(account.get('lastRefreshed', 0)) + ' ago', + "refreshed": howLongAgo(account.get('lastRefreshed', 0)) + ' ago', }) @property @@ -314,7 +314,7 @@ def update(self): self.data = self._pc.fetch('/newaccount/getAccounts') -def how_long_ago(last_epoch): +def howLongAgo(last_epoch): a = last_epoch b = time.time() c = b - a @@ -322,8 +322,8 @@ def how_long_ago(last_epoch): hours = c // 3600 % 24 minutes = c // 60 % 60 - if minutes < 60: - return str(round(minutes)) + ' minutes' - if hours < 24: + if days > 0: + return str(round(days)) + ' days' + if hours > 0: return str(round(hours)) + ' hours' - return str(round(days)) + ' days' + return str(round(minutes)) + ' minutes'