[zwavejs] Fix NullPointerException with ZUI 11.5.2 (#19500)

* Fix timout type
* Add tests

Signed-off-by: Leo Siepel <leosiepel@gmail.com>
This commit is contained in:
lsiepel
2025-11-02 11:23:23 +01:00
committed by GitHub
parent d75406f7a2
commit 7a02948d9e
6 changed files with 2894 additions and 4 deletions
@@ -33,5 +33,7 @@ public enum MetadataType {
@SerializedName("number")
NUMBER,
@SerializedName("boolean")
BOOLEAN
BOOLEAN,
@SerializedName("timeout")
TIMEOUT
}
@@ -468,8 +468,6 @@ public abstract class BaseMetadata {
switch (type) {
case ANY:
return determineTypeFromValue(value, commandClass);
case DURATION:
return MetadataType.NUMBER;
case NUMBER:
if (COMMAND_CLASS_ALARM == commandClass && optionList != null && optionList.size() == 2) {
return MetadataType.BOOLEAN;
@@ -534,6 +532,9 @@ public abstract class BaseMetadata {
type = correctedType(type, value, commandClass, optionList);
switch (type) {
case DURATION:
case TIMEOUT:
return CoreItemFactory.NUMBER + ":Time";
case NUMBER:
if (VIRTUAL_COMMAND_CLASS_ROLLERSHUTTER.equals(commandClassName)) {
return CoreItemFactory.ROLLERSHUTTER;
@@ -46,6 +46,7 @@ public class ConfigMetadata extends BaseMetadata {
private Type configTypeFromMetadata(MetadataType type, Object value, int commandClass) {
type = correctedType(type, value, commandClass, null);
switch (type) {
case TIMEOUT:
case NUMBER:
return Type.INTEGER;
// Might be future cases that require DECIMAL, might depend on scale?
@@ -90,7 +90,7 @@ public class ZwaveJSBridgeHandlerTest {
try {
verify(callback).statusUpdated(eq(thing), argThat(arg -> arg.getStatus().equals(ThingStatus.UNKNOWN)));
verify(discoveryService, times(28)).addNodeDiscovery(any());
verify(discoveryService, times(29)).addNodeDiscovery(any());
} finally {
handler.dispose();
}
@@ -194,6 +194,25 @@ public class ZwaveJSTypeGeneratorTest {
assertEquals("Dimmer", type.getItemType());
}
@Test
public void testGenCTNode12TimeOutType() throws IOException {
Channel channel = getChannel("store_4.json", 12, "protection-timeout");
ChannelType type = channelTypeProvider.getChannelType(Objects.requireNonNull(channel.getChannelTypeUID()),
null);
Configuration configuration = channel.getConfiguration();
assertNotNull(type);
assertEquals("zwavejs:test-bridge:test-thing:protection-timeout", channel.getUID().getAsString());
assertEquals("Number:Time", Objects.requireNonNull(type).getItemType());
assertEquals("RF Protection Timeout", channel.getLabel());
assertNotNull(configuration.get(BindingConstants.CONFIG_CHANNEL_WRITE_PROPERTY_STR));
StateDescription statePattern = type.getState();
assertNotNull(statePattern);
assertNull(statePattern.getStep());
assertEquals("%d %unit%", statePattern.getPattern());
}
@Test
public void testGenCTNode13MultilevelSwitchType() throws IOException {
Channel channel = getChannel("store_4.json", 13, "multilevel-switch-value");
File diff suppressed because it is too large Load Diff