Skip to content

Commit

Permalink
fix accumulation of data
Browse files Browse the repository at this point in the history
  • Loading branch information
iantrich committed Jan 12, 2019
1 parent 8ab1175 commit 6ace05c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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)](#)

Expand Down
16 changes: 8 additions & 8 deletions custom_components/sensor/personalcapital.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']

Expand Down Expand Up @@ -248,14 +248,14 @@ 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."""
self._rest.update()
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', '') == '':
Expand All @@ -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
Expand Down Expand Up @@ -314,16 +314,16 @@ 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
days = c // 86400
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'

0 comments on commit 6ace05c

Please sign in to comment.