Skip to content

Commit

Permalink
[nikohomecontrol] Add shutter invert and fix connection with NHC does…
Browse files Browse the repository at this point in the history
… not recover (openhab#10281)

* Ignore devices.changed event.

Signed-off-by: Mark Herwege <[email protected]>

* Null warnings cleanup.

Signed-off-by: Mark Herwege <[email protected]>

* Remove @NonNullByDefault({})

Signed-off-by: Mark Herwege <[email protected]>

* Shorten logger messages.

Signed-off-by: Mark Herwege <[email protected]>

* Introduce rollershutter invert flag.

Signed-off-by: Mark Herwege <[email protected]>

* Add null annotations.

Signed-off-by: Mark Herwege <[email protected]>

* Connection resilience improvements and log level cleanup.

Signed-off-by: Mark Herwege <[email protected]>

* Update bundles/org.openhab.binding.nikohomecontrol/src/main/resources/OH-INF/thing/thing-types.xml

Signed-off-by: Fabian Wolter <[email protected]>

Co-authored-by: Fabian Wolter <[email protected]>
  • Loading branch information
2 people authored and thinkingstone committed Nov 7, 2021
1 parent ea9eabf commit 3d912d4
Show file tree
Hide file tree
Showing 38 changed files with 456 additions and 262 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public class NikoHomeControlBridgeDiscoveryService extends AbstractDiscoveryServ

public NikoHomeControlBridgeDiscoveryService() {
super(NikoHomeControlBindingConstants.BRIDGE_THING_TYPES_UIDS, TIMEOUT);
logger.debug("Niko Home Control: bridge discovery service started");
logger.debug("bridge discovery service started");
}

/**
Expand All @@ -65,23 +65,23 @@ private void discoverBridge() {
try {
String broadcastAddr = networkAddressService.getConfiguredBroadcastAddress();
if (broadcastAddr == null) {
logger.warn("Niko Home Control: discovery not possible, no broadcast address found");
logger.warn("discovery not possible, no broadcast address found");
return;
}
logger.debug("Niko Home Control: discovery broadcast on {}", broadcastAddr);
logger.debug("discovery broadcast on {}", broadcastAddr);
NikoHomeControlDiscover nhcDiscover = new NikoHomeControlDiscover(broadcastAddr);
if (nhcDiscover.isNhcII()) {
addNhcIIBridge(nhcDiscover.getAddr(), nhcDiscover.getNhcBridgeId());
} else {
addNhcIBridge(nhcDiscover.getAddr(), nhcDiscover.getNhcBridgeId());
}
} catch (IOException e) {
logger.debug("Niko Home Control: no bridge found.");
logger.debug("no bridge found.");
}
}

private void addNhcIBridge(InetAddress addr, String bridgeId) {
logger.debug("Niko Home Control: NHC I bridge found at {}", addr);
logger.debug("NHC I bridge found at {}", addr);

String bridgeName = "Niko Home Control Bridge";
ThingUID uid = new ThingUID(BINDING_ID, "bridge", bridgeId);
Expand All @@ -92,7 +92,7 @@ private void addNhcIBridge(InetAddress addr, String bridgeId) {
}

private void addNhcIIBridge(InetAddress addr, String bridgeId) {
logger.debug("Niko Home Control: NHC II bridge found at {}", addr);
logger.debug("NHC II bridge found at {}", addr);

String bridgeName = "Niko Home Control II Bridge";
ThingUID uid = new ThingUID(BINDING_ID, "bridge2", bridgeId);
Expand All @@ -115,7 +115,7 @@ protected synchronized void stopScan() {

@Override
protected void startBackgroundDiscovery() {
logger.debug("Niko Home Control: Start background bridge discovery");
logger.debug("Start background bridge discovery");
ScheduledFuture<?> job = nhcDiscoveryJob;
if (job == null || job.isCancelled()) {
nhcDiscoveryJob = scheduler.scheduleWithFixedDelay(this::discoverBridge, 0, REFRESH_INTERVAL,
Expand All @@ -125,7 +125,7 @@ protected void startBackgroundDiscovery() {

@Override
protected void stopBackgroundDiscovery() {
logger.debug("Niko Home Control: Stop bridge background discovery");
logger.debug("Stop bridge background discovery");
ScheduledFuture<?> job = nhcDiscoveryJob;
if (job != null && !job.isCancelled()) {
job.cancel(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class NikoHomeControlDiscoveryService extends AbstractDiscoveryService {

public NikoHomeControlDiscoveryService(NikoHomeControlBridgeHandler handler) {
super(SUPPORTED_THING_TYPES_UIDS, TIMEOUT, false);
logger.debug("Niko Home Control: discovery service {}", handler);
logger.debug("discovery service {}", handler);
bridgeUID = handler.getThing().getUID();
this.handler = handler;
}
Expand All @@ -70,10 +70,10 @@ public void discoverDevices() {
NikoHomeControlCommunication nhcComm = handler.getCommunication();

if ((nhcComm == null) || !nhcComm.communicationActive()) {
logger.warn("Niko Home Control: not connected.");
logger.warn("not connected");
return;
}
logger.debug("Niko Home Control: getting devices on {}", handler.getThing().getUID().getId());
logger.debug("getting devices on {}", handler.getThing().getUID().getId());

Map<String, NhcAction> actions = nhcComm.getActions();

Expand All @@ -99,8 +99,7 @@ public void discoverDevices() {
thingName, thingLocation);
break;
default:
logger.debug("Niko Home Control: unrecognized action type {} for {} {}", nhcAction.getType(),
actionId, thingName);
logger.debug("unrecognized action type {} for {} {}", nhcAction.getType(), actionId, thingName);
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,20 @@

import java.util.List;

import org.eclipse.jdt.annotation.NonNullByDefault;

/**
* {@link NhcJwtToken2} represents the Niko Home Control II hobby API token payload.
*
* @author Mark Herwege - Initial Contribution
*/
@NonNullByDefault
class NhcJwtToken2 {
String sub;
String iat;
String exp;
String aud;
String iss;
String jti;
List<String> role;
String sub = "";
String iat = "";
String exp = "";
String aud = "";
String iss = "";
String jti = "";
List<String> role = List.of();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* 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.nikohomecontrol.internal.handler;

import org.eclipse.jdt.annotation.NonNullByDefault;

/**
* {@link NikoHomeControlActionBlindConfig} is the config class for Niko Home Control Blind Actions.
*
* @author Mark Herwege - Initial Contribution
*/
@NonNullByDefault
public class NikoHomeControlActionBlindConfig extends NikoHomeControlActionConfig {
public boolean invert;
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@
*/
package org.openhab.binding.nikohomecontrol.internal.handler;

import org.eclipse.jdt.annotation.NonNullByDefault;

/**
* {@link NikoHomeControlActionConfig} is the general config class for Niko Home Control Actions.
*
* @author Mark Herwege - Initial Contribution
*/
@NonNullByDefault
public class NikoHomeControlActionConfig {
public String actionId;
public String actionId = "";
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@
*/
package org.openhab.binding.nikohomecontrol.internal.handler;

import org.eclipse.jdt.annotation.NonNullByDefault;

/**
* {@link NikoHomeControlActionDimmerConfig} is the config class for Niko Home Control Dimmer Actions.
*
* @author Mark Herwege - Initial Contribution
*/
@NonNullByDefault
public class NikoHomeControlActionDimmerConfig extends NikoHomeControlActionConfig {
public int step;
public int step = 10;
}
Loading

0 comments on commit 3d912d4

Please sign in to comment.