Skip to content

Commit df9c352

Browse files
committed
cleanup
1 parent 7d87a68 commit df9c352

16 files changed

+88
-103
lines changed

.classpath

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,5 @@
33
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
44
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
55
<classpathentry kind="src" path="src/main/java"/>
6-
<classpathentry kind="lib" path="lib/commons-lang3-3.4.jar"/>
76
<classpathentry kind="output" path="target/classes"/>
87
</classpath>

META-INF/MANIFEST.MF

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@ Bundle-Name: Zigbee2Mqtt Binding
77
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
88
Bundle-SymbolicName: org.openhab.binding.zigbee2mqtt;singleton:=true
99
Bundle-Vendor: openHAB
10-
Bundle-Version: 2.4.0.qualifier
10+
Bundle-Version: 2.5.0.qualifier
1111
Import-Package:
1212
com.google.gson,
1313
org.apache.commons.lang,
1414
org.eclipse.jdt.annotation;resolution:=optional,
15-
org.eclipse.smarthome.binding.mqtt,
1615
org.eclipse.smarthome.config.core,
1716
org.eclipse.smarthome.config.discovery,
1817
org.eclipse.smarthome.core.library.types,

build.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ bin.includes=META-INF/,\
44
.,\
55
OSGI-INF/,\
66
ESH-INF/,\
7-
NOTICE
7+
about.html

lib/commons-lang3-3.4.jar

-424 KB
Binary file not shown.

pom.xml

Lines changed: 1 addition & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -7,56 +7,12 @@
77
<parent>
88
<artifactId>pom</artifactId>
99
<groupId>org.openhab.binding</groupId>
10-
<version>2.4.0-SNAPSHOT</version>
10+
<version>2.5.0-SNAPSHOT</version>
1111
</parent>
1212

1313
<artifactId>org.openhab.binding.zigbee2mqtt</artifactId>
1414
<packaging>eclipse-plugin</packaging>
1515

1616
<name>Zigbee2Mqtt Binding</name>
1717

18-
<profiles>
19-
<profile>
20-
<id>check</id>
21-
<build>
22-
<pluginManagement>
23-
<plugins>
24-
<plugin>
25-
<groupId>org.openhab.tools.sat</groupId>
26-
<artifactId>sat-plugin</artifactId>
27-
<version>${sat.version}</version>
28-
<executions>
29-
<execution>
30-
<phase>verify</phase>
31-
<goals>
32-
<goal>checkstyle</goal>
33-
<goal>pmd</goal>
34-
<goal>findbugs</goal>
35-
<goal>report</goal>
36-
</goals>
37-
</execution>
38-
</executions>
39-
</plugin>
40-
</plugins>
41-
</pluginManagement>
42-
</build>
43-
</profile>
44-
<profile>
45-
<id>check-bundles</id>
46-
<activation>
47-
<file>
48-
<exists>META-INF/MANIFEST.MF</exists>
49-
</file>
50-
</activation>
51-
<build>
52-
<plugins>
53-
<plugin>
54-
<groupId>org.openhab.tools.sat</groupId>
55-
<artifactId>sat-plugin</artifactId>
56-
</plugin>
57-
</plugins>
58-
</build>
59-
</profile>
60-
</profiles>
61-
6218
</project>

