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

[DWDPollenflug] Small code improvments #7395

Merged
merged 2 commits into from
Apr 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions bundles/org.openhab.binding.dwdpollenflug/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,22 @@ https://isabel.dwd.de/DE/leistungen/gefahrenindizespollen/gefahrenindexpollen.ht
This binding supports a bridge thing (`bridge`), which polls the dataset for Germany in an adjustable interval.
And it supports a region thing (`region`), representing the data for all pollen types of a region or partregion.

## Discovery

This binding adds a default `bridge` thing to the Inbox.
This can be used for `region` things you may add manually.

## Thing Configuration

### Bridge

| Property | Default | Required | Description |
| Parameter | Default | Required | Description |
| --------- | :-----: | :------: | ------------------------------------------------------------------------------------ |
| `refresh` | 30 | no | Define the interval for polling the data from DWD in minutes. Minimum is 15 minutes. |

### Region

| Property | Default | Required | Description |
| Parameter | Default | Required | Description |
| ---------- | :-----: | :------: | -------------------------------------------------------------------------------------------------------- |
| `regionID` | - | yes | In PaperUI just select the region you want to display data for. For files-configuration see table below. |

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
*/
package org.openhab.binding.dwdpollenflug.internal;

import java.util.Collections;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

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

Expand All @@ -28,10 +33,20 @@ public class DWDPollenflugBindingConstants {

// bridge
public static final ThingTypeUID THING_TYPE_BRIDGE = new ThingTypeUID(BINDING_ID, "bridge");
public static final String DWD = "dwd";
public static final String BRIDGE_LABEL = "DWD Pollen Count Index (Bridge)";

// List of all Thing Type UIDs
public static final ThingTypeUID THING_TYPE_REGION = new ThingTypeUID(BINDING_ID, "region");

// @formatter:off
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS =
Collections.unmodifiableSet(Stream
.of(THING_TYPE_BRIDGE, THING_TYPE_REGION)
.collect(Collectors.toSet())
);
// @formatter:on

// Channels of pollen groups
public static final String CHANNEL_TODAY = "today";
public static final String CHANNEL_TOMORROW = "tomorrow";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@

import static org.openhab.binding.dwdpollenflug.internal.DWDPollenflugBindingConstants.*;

import java.util.Collections;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.jetty.client.HttpClient;
Expand All @@ -44,10 +39,6 @@
@NonNullByDefault
@Component(configurationPid = "binding.dwdpollenflug", service = ThingHandlerFactory.class)
public class DWDPollenflugHandlerFactory extends BaseThingHandlerFactory {

private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Collections
.unmodifiableSet(Stream.of(THING_TYPE_BRIDGE, THING_TYPE_REGION).collect(Collectors.toSet()));

private final HttpClient httpClient;

@Activate
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/**
* Copyright (c) 2010-2020 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.dwdpollenflug.internal.discovery;

import static org.openhab.binding.dwdpollenflug.internal.DWDPollenflugBindingConstants.*;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.smarthome.config.discovery.AbstractDiscoveryService;
import org.eclipse.smarthome.config.discovery.DiscoveryResult;
import org.eclipse.smarthome.config.discovery.DiscoveryResultBuilder;
import org.eclipse.smarthome.config.discovery.DiscoveryService;
import org.eclipse.smarthome.core.thing.ThingUID;
import org.osgi.service.component.annotations.Component;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* The {@link DWDPollenflugDiscoveryService} create a default bridge thing.
*
* @author Johannes Ott - Initial contribution
*/
@NonNullByDefault
@Component(service = DiscoveryService.class, immediate = true, configurationPid = "discovery.dwdpollenflug")
public class DWDPollenflugDiscoveryService extends AbstractDiscoveryService {
private static final ThingUID BRIDGE_THING_UID = new ThingUID(THING_TYPE_BRIDGE, DWD);
private static final int DISCOVER_TIMEOUT_SECONDS = 2;

private final Logger logger = LoggerFactory.getLogger(DWDPollenflugDiscoveryService.class);

public DWDPollenflugDiscoveryService() throws IllegalArgumentException {
super(SUPPORTED_THING_TYPES_UIDS, DISCOVER_TIMEOUT_SECONDS, true);
}

@Override
protected void startScan() {
logger.debug("Manual DWDPollenflug discovery scan.");
addBridge();
}

@Override
protected void startBackgroundDiscovery() {
logger.debug("Background DWDPollenflug discovery scan.");
addBridge();
}

private void addBridge() {
// @formatter:off
DiscoveryResult bridge = DiscoveryResultBuilder
.create(BRIDGE_THING_UID)
.withLabel(BRIDGE_LABEL)
.build();
// @formatter:on

thingDiscovered(bridge);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ public void initialize() {
bridgeConfig = getConfigAs(DWDPollenflugBridgeConfiguration.class);

if (bridgeConfig.isValid()) {
updateStatus(ThingStatus.UNKNOWN);
startPolling();
updateStatus(ThingStatus.ONLINE);
} else {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
"Refresh interval has to be at least 15 minutes.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void initialize() {
}
}

private synchronized @Nullable DWDPollenflugBridgeHandler getBridgeHandler() {
private @Nullable DWDPollenflugBridgeHandler getBridgeHandler() {
Bridge bridge = getBridge();
if (bridge != null) {
ThingHandler handler = bridge.getHandler();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ binding.dwdpollenflug.name = DWD Pollenflugindex
binding.dwdpollenflug.description = Binding um den Pollenflugindex des deutschen Wetterdienstes anzuzeigen

#bridge
thing-type.dwdpollenflug.bridge.label = DWD Pollenflugindex - Bridge
thing-type.dwdpollenflug.bridge.label = DWD Pollenflugindex (Bridge)
thing-type.dwdpollenflug.bridge.description = Bridge um den Pollenflugindex des DWDs abzurufen.

#bridge config
thing-type.config.dwdpollenflug.bridge.refresh.label = Aktualisierungsinterval
thing-type.config.dwdpollenflug.bridge.refresh.description = Zeit zwischen zwei API-Anfragen in Minuten. Minimum 15 Minuten.

#thing types
thing-type.dwdpollenflug.region.label = DWD Pollenflugindex Region
thing-type.dwdpollenflug.region.label = DWD Pollenflugindex (Region)
thing-type.dwdpollenflug.region.description = Pollenflugindex f\u00FCr eine bestimmte Region oder Teilregion
thing-type.dwdpollenflug.region.group.updates.label = Aktualisierung
thing-type.dwdpollenflug.region.group.updates.description = Informationen zur Aktualisierung
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
xsi:schemaLocation="https://openhab.org/schemas/thing-description/v1.0.0 https://openhab.org/schemas/thing-description-1.0.0.xsd">

<bridge-type id="bridge">
<label>DWD Pollen Count Index - Bridge</label>
<label>DWD Pollen Count Index (Bridge)</label>
<description>Bridge for accessing pollen count index data of the DWD</description>

<channel-groups>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<bridge-type-ref id="bridge" />
</supported-bridge-type-refs>

<label>DWD Pollen Count Index - Region</label>
<label>DWD Pollen Count Index (Region)</label>
<description>Pollen count index for a region or partregion</description>

<channel-groups>
Expand Down