Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[deutschebahn] Initial contribution: New binding for DeutscheBahn Fahrplan #11384

Merged
merged 10 commits into from
Nov 28, 2021
Merged
1 change: 1 addition & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
/bundles/org.openhab.binding.dbquery/ @lujop
/bundles/org.openhab.binding.deconz/ @openhab/add-ons-maintainers
/bundles/org.openhab.binding.denonmarantz/ @jwveldhuis
/bundles/org.openhab.binding.deutschebahn/ @soenkekueper
/bundles/org.openhab.binding.digiplex/ @rmichalak
/bundles/org.openhab.binding.digitalstrom/ @MichaelOchel @msiegele
/bundles/org.openhab.binding.dlinksmarthome/ @MikeJMajor
Expand Down
5 changes: 5 additions & 0 deletions bom/openhab-addons/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,11 @@
<artifactId>org.openhab.binding.denonmarantz</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.openhab.addons.bundles</groupId>
<artifactId>org.openhab.binding.deutschebahn</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.openhab.addons.bundles</groupId>
<artifactId>org.openhab.binding.digiplex</artifactId>
Expand Down
13 changes: 13 additions & 0 deletions bundles/org.openhab.binding.deutschebahn/NOTICE
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
This content is produced and maintained by the openHAB project.

* Project home: https://www.openhab.org

== Declared Project Licenses

This program and the accompanying materials are made available under the terms
of the Eclipse Public License 2.0 which is available at
https://www.eclipse.org/legal/epl-2.0/.

== Source Code

https://github.com/openhab/openhab-addons
345 changes: 345 additions & 0 deletions bundles/org.openhab.binding.deutschebahn/README.md

Large diffs are not rendered by default.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
54 changes: 54 additions & 0 deletions bundles/org.openhab.binding.deutschebahn/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.openhab.addons.bundles</groupId>
<artifactId>org.openhab.addons.reactor.bundles</artifactId>
<version>3.2.0-SNAPSHOT</version>
</parent>

<artifactId>org.openhab.binding.deutschebahn</artifactId>

<name>openHAB Add-ons :: Bundles :: DeutscheBahn Binding</name>

<build>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.14.0</version>
<executions>
<execution>
<id>generate-jaxb-sources</id>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<generatePackage>org.openhab.binding.deutschebahn.internal.timetable.dto</generatePackage>
<schemaDirectory>src/main/resources/xsd</schemaDirectory>
<noFileHeader>true</noFileHeader>
<locale>en</locale>
<episode>false</episode>
<extension>true</extension>
<args>
<arg>-Xxew</arg>
<arg>-Xxew:instantiate early</arg>
</args>
<plugins>
<plugin>
<groupId>com.github.jaxb-xew-plugin</groupId>
<artifactId>jaxb-xew-plugin</artifactId>
<version>1.10</version>
</plugin>
</plugins>
</configuration>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<features name="org.openhab.binding.deutschebahn-${project.version}" xmlns="http://karaf.apache.org/xmlns/features/v1.4.0">
<repository>mvn:org.openhab.core.features.karaf/org.openhab.core.features.karaf.openhab-core/${ohc.version}/xml/features</repository>

