Closed snis closed 2 years ago
Can confirm this; due to holiday I cannot fix until mid august but will prioritize if no-one else have the time. =)
I'm guessing I'll have to wait, no programmer. looked in sensor.py, but it's way over my "GOTO 10" knowledge. Made a quick unclutering fix (on my local install) in lsapi/const.py by appending '&bus=false' to the ri4 api call.
Is the filtering done locally on data arrival, or in the query? Would make sense to filter locally cached results, e.g. in status-card.js
RP3 has lines and not lineNumber. Only SI2 has lineNumber in the query. All the other endpoints must filter on results.
Another point: I cannot actually delete the only line from the lines field when only one is there. Every time I go back, it's still there. e.g. lines: 17 delete 17 save go back, 17 is still there.
I ran into the same issues and looked into a solution, I have not tested this in the integration but rather mocked out the minimal amount of data needed to add filtering. The solution is based on the assumption that the departures
attribute in HASLDepartureSensor
returned here (line 465) is a list of dictionaries on the form:
{'departure': '13 min',
'destination': 'Fruängen',
'direction': 1,
'expected': '2021-09-05T12:18:02',
'groupofline': '',
'icon': 'mdi:bus',
'line': '704',
'time': 13,
'type': 'Buses'}
The solution I've made adds two filter functions which use CONF_DIRECTION
(assumed to be one of 0
, 1
, 2
) and CONF_LINES
(assumed to be a list of strings like ['704', ...]
).
The filter functions to add are very simple:
def direction_filter(departure):
if direction == 0:
return True # Include, we don't filter on direction
return departure["direction"] == direction
def line_filter(departure):
if lines == []:
return True # Include, we don't filter on lines
return departure["line"] in lines
All that remains is then to apply the filters to the data which can be done around here (lines 459-462) like this:
departures = self._sensordata["data"]
direction_filtered = departures if direction == 0 else list(filter(direction_filter, departures]))
lines_filtered = direction_filtered if lines == [] else list(filter(line_filter, direction_filtered))
val['departures'] = lines_filtered # Replace current assignment with this one
Trying to filter lines and direction and it doesn't seem to work. I get all lines from site/location and all directions.