From 9bb8b2bc0023d59178c0627f6af09bfc3d7024f1 Mon Sep 17 00:00:00 2001 From: Yarmo Mackenbach Date: Mon, 3 Feb 2020 13:39:45 +0000 Subject: [PATCH] Update NSAPI to 3.0.2 (#30971) * Bump NSAPI version to 3.0.1 * Compatibility with NSAPI 3.0.1 response * Removed commented code * Obsolete setups receive an upgrade notification * Bump NS-API to 3.0.2 * Assign platform values directly * Removed obsolete config warning * Improved reference to obsolete password --- .../nederlandse_spoorwegen/manifest.json | 2 +- .../nederlandse_spoorwegen/sensor.py | 55 ++++++++++++------- requirements_all.txt | 2 +- 3 files changed, 38 insertions(+), 21 deletions(-) diff --git a/homeassistant/components/nederlandse_spoorwegen/manifest.json b/homeassistant/components/nederlandse_spoorwegen/manifest.json index 92231bd460c..8718843d73d 100644 --- a/homeassistant/components/nederlandse_spoorwegen/manifest.json +++ b/homeassistant/components/nederlandse_spoorwegen/manifest.json @@ -2,7 +2,7 @@ "domain": "nederlandse_spoorwegen", "name": "Nederlandse Spoorwegen (NS)", "documentation": "https://www.home-assistant.io/integrations/nederlandse_spoorwegen", - "requirements": ["nsapi==3.0.0"], + "requirements": ["nsapi==3.0.2"], "dependencies": [], "codeowners": ["@YarmoM"] } diff --git a/homeassistant/components/nederlandse_spoorwegen/sensor.py b/homeassistant/components/nederlandse_spoorwegen/sensor.py index 5477aaf0e2b..df37fad2aa3 100644 --- a/homeassistant/components/nederlandse_spoorwegen/sensor.py +++ b/homeassistant/components/nederlandse_spoorwegen/sensor.py @@ -51,7 +51,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None): requests.exceptions.ConnectionError, requests.exceptions.HTTPError, ) as error: - _LOGGER.error("Couldn't fetch stations, API password correct?: %s", error) + _LOGGER.error("Couldn't fetch stations, API key correct?: %s", error) return sensors = [] @@ -127,20 +127,16 @@ class NSDepartureSensor(Entity): # Static attributes attributes = { "going": self._trips[0].going, - "departure_time_planned": self._trips[0].departure_time_planned.strftime( - "%H:%M" - ), + "departure_time_planned": None, "departure_time_actual": None, "departure_delay": False, "departure_platform_planned": self._trips[0].departure_platform_planned, - "departure_platform_actual": None, - "arrival_time_planned": self._trips[0].arrival_time_planned.strftime( - "%H:%M" - ), + "departure_platform_actual": self._trips[0].departure_platform_actual, + "arrival_time_planned": None, "arrival_time_actual": None, "arrival_delay": False, - "arrival_platform_platform": self._trips[0].arrival_platform_planned, - "arrival_platform_actual": None, + "arrival_platform_planned": self._trips[0].arrival_platform_planned, + "arrival_platform_actual": self._trips[0].arrival_platform_actual, "next": None, "status": self._trips[0].status.lower(), "transfers": self._trips[0].nr_transfers, @@ -149,25 +145,46 @@ class NSDepartureSensor(Entity): ATTR_ATTRIBUTION: ATTRIBUTION, } - # Departure attributes + # Planned departure attributes + if self._trips[0].departure_time_planned is not None: + attributes["departure_time_planned"] = self._trips[ + 0 + ].departure_time_planned.strftime("%H:%M") + + # Actual departure attributes if self._trips[0].departure_time_actual is not None: attributes["departure_time_actual"] = self._trips[ 0 ].departure_time_actual.strftime("%H:%M") - attributes["departure_delay"] = True - attributes["departure_platform_actual"] = self._trips[ - 0 - ].departure_platform_actual - # Arrival attributes + # Delay departure attributes + if ( + attributes["departure_time_planned"] + and attributes["departure_time_actual"] + and attributes["departure_time_planned"] + != attributes["departure_time_actual"] + ): + attributes["departure_delay"] = True + + # Planned arrival attributes + if self._trips[0].arrival_time_planned is not None: + attributes["arrival_time_planned"] = self._trips[ + 0 + ].arrival_time_planned.strftime("%H:%M") + + # Actual arrival attributes if self._trips[0].arrival_time_actual is not None: attributes["arrival_time_actual"] = self._trips[ 0 ].arrival_time_actual.strftime("%H:%M") + + # Delay arrival attributes + if ( + attributes["arrival_time_planned"] + and attributes["arrival_time_actual"] + and attributes["arrival_time_planned"] != attributes["arrival_time_actual"] + ): attributes["arrival_delay"] = True - attributes["arrival_platform_actual"] = self._trips[ - 0 - ].arrival_platform_actual # Next attributes if self._trips[1].departure_time_actual is not None: diff --git a/requirements_all.txt b/requirements_all.txt index fec294f1fc5..a494fc645f4 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -905,7 +905,7 @@ niko-home-control==0.2.1 niluclient==0.1.2 # homeassistant.components.nederlandse_spoorwegen -nsapi==3.0.0 +nsapi==3.0.2 # homeassistant.components.nsw_fuel_station nsw-fuel-api-client==1.0.10