src/main/java/org/openhab/binding/zigbee2mqtt/internal/Zigbee2MqttBindingConstants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
* The {@link Zigbee2MqttBindingConstants} class defines common constants, which are
2626
* used across the whole binding.
2727
*
28-
* @author zigbee2mqtt - Initial contribution
28+
* @author Nils
2929
*/
3030
@NonNullByDefault
3131
public class Zigbee2MqttBindingConstants {

src/main/java/org/openhab/binding/zigbee2mqtt/internal/Zigbee2MqttBridgeConfiguration.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,10 @@
1212
*/
1313
package org.openhab.binding.zigbee2mqtt.internal;
1414

15-
import org.apache.commons.lang3.builder.ToStringBuilder;
16-
1715
/**
1816
* The {@link Zigbee2MqttBridgeConfiguration} class contains fields mapping thing configuration parameters.
1917
*
20-
* @author mqttbroker - Initial contribution
18+
* @author Nils
2119
*/
2220
public class Zigbee2MqttBridgeConfiguration {
2321

@@ -76,13 +74,20 @@ public void setMqttbrokerClientID(String mqttbrokerClientID) {
7674
this.mqttbrokerClientID = mqttbrokerClientID;
7775
}
7876

77+
// @Override
78+
// public String toString() {
79+
// return new ToStringBuilder(this).append("mqttbrokerIpAddress", this.getMqttbrokerIpAddress())
80+
// .append("mqttbrokerPort", this.getMqttbrokerPort())
81+
// .append("mqttbrokerBaseTopic", this.getMqttbrokerBaseTopic())
82+
// .append("mqttbrokerUsername", this.getMqttbrokerUsername()).append("mqttbrokerPassword", "*****")
83+
// .toString();
84+
// }
85+
7986
@Override
8087
public String toString() {
81-
return new ToStringBuilder(this).append("mqttbrokerIpAddress", this.getMqttbrokerIpAddress())
82-
.append("mqttbrokerPort", this.getMqttbrokerPort())
83-
.append("mqttbrokerBaseTopic", this.getMqttbrokerBaseTopic())
84-
.append("mqttbrokerUsername", this.getMqttbrokerUsername()).append("mqttbrokerPassword", "*****")
85-
.toString();
88+
return "Zigbee2MqttBridgeConfiguration [mqttbrokerIpAddress=" + mqttbrokerIpAddress + ", mqttbrokerPort="
89+
+ mqttbrokerPort + ", mqttbrokerBaseTopic=" + mqttbrokerBaseTopic + ", mqttbrokerUsername="
90+
+ mqttbrokerUsername + "]";
8691
}
8792

8893
}

src/main/java/org/openhab/binding/zigbee2mqtt/internal/Zigbee2MqttBridgeHandler.java

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.eclipse.smarthome.core.library.types.OnOffType;
2121
import org.eclipse.smarthome.core.library.types.StringType;
2222
import org.eclipse.smarthome.core.thing.Bridge;
23+
import org.eclipse.smarthome.core.thing.Channel;
2324
import org.eclipse.smarthome.core.thing.ChannelUID;
2425
import org.eclipse.smarthome.core.thing.ThingStatus;
2526
import org.eclipse.smarthome.core.thing.binding.BaseBridgeHandler;
@@ -31,14 +32,13 @@
3132
import org.slf4j.Logger;
3233
import org.slf4j.LoggerFactory;
3334

34-
import com.google.gson.JsonArray;
3535
import com.google.gson.JsonObject;
3636

3737
/**
3838
* The {@link Zigbee2MqttBridgeHandler} is responsible for handling commands, which are
3939
* sent to one of the channels.
4040
*
41-
* @author zigbee2mqtt - Initial contribution
41+
* @author Nils
4242
*/
4343
public class Zigbee2MqttBridgeHandler extends BaseBridgeHandler implements Zigbee2MqttMessageSubscriber {
4444

@@ -47,10 +47,12 @@ public class Zigbee2MqttBridgeHandler extends BaseBridgeHandler implements Zigbe
4747
private final Logger logger = LoggerFactory.getLogger(Zigbee2MqttBridgeHandler.class);
4848

4949
private MqttBrokerConnection mqttBrokerConnection;
50+
51+
@SuppressWarnings("unused")
5052
private @Nullable Zigbee2MqttDiscoveryService discoveryService;
5153

52-
@Nullable
53-
private Zigbee2MqttBridgeConfiguration config;
54+
@NonNull
55+
private Zigbee2MqttBridgeConfiguration config = new Zigbee2MqttBridgeConfiguration();
5456

5557
public Zigbee2MqttBridgeHandler(Bridge thing) {
5658
super(thing);
@@ -145,14 +147,6 @@ public void setDiscovery(Zigbee2MqttDiscoveryService discoveryService) {
145147
this.discoveryService = discoveryService;
146148
}
147149

148-
/**
149-
* @return
150-
*/
151-
private Zigbee2MqttBridgeConfiguration loadAndCheckConfiguration() {
152-
153-
return getConfigAs(Zigbee2MqttBridgeConfiguration.class);
154-
}
155-
156150
@Override
157151
public void processMessage(@NonNull String topic, @NonNull JsonObject jsonMessage) {
158152

@@ -168,16 +162,21 @@ public void processMessage(@NonNull String topic, @NonNull JsonObject jsonMessag
168162
break;
169163
case "config":
170164
String logLevel = jsonMessage.get("log_level").getAsString();
171-
updateState(getThing().getChannel(CHANNEL_NAME_LOGLEVEL).getUID(), StringType.valueOf(logLevel));
165+
Channel channelLogLevel = getThing().getChannel(CHANNEL_NAME_LOGLEVEL);
166+
if (channelLogLevel != null) {
167+
updateState(channelLogLevel.getUID(), StringType.valueOf(logLevel));
168+
}
172169

173170
String permitJoin = jsonMessage.get("permit_join").getAsString();
174-
updateState(getThing().getChannel(CHANNEL_NAME_PERMITJOIN).getUID(),
175-
Boolean.parseBoolean(permitJoin) ? OnOffType.ON : OnOffType.OFF);
171+
Channel channelPermitJoin = getThing().getChannel(CHANNEL_NAME_PERMITJOIN);
172+
if (channelPermitJoin != null) {
173+
updateState(channelPermitJoin.getUID(),
174+
Boolean.parseBoolean(permitJoin) ? OnOffType.ON : OnOffType.OFF);
175+
}
176176

177177
break;
178178
case "log":
179-
String type = jsonMessage.get("type").getAsString();
180-
JsonArray message = jsonMessage.get("message").getAsJsonArray();
179+
181180
// TODO mach was!
182181
break;
183182
case "device_connected":
@@ -188,7 +187,6 @@ public void processMessage(@NonNull String topic, @NonNull JsonObject jsonMessag
188187
default:
189188
break;
190189
}
191-
192190
}
193191

194192
/**

src/main/java/org/openhab/binding/zigbee2mqtt/internal/Zigbee2MqttDeviceHandler.java

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
* The{@link Zigbee2MqttDeviceHandler} is responsible for handling commands, which are
5151
* sent to one of the channels.
5252
*
53-
* @author zigbee2mqtt - Initial contribution
53+
* @author Nils
5454
*/
5555
@NonNullByDefault
5656
public class Zigbee2MqttDeviceHandler extends BaseThingHandler implements Zigbee2MqttMessageSubscriber {
@@ -145,30 +145,36 @@ public void processMessage(@NonNull String topic, @NonNull JsonObject jsonMessag
145145

146146
Channel channel = getThing().getChannel(channelKey);
147147

148-
switch (channel.getAcceptedItemType()) {
149-
150-
case ITEM_TYPE_NUMBER:
151-
updateState(channel.getUID(), new DecimalType(channelValue));
152-
break;
153-
154-
case ITEM_TYPE_STRING:
155-
triggerChannel(channel.getUID(), channelValue);
156-
break;
157-
158-
case ITEM_TYPE_CONTACT:
159-
updateState(channel.getUID(),
160-
Boolean.parseBoolean(channelValue) ? OpenClosedType.CLOSED : OpenClosedType.OPEN);
161-
break;
162-
163-
case ITEM_TYPE_SWITCH:
164-
updateState(channel.getUID(),
165-
Boolean.parseBoolean(channelValue) ? OnOffType.ON : OnOffType.OFF);
166-
break;
167-
168-
default:
169-
channelValue = entry.getValue().getAsString();
170-
logger.warn("ThingUID: {} - channel not found -> channel: {}", thingId, channel);
171-
break;
148+
if (channel != null) {
149+
String acceptedItemType = channel.getAcceptedItemType();
150+
if (acceptedItemType != null) {
151+
switch (acceptedItemType) {
152+
153+
case ITEM_TYPE_NUMBER:
154+
updateState(channel.getUID(), new DecimalType(channelValue));
155+
break;
156+
157+
case ITEM_TYPE_STRING:
158+
triggerChannel(channel.getUID(), channelValue);
159+
break;
160+
161+
case ITEM_TYPE_CONTACT:
162+
updateState(channel.getUID(),
163+
Boolean.parseBoolean(channelValue) ? OpenClosedType.CLOSED
164+
: OpenClosedType.OPEN);
165+
break;
166+
167+
case ITEM_TYPE_SWITCH:
168+
updateState(channel.getUID(),
169+
Boolean.parseBoolean(channelValue) ? OnOffType.ON : OnOffType.OFF);
170+
break;
171+
172+
default:
173+
channelValue = entry.getValue().getAsString();
174+
logger.warn("ThingUID: {} - channel not found -> channel: {}", thingId, channel);
175+
break;
176+
}
177+
}
172178
}
173179
} else {
174180
logger.debug("ThingUID: {} - channel '{}' for device not found", thingId, channelKey);

src/main/java/org/openhab/binding/zigbee2mqtt/internal/Zigbee2MqttHandlerFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
* The {@link Zigbee2MqttHandlerFactory} is responsible for creating things and thing
3939
* handlers.
4040
*
41-
* @author zigbee2mqtt - Initial contribution
41+
* @author Nils
4242
*/
4343
@NonNullByDefault
4444
@Component(configurationPid = "binding.zigbee2mqtt", service = ThingHandlerFactory.class)

0 commit comments

Comments
 (0)