From 87b13ee732a8451526eae28a6a0d222e190866e5 Mon Sep 17 00:00:00 2001 From: Peter Nijssen Date: Sat, 16 Nov 2019 10:37:58 +0100 Subject: [PATCH] Fix broken postnl sensor (#28794) * fix broken postnl sensor * make sure shipment list is not growing indefinitely --- homeassistant/components/postnl/manifest.json | 2 +- homeassistant/components/postnl/sensor.py | 11 ++++++++--- requirements_all.txt | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/postnl/manifest.json b/homeassistant/components/postnl/manifest.json index d07f9746ee8..c45eea0610d 100644 --- a/homeassistant/components/postnl/manifest.json +++ b/homeassistant/components/postnl/manifest.json @@ -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": [] diff --git a/homeassistant/components/postnl/sensor.py b/homeassistant/components/postnl/sensor.py index cd190c09d87..6155f58519a 100644 --- a/homeassistant/components/postnl/sensor.py +++ b/homeassistant/components/postnl/sensor.py @@ -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) diff --git a/requirements_all.txt b/requirements_all.txt index 4e95af20556..ac41e7b1e46 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -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