Skip to content

Commit

Permalink
Initial upload of deutsche bahn custom integration
Browse files Browse the repository at this point in the history
  • Loading branch information
FaserF committed Sep 8, 2022
1 parent 74400ac commit 1732e04
Show file tree
Hide file tree
Showing 17 changed files with 457 additions and 2 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.github/* @faserf
20 changes: 20 additions & 0 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
## Issues and feature requests

You've found a bug in the source code, a mistake in the documentation or maybe
you'd like a new feature? You can help us by submitting an issue to our
[GitHub Repository][github]. Before you create an issue, make sure you search
the archive, maybe your question was already answered.

Even better: You could submit a pull request with a fix / new feature!

## Pull request process

1. Search our repository for open or closed [pull requests][prs] that relates
to your submission. You don't want to duplicate effort.

1. You may merge the pull request in once you have the sign-off of two other
developers, or if you do not have permission to do that, you may request
the second reviewer to merge it for you.

[github]: https://github.com/faserf/ha-foodsharing/issues
[prs]: https://github.com/faserf/ha-foodsharing/pulls
3 changes: 3 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
github: faserf
custom: https://paypal.me/FaserF
31 changes: 31 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
name: Bug report
about: Report an issue with one of the add-ons in this repository
title: ''
labels: bug
assignees: FaserF

---

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error

**Expected behavior**
A clear and concise description of what you expected to happen.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Version Details**
- Homeassistant Version:
- Foodsharing Integration Version:

**Additional context**
Add any other context about the problem here.
20 changes: 20 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: enhancement
assignees: FaserF

---

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
Add any other context or screenshots about the feature request here.
9 changes: 9 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Proposed Changes

> (Describe the changes and rationale behind them)
## Related Issues

> ([Github link][autolink-references] to related issues or pull requests)
[autolink-references]: https://help.github.com/articles/autolinked-references-and-urls/
72 changes: 72 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL"

on:
push:
branches: [ "main" ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ "main" ]
schedule:
- cron: '44 12 * * 6'

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language: [ 'python' ]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support

steps:
- name: Checkout repository
uses: actions/checkout@v3

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.

# Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality


# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2

# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun

# If the Autobuild fails above, remove it and uncomment the following three lines.
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.

# - run: |
# echo "Run, Build Application using script"
# ./location_of_script_within_repo/buildscript.sh

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
24 changes: 24 additions & 0 deletions .github/workflows/validate-integration.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
name: Cron actions

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
validate:
runs-on: "ubuntu-latest"
name: Validate
steps:
- uses: "actions/checkout@v2"

- name: HACS validation
uses: "hacs/action@main"
with:
category: "integration"
ignore: brands

- name: Hassfest validation
uses: "home-assistant/actions/hassfest@master"
9 changes: 9 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* ------------------------------------------------------------
* "THE BEERWARE LICENSE" (Revision 42):
* The Homeassistant Community wrote this code. As long as you retain this
* notice, you can do whatever you want with this stuff. If we
* meet someday, and you think this stuff is worth it, you can
* buy me a beer in return.
* ------------------------------------------------------------
*/
122 changes: 120 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,120 @@
# ha-deutschebahn
Unofficial HA DB Integration, due to removal as of Home Assistant 2022.11
[![hacs_badge](https://img.shields.io/badge/HACS-Custom-orange.svg)](https://github.com/custom-components/hacs)
# Deutsche Bahn Homeassistant Sensor
The `deutsche_bahn` sensor will give you the departure time of the next train for the given connection. In case of a delay, the delay is also shown. Additional details are used to inform about, e.g., the type of the train, price, and if it is on time.

<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/2/21/Db-bahn.svg/1280px-Db-bahn.svg.png" alt="Deutsche Bahn" width="300px">

<img src="images/sensor.png" alt="Deutsche Bahn Sensor" width="300px">


The official Deutsche Bahn Homeassistant integration got removed with release 2022.11 - therefore this custom integration exists. It got removed due to cloud scraping, but still was fully functional.
I will not give much support on this integration! Use it as it is, this is the same part as of release 2022.09 from HA, see [here](https://github.com/home-assistant/core/tree/c741d9d0452970c39397deca1c65766c8cb917da/homeassistant/components/deutsche_bahn).

Below is the old Homeassistant documentation taken from [here](https://github.com/home-assistant/home-assistant.io/blob/b38ab5e8bc745e8e751eb27c2c079de8a8e83d5e/source/_integrations/deutsche_bahn.markdown).
---
title: Deutsche Bahn
description: Instructions on how to integrate timetable data for traveling in Germany within Home Assistant.
ha_category:
- Transport
ha_iot_class: Cloud Polling
ha_release: 0.14
ha_domain: deutsche_bahn
ha_platforms:
- sensor
ha_integration_type: integration
---

The `deutsche_bahn` sensor will give you the departure time of the next train for the given connection. In case of a delay, the delay is also shown. Additional details are used to inform about, e.g., the type of the train, price, and if it is on time.

To enable this sensor, add the following lines to your `configuration.yaml` file:

```yaml
# Example configuration.yaml entry
sensor:
- platform: deutschebahn
from: NAME_OF_START_STATION
to: NAME_OF_FINAL_STATION
```
{% configuration %}
from:
description: The name of the start station.
required: true
type: string
to:
description: The name of the end/destination station.
required: true
type: string
offset:
description: Do not display departures leaving sooner than this number of seconds. Useful if you are a couple of minutes away from the stop. The formats "HH:MM" and "HH:MM:SS" are also supported.
required: false
type: time
default: 00:00
only_direct:
description: Only show direct connections.
required: false
type: boolean
default: false
{% endconfiguration %}
This sensor stores a lot of attributes which can be accessed by other sensors, e.g., a [template sensor](/integrations/template).
{% raw %}
```yaml
# Example configuration.yaml entry
template:
- sensor:
- name : "Next departure"
state: "{{ state_attr('sensor.munich_to_ulm', 'next') }}"
```
{% endraw %}
The data is coming from the [bahn.de](https://www.bahn.de/p/view/index.shtml) website.
## Installation
### 1. Using HACS (recommended way)
Open your HACS Settings and add
https://github.com/faserf/ha-deutschebahn
as custom repository URL.
Then install the "Deutsche Bahn" integration.
If you use this method, your component will always update to the latest version.
### 2. Manual
Place a copy of:
[`__init__.py`](custom_components/deutschebahn) at `<config>/custom_components/`

where `<config>` is your Home Assistant configuration directory.

>__NOTE__: Do not download the file by using the link above directly. Rather, click on it, then on the page that comes up use the `Raw` button.

## Configuration

Go to Configuration -> Integrations and click on "add integration". Then search for Deutsche Bahn

### Configuration Variables
- **from**: Enter your Start location
- **to**: Enter your destination

## Bug reporting
Open an issue over at [github issues](https://github.com/FaserF/ha-deutschebahn/issues). Please prefer sending over a log with debugging enabled.

Please note that I will only give limited support, as this integration was written by the HA devs and not by me!

To enable debugging enter the following in your configuration.yaml

```yaml
logger:
logs:
custom_components.deutschebahn: debug
```

## Thanks to
Huge thanks to [@homeassistant](https://github.com/home-assistant/core/tree/c741d9d0452970c39397deca1c65766c8cb917da/homeassistant/components/deutsche_bahn) for the official old integration, where this one is based on!
Empty file added custom_components/__init__.py
Empty file.
1 change: 1 addition & 0 deletions custom_components/deutschebahn/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
custom_components/deutschebahn/__pycache__/
1 change: 1 addition & 0 deletions custom_components/deutschebahn/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""The deutsche_bahn component."""
14 changes: 14 additions & 0 deletions custom_components/deutschebahn/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"domain": "deutschebahn",
"name": "Deutsche Bahn",
"documentation": "https://github.com/faserf/ha-deutschebahn#readme",
"issue_tracker": "https://github.com/faserf/ha-deutschebahn/issues",
"requirements": [
"schiene==0.23"
],
"codeowners": [],
"iot_class": "cloud_polling",
"loggers": [
"schiene"
]
}
Loading

0 comments on commit 1732e04

Please sign in to comment.