Skip to content

Commit 5dc509c

Browse files
authored
Add typing to Nederlandse Spoorwegen (home-assistant#152367)
1 parent 75597ac commit 5dc509c

File tree

1 file changed

+20
-8
lines changed
  • homeassistant/components/nederlandse_spoorwegen

1 file changed

+20
-8
lines changed

homeassistant/components/nederlandse_spoorwegen/sensor.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22

33
from __future__ import annotations
44

5+
import datetime as dt
56
from datetime import datetime, timedelta
67
import logging
8+
from typing import Any
79

10+
from ns_api import NSAPI, Trip
811
import requests
912
import voluptuous as vol
1013

@@ -142,31 +145,39 @@ class NSDepartureSensor(SensorEntity):
142145
_attr_attribution = "Data provided by NS"
143146
_attr_icon = "mdi:train"
144147

145-
def __init__(self, nsapi, name, departure, heading, via, time):
148+
def __init__(
149+
self,
150+
nsapi: NSAPI,
151+
name: str,
152+
departure: str,
153+
heading: str,
154+
via: str | None,
155+
time: dt.time | None,
156+
) -> None:
146157
"""Initialize the sensor."""
147158
self._nsapi = nsapi
148159
self._name = name
149160
self._departure = departure
150161
self._via = via
151162
self._heading = heading
152163
self._time = time
153-
self._state = None
154-
self._trips = None
155-
self._first_trip = None
156-
self._next_trip = None
164+
self._state: str | None = None
165+
self._trips: list[Trip] | None = None
166+
self._first_trip: Trip | None = None
167+
self._next_trip: Trip | None = None
157168

158169
@property
159-
def name(self):
170+
def name(self) -> str:
160171
"""Return the name of the sensor."""
161172
return self._name
162173

163174
@property
164-
def native_value(self):
175+
def native_value(self) -> str | None:
165176
"""Return the next departure time."""
166177
return self._state
167178

168179
@property
169-
def extra_state_attributes(self):
180+
def extra_state_attributes(self) -> dict[str, Any] | None:
170181
"""Return the state attributes."""
171182
if not self._trips or self._first_trip is None:
172183
return None
@@ -236,6 +247,7 @@ def extra_state_attributes(self):
236247
):
237248
attributes["arrival_delay"] = True
238249

250+
assert self._next_trip is not None
239251
# Next attributes
240252
if self._next_trip.departure_time_actual is not None:
241253
attributes["next"] = self._next_trip.departure_time_actual.strftime("%H:%M")

0 commit comments

Comments
 (0)