Fix broken postnl sensor (#28794)

* fix broken postnl sensor

* make sure shipment list is not growing indefinitely
This commit is contained in:
Peter Nijssen 2019-11-16 10:37:58 +01:00 committed by Martin Hjelmare
parent afbd966ba6
commit 87b13ee732
3 changed files with 10 additions and 5 deletions

View File

@ -3,7 +3,7 @@
"name": "Postnl",
"documentation": "https://www.home-assistant.io/integrations/postnl",
"requirements": [
"postnl_api==1.0.2"
"postnl_api==1.2.2"
],
"dependencies": [],
"codeowners": []

View File

@ -58,7 +58,7 @@ class PostNLSensor(Entity):
def __init__(self, api, name):
"""Initialize the PostNL sensor."""
self._name = name
self._attributes = {ATTR_ATTRIBUTION: ATTRIBUTION}
self._attributes = {ATTR_ATTRIBUTION: ATTRIBUTION, "shipments": []}
self._state = None
self._api = api
@ -90,6 +90,11 @@ class PostNLSensor(Entity):
@Throttle(MIN_TIME_BETWEEN_UPDATES)
def update(self):
"""Update device state."""
shipments = self._api.get_relevant_shipments()
self._attributes["shipments"] = shipments
shipments = self._api.get_relevant_deliveries()
self._attributes["shipments"] = []
for shipment in shipments:
self._attributes["shipments"].append(vars(shipment))
self._state = len(shipments)

View File

@ -999,7 +999,7 @@ pmsensor==0.4
pocketcasts==0.1
# homeassistant.components.postnl
postnl_api==1.0.2
postnl_api==1.2.2
# homeassistant.components.reddit
praw==6.4.0