FaserF / ha-deutschebahn

Unofficial HA DB Integration, due to removal as of Home Assistant 2022.11
Apache License 2.0
40 stars 7 forks source link

[Feature Request]: information on next and next_on trains #16

Closed M-See closed 7 months ago

M-See commented 1 year ago

The request

I just wanted to know whether it´s already possible or can easily be implemented that one gets the same information for the next and next next trains as for the real next train.

Same issue as here:

https://community.home-assistant.io/t/extension-of-deutsche-bahn-sensor/349958

Is that possible?

Is your feature request related to a problem?

No response

Additional information

No response

M-See commented 1 year ago

Just too easy!

Fixed it by adding the parameters for the next and next next trains in sensor.py here:

@property
    def extra_state_attributes(self):
        """Return the state attributes."""
        if len(self.connections) > 0:
            connections = self.connections[0]
            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"]

Thank you very much for the general scripts :)!

M-See commented 7 months ago

In Version 2.1.0, this doesn´t seem to work anymore, so i downgraded again and added the lines to the original code again, to make it work.

For Version 2.0.4 the following result was obtained by adding the lines above: 123

In version 2.1.0, the attributes of the last line were completely undefined, but I have not yet found out which commits this refers to, as with a previous version it seems to work properly

M-See commented 7 months ago

Ah.. solved by setting the max. number of connections to 3 from the UI of the 2.1.0 version.

Thanks for the additonal features :)!