Skip to content

Commit

Permalink
Add support for routeid filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
amaximus committed Dec 10, 2022
1 parent 091673e commit 785cd4f
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ Define sensors with the following configuration parameters:<br />
| 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
Expand All @@ -42,6 +43,10 @@ name: 'bkk7u'
stopId: 'BKK_F00940'
minsAfter: 25
wheelchair: true
routes:
- 287
- 114
- 213
```

#### Lovelace UI
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.3.0"
"version": "2.4.0"
}
12 changes: 9 additions & 3 deletions custom_components/bkk_stop/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
CONF_MAXITEMS = 'maxItems'
CONF_STOPID = 'stopId'
CONF_WHEELCHAIR = 'wheelchair'
CONF_ROUTES = 'routes'

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

Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -169,4 +175,4 @@ def state(self):

@property
def unique_id(self) -> str:
return self.entity_id
return self.entity_id
9 changes: 7 additions & 2 deletions info.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@ Define sensors with the following configuration parameters:<br />
| 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
Expand All @@ -42,6 +43,10 @@ name: 'bkk7u'
stopId: 'BKK_F00940'
minsAfter: 25
wheelchair: true
routes:
- 287
- 114
- 213
```

#### Lovelace UI
Expand Down

0 comments on commit 785cd4f

Please sign in to comment.