Skip to content

Commit

Permalink
HA 2022.3 compatibility: relax dependency requirements.
Browse files Browse the repository at this point in the history
Due to stricter dependency handling, dependencies can easily conflict if pinned
to a specific version.  Github workflows previously warned if they were not
pinned, but the problems caused by the dependency handling are more severe.
  • Loading branch information
make-all committed Mar 10, 2022
1 parent 175582c commit 5599c02
Show file tree
Hide file tree
Showing 9 changed files with 293 additions and 293 deletions.
34 changes: 17 additions & 17 deletions .github/workflows/hacs-validate.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
name: Validate with HACS

on:
push:
pull_request:
schedule:
- cron: '54 0 * * THU'

jobs:
validate:
runs-on: 'ubuntu-latest'
steps:
- uses: 'actions/checkout@v2'
- name: HACS validation
uses: 'hacs/action@main'
with:
category: 'integration'
name: Validate with HACS

on:
push:
pull_request:
schedule:
- cron: '54 0 * * THU'

jobs:
validate:
runs-on: 'ubuntu-latest'
steps:
- uses: 'actions/checkout@v2'
- name: HACS validation
uses: 'hacs/action@main'
with:
category: 'integration'
126 changes: 63 additions & 63 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,63 +1,63 @@
# Metlink Wellington Transport for Home Assistant