<feature name="openhab-binding-deutschebahn" description="DeutscheBahn Binding" version="${project.version}">
<feature>openhab-runtime-base</feature>
<bundle start-level="80">mvn:org.openhab.addons.bundles/org.openhab.binding.deutschebahn/${project.version}</bundle>
</feature>
</features>
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/**
* Copyright (c) 2010-2021 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.deutschebahn.internal;

import java.util.function.BiConsumer;
import java.util.function.Function;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.deutschebahn.internal.timetable.dto.JaxbEntity;
import org.openhab.core.types.State;

/**
* Accessor for attribute value of an DTO-Object.
*
* @author Sönke Küper - Initial contribution.
*
* @param <DTO_TYPE> type of value in Bean.
* @param <VALUE_TYPE> type of value in Bean.
* @param <STATE_TYPE> type of state.
*/
@NonNullByDefault
public abstract class AbstractDtoAttributeSelector<DTO_TYPE extends JaxbEntity, VALUE_TYPE, STATE_TYPE extends State> {

private final Function<DTO_TYPE, @Nullable VALUE_TYPE> getter;
private final BiConsumer<DTO_TYPE, VALUE_TYPE> setter;
private final Function<VALUE_TYPE, @Nullable STATE_TYPE> getState;
private final String channelTypeName;
private final Class<STATE_TYPE> stateType;

/**
* Creates an new {@link EventAttribute}.
*
* @param getter Function to get the raw value.
* @param setter Function to set the raw value.
* @param getState Function to get the Value as {@link State}.
*/
protected AbstractDtoAttributeSelector(final String channelTypeName, //
final Function<DTO_TYPE, @Nullable VALUE_TYPE> getter, //
final BiConsumer<DTO_TYPE, VALUE_TYPE> setter, //
final Function<VALUE_TYPE, @Nullable STATE_TYPE> getState, //
final Class<STATE_TYPE> stateType) {
this.channelTypeName = channelTypeName;
this.getter = getter;
this.setter = setter;
this.getState = getState;
this.stateType = stateType;
}

/**
* Returns the type of the state value.
*/
public final Class<STATE_TYPE> getStateType() {
return this.stateType;
}

/**
* Returns the name of the corresponding channel-type.
*/
public final String getChannelTypeName() {
return this.channelTypeName;
}

/**
* Returns the {@link State} for the selected attribute from the given DTO object
* Returns <code>null</code> if the value is <code>null</code>.
*/
@Nullable
public final STATE_TYPE getState(final DTO_TYPE object) {
final VALUE_TYPE value = this.getValue(object);
if (value == null) {
return null;
}
return this.getState.apply(value);
}

/**
* Returns the value for the selected attribute from the given DTO object.
*/
@Nullable
public final VALUE_TYPE getValue(final DTO_TYPE object) {
return this.getter.apply(object);
}

/**
* Sets the value for the selected attribute in the given DTO object
*/
public final void setValue(final DTO_TYPE event, final VALUE_TYPE object) {
this.setter.accept(event, object);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* Copyright (c) 2010-2021 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.deutschebahn.internal;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.deutschebahn.internal.timetable.dto.TimetableStop;
import org.openhab.core.types.State;

/**
* Selection of an attribute within an {@link TimetableStop} that provides a channel {@link State}.
*
* @author Sönke Küper - Initial contribution
*/
@NonNullByDefault
public interface AttributeSelection {

/**
* Returns the {@link State} that should be set for the channels'value for this attribute.
*/
@Nullable
public abstract State getState(TimetableStop stop);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* Copyright (c) 2010-2021 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.deutschebahn.internal;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.core.thing.ThingTypeUID;

/**
* The {@link DeutscheBahnBindingConstants} class defines common constants, which are used across the whole binding.
*
* @author Sönke Küper - Initial contribution
*/
@NonNullByDefault
public class DeutscheBahnBindingConstants {

/**
* Binding-ID.
*/
public static final String BINDING_ID = "deutschebahn";

/**
* {@link ThingTypeUID} for Timetable-API Bridge.
*/
public static final ThingTypeUID TIMETABLE_TYPE = new ThingTypeUID(BINDING_ID, "timetable");

/**
* {@link ThingTypeUID} for Train.
*/
public static final ThingTypeUID TRAIN_TYPE = new ThingTypeUID(BINDING_ID, "train");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* Copyright (c) 2010-2021 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.deutschebahn.internal;

import org.eclipse.jdt.annotation.NonNullByDefault;

/**
* The {@link DeutscheBahnTimetableConfiguration} for the Timetable bridge-type.
*
* @author Sönke Küper - Initial contribution
*/
@NonNullByDefault
public class DeutscheBahnTimetableConfiguration {

/**
* Access-Token.
*/
public String accessToken = "";

/**
* evaNo of the station to be queried.
*/
public String evaNo = "";

/**
* Filter for timetable stops.
*/
public String trainFilter = "";

/**
* Returns the {@link TimetableStopFilter}.
*/
public TimetableStopFilter getTimetableStopFilter() {
return TimetableStopFilter.valueOf(this.trainFilter.toUpperCase());
}
}
Loading