Skip to content

Commit

Permalink
Add minsWalking parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
amaximus committed Nov 2, 2023
1 parent 9b1edac commit 783ddc4
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Define sensors with the following configuration parameters:<br />
| 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
Expand Down
2 changes: 1 addition & 1 deletion custom_components/bkk_stop/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
"codeowners": ["@amaximus"],
"iot_class": "cloud_polling",
"requirements": [],
"version": "2.8.0"
"version": "2.9.0"
}
10 changes: 8 additions & 2 deletions custom_components/bkk_stop/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
CONF_MAXITEMS = 'maxItems'
CONF_ROUTES = 'routes'
CONF_STOPID = 'stopId'
CONF_MINSWALKING = 'minsWalking'
CONF_WHEELCHAIR = 'wheelchair'

DEFAULT_NAME = 'Budapest GO'
Expand All @@ -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,
})

Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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"]
Expand Down
1 change: 1 addition & 0 deletions info.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Define sensors with the following configuration parameters:<br />
| 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
Expand Down

0 comments on commit 783ddc4

Please sign in to comment.