This is a custom component for Home Assistant which uses
the [Metlink opendata API](https://opendata.metlink.org.nz/) to obtain
realtime departure info for Greater Wellington public transport, which can
then be displayed on your Home Assistant dashboard or used in automations.


## Installation

[![hacs_badge](https://img.shields.io/badge/HACS-Default-orange.svg?style=for-the-badge)](https://github.com/custom-components/hacs)

The integration can be installed using HACS.
If you prefer to instal manually, copy `custom_components/metlink` to your
installation's `config/custom_components` directory.

### Configuration

After installing the custom component, you still need to configure it before
it will do anything.

The integration can be added from the Integrations configuration screen.

API keys can be obtained by registering on the
[Metlink Developer Portal](https://opendata.metlink.org.nz/). Be sure to subscribe to the "Metlink Open Data API". Currently this is the only API they offer, and is free, but is still unsubscribed by default.

If you prefer to configure using yaml instead of the UI, add something like
the following to your `config/configuration.yaml`:

```
sensor:
- platform: metlink
api_key: abcdefg1234xzy
stops:
- stop_id: 9999
- stop_id: WELL
route: HVL
- stop_id: 5016
destination: 3451
num_departures: 3
```


`stop_id` for Train and Cable Car stops is a 4 character alphabetic
code, and for bus and ferry stops, is a 4 digit numeric code.
The IDs are on bus stop signs, or can be looked up on the
[Metlink](https://metlink.org.nz) main web site.


If your stop is busy with multiple routes, you can filter by route and/or destination. Currently exact matches are expected and only a single route or destination can be specified, though the destination does check the name as well as the stop id for a match, though some of the names that come through the API are abbreviated in ways that do not match the main web site so stop id will be more reliable. The destination filter is only available on the final destination, not any intermediate stops.


Each stop will create a sensor in Home Assistant, which will return the next departure time as its status.

It will also return attributes for departure time, service, service
name, destination name, stop id for the destination, and status. The
duplication of departure time in the attributes makes more sense when
there is more than one result being returned.

If more than 1 result is requested in `num_departures`, the attributes
will be suffixed with a number for second and subsequent departures.

[![BuyMeCoffee](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://www.buymeacoffee.com/jasonrumney)
# Metlink Wellington Transport for Home Assistant

This is a custom component for Home Assistant which uses
the [Metlink opendata API](https://opendata.metlink.org.nz/) to obtain
realtime departure info for Greater Wellington public transport, which can
then be displayed on your Home Assistant dashboard or used in automations.


## Installation

[![hacs_badge](https://img.shields.io/badge/HACS-Default-orange.svg?style=for-the-badge)](https://github.com/custom-components/hacs)

The integration can be installed using HACS.
If you prefer to instal manually, copy `custom_components/metlink` to your
installation's `config/custom_components` directory.

### Configuration

After installing the custom component, you still need to configure it before
it will do anything.

The integration can be added from the Integrations configuration screen.

API keys can be obtained by registering on the
[Metlink Developer Portal](https://opendata.metlink.org.nz/). Be sure to subscribe to the "Metlink Open Data API". Currently this is the only API they offer, and is free, but is still unsubscribed by default.

If you prefer to configure using yaml instead of the UI, add something like
the following to your `config/configuration.yaml`:

```
sensor:
- platform: metlink
api_key: abcdefg1234xzy
stops:
- stop_id: 9999
- stop_id: WELL
route: HVL
- stop_id: 5016
destination: 3451
num_departures: 3
```


`stop_id` for Train and Cable Car stops is a 4 character alphabetic
code, and for bus and ferry stops, is a 4 digit numeric code.
The IDs are on bus stop signs, or can be looked up on the
[Metlink](https://metlink.org.nz) main web site.


If your stop is busy with multiple routes, you can filter by route and/or destination. Currently exact matches are expected and only a single route or destination can be specified, though the destination does check the name as well as the stop id for a match, though some of the names that come through the API are abbreviated in ways that do not match the main web site so stop id will be more reliable. The destination filter is only available on the final destination, not any intermediate stops.


Each stop will create a sensor in Home Assistant, which will return the next departure time as its status.

It will also return attributes for departure time, service, service
name, destination name, stop id for the destination, and status. The
duplication of departure time in the attributes makes more sense when
there is more than one result being returned.

If more than 1 result is requested in `num_departures`, the attributes
will be suffixed with a number for second and subsequent departures.

[![BuyMeCoffee](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://www.buymeacoffee.com/jasonrumney)
130 changes: 65 additions & 65 deletions custom_components/metlink/__init__.py
Original file line number Diff line number Diff line change
@@ -1,65 +1,65 @@
"""Metlink Wellington Transport integration."""
import asyncio
import logging

from homeassistant import config_entries, core

from .const import DOMAIN

_LOGGER = logging.getLogger(__name__)


async def async_setup_entry(
hass: core.HomeAssistant, entry: config_entries.ConfigEntry
) -> bool:
"""Set up platform from a ConfigEntry."""
hass.data.setdefault(DOMAIN, {})
data = {**entry.data, **entry.options}
# Register an update listener to refresh when options are updated.
update_listener = entry.add_update_listener(options_update_listener)
data["unsub_options_update_listener"] = update_listener
hass.data[DOMAIN][entry.entry_id] = data

# Forward the setup to the sensor platform.
_LOGGER.debug(f"Setting up based on {entry.data}")
hass.async_create_task(
hass.config_entries.async_forward_entry_setup(entry, "sensor")
)
return True


async def options_update_listener(
hass: core.HomeAssistant, config_entry: config_entries.ConfigEntry
):
"""Handle options update."""
_LOGGER.debug("Reloading config after options update")
await hass.config_entries.async_reload(config_entry.entry_id)


async def async_unload_entry(
hass: core.HomeAssistant, entry: config_entries.ConfigEntry
) -> bool:
"""Unload a config entry."""
_LOGGER.debug("Unloading")
unload_ok = all(
await asyncio.gather(
*[hass.config_entries.async_forward_entry_unload(entry, "sensor")]
)
)
# Remove the listener
hass.data[DOMAIN][entry.entry_id]["unsub_options_update_listener"]()

# Remove from domain
if unload_ok:
hass.data[DOMAIN].pop(entry.entry_id)
else:
_LOGGER.warning("Unload failed")

return unload_ok


async def async_setup(hass: core.HomeAssistant, config: dict) -> bool:
"""Setup the Metlink component from yaml configuration."""
_LOGGER.debug("Setting up from YAML config")
hass.data.setdefault(DOMAIN, {})
return True
"""Metlink Wellington Transport integration."""
import asyncio
import logging

from homeassistant import config_entries, core

from .const import DOMAIN

_LOGGER = logging.getLogger(__name__)


async def async_setup_entry(
hass: core.HomeAssistant, entry: config_entries.ConfigEntry
) -> bool:
"""Set up platform from a ConfigEntry."""
hass.data.setdefault(DOMAIN, {})
data = {**entry.data, **entry.options}
# Register an update listener to refresh when options are updated.
update_listener = entry.add_update_listener(options_update_listener)
data["unsub_options_update_listener"] = update_listener
hass.data[DOMAIN][entry.entry_id] = data

# Forward the setup to the sensor platform.
_LOGGER.debug(f"Setting up based on {entry.data}")
hass.async_create_task(
hass.config_entries.async_forward_entry_setup(entry, "sensor")
)
return True


async def options_update_listener(
hass: core.HomeAssistant, config_entry: config_entries.ConfigEntry
):
"""Handle options update."""
_LOGGER.debug("Reloading config after options update")
await hass.config_entries.async_reload(config_entry.entry_id)


async def async_unload_entry(
hass: core.HomeAssistant, entry: config_entries.ConfigEntry
) -> bool:
"""Unload a config entry."""
_LOGGER.debug("Unloading")
unload_ok = all(
await asyncio.gather(
*[hass.config_entries.async_forward_entry_unload(entry, "sensor")]
)
)
# Remove the listener
hass.data[DOMAIN][entry.entry_id]["unsub_options_update_listener"]()

# Remove from domain
if unload_ok:
hass.data[DOMAIN].pop(entry.entry_id)
else:
_LOGGER.warning("Unload failed")

return unload_ok


async def async_setup(hass: core.HomeAssistant, config: dict) -> bool:
"""Setup the Metlink component from yaml configuration."""
_LOGGER.debug("Setting up from YAML config")
hass.data.setdefault(DOMAIN, {})
return True
90 changes: 45 additions & 45 deletions custom_components/metlink/const.py
Original file line number Diff line number Diff line change
@@ -1,45 +1,45 @@
# Copyright 2021 Jason Rumney
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

DOMAIN = "metlink"
ATTRIBUTION = "Data provided by Greater Wellington Regional Council"

CONF_STOPS = "stops"
CONF_STOP_ID = "stop_id"
CONF_DEST = "destination"
CONF_ROUTE = "route"
CONF_NUM_DEPARTURES = "num_departures"

ATTR_ACCESSIBLE = "wheelchair_accessible"
ATTR_AIMED = "aimed"
ATTR_ARRIVAL = "arrival"
ATTR_CLOSED = "closed"
ATTR_DELAY = "delay"
ATTR_DEPARTURE = "departure"
ATTR_DEPARTURES = "departures"
ATTR_DESCRIPTION = "description"
ATTR_DESTINATION = "destination"
ATTR_DESTINATION_ID = "destination_id"
ATTR_DIRECTION = "direction"
ATTR_EXPECTED = "expected"
ATTR_FAREZONE = "farezone"
ATTR_MONITORED = "monitored"
ATTR_NAME = "name"
ATTR_OPERATOR = "operator"
ATTR_ORIGIN = "origin"
ATTR_SERVICE = "service_id"
ATTR_STATUS = "status"
ATTR_STOP = "stop_id"
ATTR_STOP_NAME = "stop_name"
ATTR_VEHICLE = "vehicle_id"
# Copyright 2021 Jason Rumney
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

DOMAIN = "metlink"
ATTRIBUTION = "Data provided by Greater Wellington Regional Council"

CONF_STOPS = "stops"
CONF_STOP_ID = "stop_id"
CONF_DEST = "destination"
CONF_ROUTE = "route"
CONF_NUM_DEPARTURES = "num_departures"

ATTR_ACCESSIBLE = "wheelchair_accessible"
ATTR_AIMED = "aimed"
ATTR_ARRIVAL = "arrival"
ATTR_CLOSED = "closed"
ATTR_DELAY = "delay"
ATTR_DEPARTURE = "departure"
ATTR_DEPARTURES = "departures"
ATTR_DESCRIPTION = "description"
ATTR_DESTINATION = "destination"
ATTR_DESTINATION_ID = "destination_id"
ATTR_DIRECTION = "direction"
ATTR_EXPECTED = "expected"
ATTR_FAREZONE = "farezone"
ATTR_MONITORED = "monitored"
ATTR_NAME = "name"
ATTR_OPERATOR = "operator"
ATTR_ORIGIN = "origin"
ATTR_SERVICE = "service_id"
ATTR_STATUS = "status"
ATTR_STOP = "stop_id"
ATTR_STOP_NAME = "stop_name"
ATTR_VEHICLE = "vehicle_id"
Loading

0 comments on commit 5599c02

Please sign in to comment.