diff --git a/com.zsmartsystems.zigbee.dongle.ember/src/main/java/com/zsmartsystems/zigbee/dongle/ember/ZigBeeDongleEzsp.java b/com.zsmartsystems.zigbee.dongle.ember/src/main/java/com/zsmartsystems/zigbee/dongle/ember/ZigBeeDongleEzsp.java index 8a1c11046..214592eb5 100644 --- a/com.zsmartsystems.zigbee.dongle.ember/src/main/java/com/zsmartsystems/zigbee/dongle/ember/ZigBeeDongleEzsp.java +++ b/com.zsmartsystems.zigbee.dongle.ember/src/main/java/com/zsmartsystems/zigbee/dongle/ember/ZigBeeDongleEzsp.java @@ -1083,11 +1083,12 @@ public ZigBeeStatus setZigBeeChannel(ZigBeeChannel channel) { } if (networkStateUp) { EmberNcp ncp = getEmberNcp(); - ncp.setRadioChannel(channel); + return ncp.setRadioChannel(channel) == EmberStatus.EMBER_SUCCESS ? ZigBeeStatus.SUCCESS + : ZigBeeStatus.BAD_RESPONSE; } else { networkParameters.setRadioChannel(channel.getChannel()); + return ZigBeeStatus.SUCCESS; } - return ZigBeeStatus.SUCCESS; } @Override diff --git a/com.zsmartsystems.zigbee.dongle.ember/src/test/java/com/zsmartsystems/zigbee/dongle/ember/ZigBeeDongleEzspTest.java b/com.zsmartsystems.zigbee.dongle.ember/src/test/java/com/zsmartsystems/zigbee/dongle/ember/ZigBeeDongleEzspTest.java index bdc7ffc56..bbefeaee9 100644 --- a/com.zsmartsystems.zigbee.dongle.ember/src/test/java/com/zsmartsystems/zigbee/dongle/ember/ZigBeeDongleEzspTest.java +++ b/com.zsmartsystems.zigbee.dongle.ember/src/test/java/com/zsmartsystems/zigbee/dongle/ember/ZigBeeDongleEzspTest.java @@ -415,11 +415,18 @@ public EmberNcp getEmberNcp() { } @Test - public void setZigBeeChannel() { + public void setZigBeeChannelOk() { System.out.println("--- " + Thread.currentThread().getStackTrace()[1].getMethodName()); - ZigBeeDongleEzsp dongle = new ZigBeeDongleEzsp(null); - assertEquals(ZigBeeStatus.INVALID_ARGUMENTS, dongle.setZigBeeChannel(ZigBeeChannel.CHANNEL_03)); + final EmberNcp ncp = Mockito.mock(EmberNcp.class); + ZigBeeDongleEzsp dongle = new ZigBeeDongleEzsp(null) { + @Override + public EmberNcp getEmberNcp() { + return ncp; + } + }; + + Mockito.when(ncp.setRadioChannel(ArgumentMatchers.any())).thenReturn(EmberStatus.EMBER_SUCCESS); assertEquals(ZigBeeStatus.SUCCESS, dongle.setZigBeeChannel(ZigBeeChannel.CHANNEL_11)); assertEquals(ZigBeeChannel.CHANNEL_11, dongle.getZigBeeChannel()); @@ -428,13 +435,31 @@ public void setZigBeeChannel() { assertEquals(ZigBeeChannel.CHANNEL_24, dongle.getZigBeeChannel()); } + @Test + public void setZigBeeChannelError() throws Exception { + System.out.println("--- " + Thread.currentThread().getStackTrace()[1].getMethodName()); + + final EmberNcp ncp = Mockito.mock(EmberNcp.class); + ZigBeeDongleEzsp dongle = new ZigBeeDongleEzsp(null) { + @Override + public EmberNcp getEmberNcp() { + return ncp; + } + }; + + TestUtilities.setField(ZigBeeDongleEzsp.class, dongle, "networkStateUp", true); + + Mockito.when(ncp.setRadioChannel(ArgumentMatchers.any())).thenReturn(EmberStatus.UNKNOWN); + + assertEquals(ZigBeeStatus.INVALID_ARGUMENTS, dongle.setZigBeeChannel(ZigBeeChannel.CHANNEL_03)); + assertEquals(ZigBeeStatus.BAD_RESPONSE, dongle.setZigBeeChannel(ZigBeeChannel.CHANNEL_24)); + } + @Test public void testEzspMessageSentHandler() throws Exception { System.out.println("--- " + Thread.currentThread().getStackTrace()[1].getMethodName()); ZigBeeTransportReceive transport = Mockito.mock(ZigBeeTransportReceive.class); - final EmberNcp ncp = Mockito.mock(EmberNcp.class); - Mockito.when(ncp.getNwkAddress()).thenReturn(1243); ZigBeeDongleEzsp dongle = new ZigBeeDongleEzsp(null); dongle.setZigBeeTransportReceive(transport);