Skip to content
This repository has been archived by the owner on Jan 23, 2025. It is now read-only.

Update sensor.py #28

Merged
merged 1 commit into from
Dec 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions custom_components/deutschebahn/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,12 @@ def extra_state_attributes(self):
"""Return the state attributes."""
if len(self.connections) > 0:
connections = self.connections[0].copy()
if len(self.connections) > 1:
connections["next"] = self.connections[1]["departure"]
connections["next_delay"] = self.connections[1]["delay"]
connections["next_canceled"] = self.connections[1]["canceled"]
if len(self.connections) > 2:
connections["next_on"] = self.connections[2]["departure"]
connections["next_on_delay"] = self.connections[2]["delay"]
connections["next_on_canceled"] = self.connections[2]["canceled"]
for cons in range(1,len(self.connections)):
if len(self.connections) > cons:
connections[f"next_{cons}"] = self.connections[cons]["departure"]
connections[f"next_{cons}_delay"] = self.connections[cons]["delay"]
connections[f"next_{cons}_canceled"] = self.connections[cons]["canceled"]
connections[f"next_{cons}_arrival"] = self.connections[cons]["arrival"]
else:
connections = None
connections["departures"] = self.connections
Expand Down