From 785cd4f49b07e9a9d4a41ff0307ff89027ee3348 Mon Sep 17 00:00:00 2001 From: attila Date: Sat, 10 Dec 2022 16:49:16 +0100 Subject: [PATCH] Add support for routeid filtering --- README.md | 7 ++++++- custom_components/bkk_stop/manifest.json | 2 +- custom_components/bkk_stop/sensor.py | 12 +++++++++--- info.md | 9 +++++++-- 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 6555991..ee2d71b 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,8 @@ Define sensors with the following configuration parameters:
| bikes | **Y** | `false` | Display whether bikes are allowed on vehicle | | colors | **Y** | `false` | Display BKK's default color for the line and the text | | ignoreNow | **Y** | `true` | Ignore vehicles already in the station | -| entity_id | **Y** | - | Used instead of name for automatic generation of entity_id | +| entity_id | **Y** | `` | Used instead of name for automatic generation of entity_id | +| routes | **Y** | `` | List of routes to consider. Those not listed will be discarded | --- #### Example @@ -42,6 +43,10 @@ name: 'bkk7u' stopId: 'BKK_F00940' minsAfter: 25 wheelchair: true +routes: + - 287 + - 114 + - 213 ``` #### Lovelace UI diff --git a/custom_components/bkk_stop/manifest.json b/custom_components/bkk_stop/manifest.json index 2c3f533..90ce34c 100644 --- a/custom_components/bkk_stop/manifest.json +++ b/custom_components/bkk_stop/manifest.json @@ -7,5 +7,5 @@ "codeowners": ["@amaximus"], "iot_class": "cloud_polling", "requirements": [], - "version": "2.3.0" + "version": "2.4.0" } diff --git a/custom_components/bkk_stop/sensor.py b/custom_components/bkk_stop/sensor.py index 185a1e5..b931418 100644 --- a/custom_components/bkk_stop/sensor.py +++ b/custom_components/bkk_stop/sensor.py @@ -24,6 +24,7 @@ CONF_MAXITEMS = 'maxItems' CONF_STOPID = 'stopId' CONF_WHEELCHAIR = 'wheelchair' +CONF_ROUTES = 'routes' DEFAULT_NAME = 'Budapest GO' DEFAULT_ICON = 'mdi:bus' @@ -39,6 +40,7 @@ vol.Optional(CONF_COLORS, default=False): cv.boolean, vol.Optional(CONF_IGNORENOW, default='true'): cv.boolean, vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string, + vol.Optional(CONF_ROUTES, default=''): vol.All(cv.ensure_list, [cv.string]), vol.Optional(ATTR_ENTITY_ID, default=''): cv.string, }) @@ -54,13 +56,14 @@ def async_setup_platform(hass, config, async_add_devices, discovery_info=None): bikes = config.get(CONF_BIKES) colors = config.get(CONF_COLORS) ignorenow = config.get(CONF_IGNORENOW) + routes = config.get(CONF_ROUTES) async_add_devices( - [BKKPublicTransportSensor(hass, name, entityid, stopid, minsafter, wheelchair, bikes, colors, ignorenow, maxitems)],update_before_add=True) + [BKKPublicTransportSensor(hass, name, entityid, stopid, minsafter, wheelchair, bikes, colors, ignorenow, maxitems, routes)],update_before_add=True) class BKKPublicTransportSensor(Entity): - def __init__(self, hass, name, entityid, stopid, minsafter, wheelchair, bikes, colors, ignorenow, maxitems): + def __init__(self, hass, name, entityid, stopid, minsafter, wheelchair, bikes, colors, ignorenow, maxitems, routes): """Initialize the sensor.""" self._name = name self._hass = hass @@ -71,6 +74,7 @@ def __init__(self, hass, name, entityid, stopid, minsafter, wheelchair, bikes, c self._bikes = bikes self._colors = colors self._ignorenow = ignorenow + self._routes = routes self._state = None self._bkkdata = {} self._icon = DEFAULT_ICON @@ -113,6 +117,8 @@ def extra_state_attributes(self): stopdata["in"] = str(diff) stopdata["type"] = bkkdata["data"]["references"]["routes"][routeid]["type"] stopdata["routeid"] = bkkdata["data"]["references"]["routes"][routeid]["iconDisplayText"] + if stopdata["routeid"] not in self._routes: + continue stopdata["headsign"] = stopTime.get("stopHeadsign","?") stopdata["attime"] = datetime.fromtimestamp(attime).strftime('%H:%M') if predicted_attime: @@ -169,4 +175,4 @@ def state(self): @property def unique_id(self) -> str: - return self.entity_id \ No newline at end of file + return self.entity_id diff --git a/info.md b/info.md index 88ac86d..ee2d71b 100644 --- a/info.md +++ b/info.md @@ -25,14 +25,15 @@ Define sensors with the following configuration parameters:
| Name | Optional | `Default` | Description | | :---- | :---- | :------- | :----------- | | name | **N** | - | sensor of bkk_stop type to display | -| stopId | **N** | - | StopId as per [futar.bkk.hu](http://futar.bkk.hu) | +| stopId | **N** | - | StopId as per [go.bkk.hu](https://go.bkk.hu/) | | maxItems | **Y** | `0` | Number of items to consider. 0 disables this feature | | minsAfter | **Y** | `20` | Number of minutes ahead to show vehicles departing from station | | wheelchair | **Y** | `false` | Display vehicle's wheelchair accessibility | | bikes | **Y** | `false` | Display whether bikes are allowed on vehicle | | colors | **Y** | `false` | Display BKK's default color for the line and the text | | ignoreNow | **Y** | `true` | Ignore vehicles already in the station | -| entity_id | **Y** | - | Used instead of name for automatic generation of entity_id | +| entity_id | **Y** | `` | Used instead of name for automatic generation of entity_id | +| routes | **Y** | `` | List of routes to consider. Those not listed will be discarded | --- #### Example @@ -42,6 +43,10 @@ name: 'bkk7u' stopId: 'BKK_F00940' minsAfter: 25 wheelchair: true +routes: + - 287 + - 114 + - 213 ``` #### Lovelace UI