Skip to content

Commit

Permalink
Replace minsWalking with minsBefore using minutesBefore service
Browse files Browse the repository at this point in the history
  • Loading branch information
amaximus committed Nov 3, 2023
1 parent 783ddc4 commit 49c47e7
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +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 |
| minsBefore | **Y** | `0` | Skip vehicles departing from station in `minsBefore` minutes, e.g. 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.9.0"
"version": "2.9.1"
}
16 changes: 7 additions & 9 deletions custom_components/bkk_stop/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
CONF_MAXITEMS = 'maxItems'
CONF_ROUTES = 'routes'
CONF_STOPID = 'stopId'
CONF_MINSWALKING = 'minsWalking'
CONF_MINSBEFORE = 'minsBefore'
CONF_WHEELCHAIR = 'wheelchair'

DEFAULT_NAME = 'Budapest GO'
Expand All @@ -47,7 +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_MINSBEFORE, default=0): cv.string,
vol.Optional(CONF_WHEELCHAIR, default=False): cv.boolean,
})

Expand All @@ -65,15 +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)
minsbefore = config.get(CONF_MINSBEFORE)
apikey = config.get(CONF_APIKEY)

async_add_devices(
[BKKPublicTransportSensor(hass, name, entityid, stopid, minsafter, wheelchair, bikes, colors, ignorenow, maxitems, routes, inpredicted, apikey, headsigns, minswalking)],update_before_add=True)
[BKKPublicTransportSensor(hass, name, entityid, stopid, minsafter, wheelchair, bikes, colors, ignorenow, maxitems, routes, inpredicted, apikey, headsigns, minsbefore)],update_before_add=True)

class BKKPublicTransportSensor(Entity):

def __init__(self, hass, name, entityid, stopid, minsafter, wheelchair, bikes, colors, ignorenow, maxitems, routes, inpredicted, apikey, headsigns, minswalking):
def __init__(self, hass, name, entityid, stopid, minsafter, wheelchair, bikes, colors, ignorenow, maxitems, routes, inpredicted, apikey, headsigns, minsbefore):
"""Initialize the sensor."""
self._name = name
self._hass = hass
Expand All @@ -88,7 +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._minsbefore = minsbefore
self._state = None
self._bkkdata = {}
self._icon = DEFAULT_ICON
Expand Down Expand Up @@ -124,8 +124,6 @@ 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 Expand Up @@ -174,7 +172,7 @@ async def async_update(self):
## headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.3'}
# BKKURL="http://go.bkk.hu/bkk-utvonaltervezo-api/ws/otp/api/where/arrivals-and-departures-for-stop.json?key=apaiary-test&version=3&appVersion=apiary-1.0&onlyDepartures=true&stopId=" + self._stopid + "&minutesAfter=" + self._minsafter
# As of 2019-07-02 upgrade:
BKKURL="https://go.bkk.hu/api/query/v1/ws/otp/api/where/arrivals-and-departures-for-stop.json?key=" + self._apikey + "&version=3&appVersion=apiary-1.0&onlyDepartures=true&stopId=" + self._stopid + "&minutesAfter=" + self._minsafter
BKKURL="https://go.bkk.hu/api/query/v1/ws/otp/api/where/arrivals-and-departures-for-stop.json?key=" + self._apikey + "&version=3&appVersion=apiary-1.0&onlyDepartures=true&stopId=" + self._stopid + "&minutesAfter=" + self._minsafter + "&minutesBefore=-" + self._minsbefore

async with self._session.get(BKKURL) as response:
self._bkkdata = await response.json()
Expand Down
2 changes: 1 addition & 1 deletion info.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +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 |
| minsBefore | **Y** | `0` | Skip vehicles departing from station in `minsBefore` minutes, e.g. 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 49c47e7

Please sign in to comment.