From 783ddc4975fb194e18cca33147e5b5191e084b68 Mon Sep 17 00:00:00 2001 From: attila Date: Thu, 2 Nov 2023 15:33:58 +0100 Subject: [PATCH] Add minsWalking parameter --- README.md | 1 + custom_components/bkk_stop/manifest.json | 2 +- custom_components/bkk_stop/sensor.py | 10 ++++++++-- info.md | 1 + 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 36e741d..2c9cbf4 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,7 @@ Define sensors with the following configuration parameters:
| inPredicted | **Y** | `false` | Calculate time in as per estimated arrival time, when available | | routes | **Y** | `` | List of routes to consider. Those not listed will be discarded | | headsigns | **Y** | `` | List of headsigns to consider. Those not listed will be discarded. Useful for trans stations | +| minsWalking | **Y** | `0` | Skip vehicles departing from station while walking to the station | --- On begining of June the test API key has been revoked, therefore to use this integration you'll have to create an account diff --git a/custom_components/bkk_stop/manifest.json b/custom_components/bkk_stop/manifest.json index 87d9fda..a1b5df7 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.8.0" + "version": "2.9.0" } diff --git a/custom_components/bkk_stop/sensor.py b/custom_components/bkk_stop/sensor.py index 9423b8a..6a5e86c 100644 --- a/custom_components/bkk_stop/sensor.py +++ b/custom_components/bkk_stop/sensor.py @@ -26,6 +26,7 @@ CONF_MAXITEMS = 'maxItems' CONF_ROUTES = 'routes' CONF_STOPID = 'stopId' +CONF_MINSWALKING = 'minsWalking' CONF_WHEELCHAIR = 'wheelchair' DEFAULT_NAME = 'Budapest GO' @@ -46,6 +47,7 @@ vol.Optional(CONF_MINSAFTER, default=20): cv.string, vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string, vol.Optional(CONF_ROUTES, default=[]): vol.All(cv.ensure_list, [cv.string]), + vol.Optional(CONF_MINSWALKING, default=0): cv.string, vol.Optional(CONF_WHEELCHAIR, default=False): cv.boolean, }) @@ -63,14 +65,15 @@ async def async_setup_platform(hass, config, async_add_devices, discovery_info=N routes = config.get(CONF_ROUTES) headsigns = config.get(CONF_HEADSIGNS) inpredicted = config.get(CONF_INPREDICTED) + minswalking = config.get(CONF_MINSWALKING) apikey = config.get(CONF_APIKEY) async_add_devices( - [BKKPublicTransportSensor(hass, name, entityid, stopid, minsafter, wheelchair, bikes, colors, ignorenow, maxitems, routes, inpredicted, apikey, headsigns)],update_before_add=True) + [BKKPublicTransportSensor(hass, name, entityid, stopid, minsafter, wheelchair, bikes, colors, ignorenow, maxitems, routes, inpredicted, apikey, headsigns, minswalking)],update_before_add=True) class BKKPublicTransportSensor(Entity): - def __init__(self, hass, name, entityid, stopid, minsafter, wheelchair, bikes, colors, ignorenow, maxitems, routes, inpredicted, apikey, headsigns): + def __init__(self, hass, name, entityid, stopid, minsafter, wheelchair, bikes, colors, ignorenow, maxitems, routes, inpredicted, apikey, headsigns, minswalking): """Initialize the sensor.""" self._name = name self._hass = hass @@ -85,6 +88,7 @@ def __init__(self, hass, name, entityid, stopid, minsafter, wheelchair, bikes, c self._apikey = apikey self._routes = routes self._headsigns = headsigns + self._minswalking = minswalking self._state = None self._bkkdata = {} self._icon = DEFAULT_ICON @@ -120,6 +124,8 @@ def extra_state_attributes(self): diff = 0 if self._ignorenow and diff == 0: continue + if diff < int(self._minswalking): + continue tripid = stopTime.get("tripId") routeid = bkkdata["data"]["references"]["trips"][tripid]["routeId"] diff --git a/info.md b/info.md index 36e741d..2c9cbf4 100644 --- a/info.md +++ b/info.md @@ -37,6 +37,7 @@ Define sensors with the following configuration parameters:
| inPredicted | **Y** | `false` | Calculate time in as per estimated arrival time, when available | | routes | **Y** | `` | List of routes to consider. Those not listed will be discarded | | headsigns | **Y** | `` | List of headsigns to consider. Those not listed will be discarded. Useful for trans stations | +| minsWalking | **Y** | `0` | Skip vehicles departing from station while walking to the station | --- On begining of June the test API key has been revoked, therefore to use this integration you'll have to create an account