-
-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for listening to group addresses on Ember coordinator (#695)
Signed-off-by: Chris Jackson <chris@cd-jackson.com>
- Loading branch information
Showing
8 changed files
with
235 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
...binding.zigbee.ember/src/test/java/org/openhab/binding/zigbee/ember/EmberHandlerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package org.openhab.binding.zigbee.ember; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.mockito.ArgumentCaptor; | ||
import org.mockito.Mockito; | ||
import org.openhab.binding.zigbee.ZigBeeBindingConstants; | ||
import org.openhab.binding.zigbee.converter.ZigBeeChannelConverterFactory; | ||
import org.openhab.binding.zigbee.ember.handler.EmberHandler; | ||
import org.openhab.core.config.core.Configuration; | ||
import org.openhab.core.io.transport.serial.SerialPortManager; | ||
import org.openhab.core.thing.Bridge; | ||
|
||
import com.zsmartsystems.zigbee.dongle.ember.EmberNcp; | ||
import com.zsmartsystems.zigbee.dongle.ember.ZigBeeDongleEzsp; | ||
import com.zsmartsystems.zigbee.dongle.ember.ezsp.structure.EmberMulticastTableEntry; | ||
import com.zsmartsystems.zigbee.dongle.ember.ezsp.structure.EzspConfigId; | ||
|
||
/** | ||
* | ||
* @author Chris Jackson | ||
* | ||
*/ | ||
public class EmberHandlerTest { | ||
class EmberHandlerForTest extends EmberHandler { | ||
public EmberHandlerForTest(Bridge coordinator, SerialPortManager serialPortManager, | ||
ZigBeeChannelConverterFactory channelFactory, ZigBeeDongleEzsp dongle) { | ||
super(coordinator, serialPortManager, channelFactory); | ||
this.zigbeeTransport = dongle; | ||
} | ||
|
||
@Override | ||
protected Configuration editConfiguration() { | ||
return new Configuration(); | ||
} | ||
} | ||
|
||
@Test | ||
public void setGroupRegistration() { | ||
Bridge bridge = Mockito.mock(Bridge.class); | ||
SerialPortManager serialPortManager = Mockito.mock(SerialPortManager.class); | ||
ZigBeeChannelConverterFactory zigBeeChannelConverterFactory = Mockito.mock(ZigBeeChannelConverterFactory.class); | ||
|
||
ZigBeeDongleEzsp dongle = Mockito.mock(ZigBeeDongleEzsp.class); | ||
EmberNcp ncp = Mockito.mock(EmberNcp.class); | ||
Mockito.when(dongle.getEmberNcp()).thenReturn(ncp); | ||
EmberHandler handler = new EmberHandlerForTest(bridge, serialPortManager, zigBeeChannelConverterFactory, | ||
dongle); | ||
|
||
ArgumentCaptor<Integer> indexCaptor = ArgumentCaptor.forClass(Integer.class); | ||
ArgumentCaptor<EmberMulticastTableEntry> valueCaptor = ArgumentCaptor.forClass(EmberMulticastTableEntry.class); | ||
|
||
Map<String, Object> cfg = new HashMap<>(); | ||
cfg.put(ZigBeeBindingConstants.CONFIGURATION_GROUPREGISTRATION, "1234,5678, 90AB ,CDEF"); | ||
handler.handleConfigurationUpdate(cfg); | ||
|
||
Mockito.verify(dongle).updateDefaultConfiguration(EzspConfigId.EZSP_CONFIG_MULTICAST_TABLE_SIZE, 7); | ||
Mockito.verify(ncp, Mockito.times(4)).setMulticastTableEntry(indexCaptor.capture(), valueCaptor.capture()); | ||
|
||
int[] mcastId = { 0x1234, 0x5678, 0x90AB, 0xCDEF }; | ||
for (int cnt = 0; cnt < 4; cnt++) { | ||
assertEquals(cnt, indexCaptor.getAllValues().get(cnt)); | ||
assertEquals(1, valueCaptor.getAllValues().get(cnt).getEndpoint()); | ||
assertEquals(0, valueCaptor.getAllValues().get(cnt).getNetworkIndex()); | ||
assertEquals(mcastId[cnt], valueCaptor.getAllValues().get(cnt).getMulticastId()); | ||
} | ||
} | ||
} |
Oops, something went wrong.