use of org.openhab.core.thing.binding.ThingHandlerCallback in project org.openhab.binding.zwave by openhab.
the class ZWaveThingHandlerTest method doConfigurationUpdate.
private ZWaveThingHandler doConfigurationUpdate(String param, Object value) {
ThingType thingType = ThingTypeBuilder.instance("bindingId", "thingTypeId", "label").build();
Thing thing = ThingBuilder.create(thingType.getUID(), new ThingUID(thingType.getUID(), "thingId")).withConfiguration(new Configuration()).build();
ZWaveNode node = Mockito.mock(ZWaveNode.class);
ZWaveController controller = Mockito.mock(ZWaveController.class);
ZWaveControllerHandler controllerHandler = Mockito.mock(ZWaveControllerHandler.class);
Mockito.when(controllerHandler.isControllerMaster()).thenReturn(false);
ThingHandlerCallback thingCallback = Mockito.mock(ThingHandlerCallback.class);
ZWaveThingHandler thingHandler = new ZWaveThingHandlerForTest(thing);
thingHandler.setCallback(thingCallback);
payloadCaptor = ArgumentCaptor.forClass(ZWaveCommandClassTransactionPayload.class);
Field fieldControllerHandler;
try {
ZWaveWakeUpCommandClass wakeupClass = new ZWaveWakeUpCommandClass(node, controller, null);
ZWaveAssociationCommandClass associationClass = new ZWaveAssociationCommandClass(node, controller, null);
ZWaveNodeNamingCommandClass namingClass = new ZWaveNodeNamingCommandClass(node, controller, null);
Mockito.doNothing().when(node).sendMessage(payloadCaptor.capture());
fieldControllerHandler = ZWaveThingHandler.class.getDeclaredField("controllerHandler");
fieldControllerHandler.setAccessible(true);
fieldControllerHandler.set(thingHandler, controllerHandler);
Mockito.when(controller.getOwnNodeId()).thenReturn(1);
Mockito.when(controllerHandler.getOwnNodeId()).thenReturn(1);
Mockito.when(controllerHandler.getNode(ArgumentMatchers.anyInt())).thenReturn(node);
Mockito.when(node.getNodeId()).thenReturn(1);
Mockito.when(node.getAssociationGroup(ArgumentMatchers.anyInt())).thenReturn(new ZWaveAssociationGroup(1));
Mockito.when(node.getCommandClass(ArgumentMatchers.eq(CommandClass.COMMAND_CLASS_WAKE_UP))).thenReturn(wakeupClass);
Mockito.when(node.getCommandClass(ArgumentMatchers.eq(CommandClass.COMMAND_CLASS_ASSOCIATION))).thenReturn(associationClass);
Mockito.when(node.getCommandClass(ArgumentMatchers.eq(CommandClass.COMMAND_CLASS_NODE_NAMING))).thenReturn(namingClass);
} catch (NoSuchFieldException | SecurityException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
Map<String, Object> config = new HashMap<String, Object>();
config.put(param, value);
thingHandler.handleConfigurationUpdate(config);
configResult = thingHandler.getThing().getConfiguration();
return thingHandler;
}
use of org.openhab.core.thing.binding.ThingHandlerCallback in project openhab-addons by openhab.
the class AhaWasteCollectionHandlerTest method testUpdateChannels.
@Test
public void testUpdateChannels() {
final Thing thing = mockThing(CONFIG);
final ThingHandlerCallback callback = mock(ThingHandlerCallback.class);
final AhaWasteCollectionHandler handler = createAndInitHandler(callback, thing);
try {
verify(callback).statusUpdated(eq(thing), argThat(arg -> arg.getStatus().equals(ThingStatus.UNKNOWN)));
verify(callback, timeout(1000)).statusUpdated(eq(thing), argThat(arg -> arg.getStatus().equals(ThingStatus.ONLINE)));
verify(callback, timeout(1000)).stateUpdated(new ChannelUID(thing.getUID(), AhaWasteCollectionBindingConstants.BIOWASTE), getDateTime(AhaCollectionScheduleStub.BIO_WASTE_DATE));
verify(callback, timeout(1000)).stateUpdated(new ChannelUID(thing.getUID(), AhaWasteCollectionBindingConstants.GENERAL_WASTE), getDateTime(AhaCollectionScheduleStub.GENERAL_WASTE_DATE));
verify(callback, timeout(1000)).stateUpdated(new ChannelUID(thing.getUID(), AhaWasteCollectionBindingConstants.LEIGHTWEIGHT_PACKAGING), getDateTime(AhaCollectionScheduleStub.LEIGHTWEIGHT_PACKAGING_DATE));
verify(callback, timeout(1000)).stateUpdated(new ChannelUID(thing.getUID(), AhaWasteCollectionBindingConstants.PAPER), getDateTime(AhaCollectionScheduleStub.PAPER_DATE));
} finally {
handler.dispose();
}
}
use of org.openhab.core.thing.binding.ThingHandlerCallback in project openhab-addons by openhab.
the class AVMFritzBaseThingHandler method createChannel.
/**
* Creates new channels for the thing.
*
* @param channelId ID of the channel to be created.
*/
private void createChannel(String channelId) {
ThingHandlerCallback callback = getCallback();
if (callback != null) {
ChannelUID channelUID = new ChannelUID(thing.getUID(), channelId);
ChannelTypeUID channelTypeUID = createChannelTypeUID(channelId);
Channel channel = callback.createChannelBuilder(channelUID, channelTypeUID).build();
updateThing(editThing().withoutChannel(channelUID).withChannel(channel).build());
}
}
use of org.openhab.core.thing.binding.ThingHandlerCallback in project openhab-addons by openhab.
the class Powerline546EHandler method createChannel.
/**
* Creates new channels for the thing.
*
* @param channelId ID of the channel to be created.
*/
private void createChannel(String channelId) {
ThingHandlerCallback callback = getCallback();
if (callback != null) {
ChannelUID channelUID = new ChannelUID(thing.getUID(), channelId);
ChannelTypeUID channelTypeUID = CHANNEL_BATTERY.equals(channelId) ? DefaultSystemChannelTypeProvider.SYSTEM_CHANNEL_BATTERY_LEVEL.getUID() : new ChannelTypeUID(BINDING_ID, channelId);
Channel channel = callback.createChannelBuilder(channelUID, channelTypeUID).build();
updateThing(editThing().withoutChannel(channelUID).withChannel(channel).build());
}
}
use of org.openhab.core.thing.binding.ThingHandlerCallback in project openhab-addons by openhab.
the class HomeConnectBridgeHandler method handleConfigurationUpdate.
@Override
public void handleConfigurationUpdate(Map<String, Object> configurationParameters) {
if (isModifyingCurrentConfig(configurationParameters)) {
List<String> parameters = configurationParameters.entrySet().stream().map((entry) -> {
if (CLIENT_ID.equals(entry.getKey()) || CLIENT_SECRET.equals(entry.getKey())) {
return entry.getKey() + ": ***";
}
return entry.getKey() + ": " + entry.getValue();
}).collect(Collectors.toList());
logger.debug("Update bridge configuration. bridge={}, parameters={}", getThing().getLabel(), parameters);
validateConfigurationParameters(configurationParameters);
Configuration configuration = editConfiguration();
for (Entry<String, Object> configurationParameter : configurationParameters.entrySet()) {
configuration.put(configurationParameter.getKey(), configurationParameter.getValue());
}
// invalidate oAuth credentials
try {
logger.debug("Clear oAuth credential store. bridge={}", getThing().getLabel());
var oAuthClientService = this.oAuthClientService;
if (oAuthClientService != null) {
oAuthClientService.remove();
}
} catch (OAuthException e) {
logger.error("Could not clear oAuth credentials. bridge={}", getThing().getLabel(), e);
}
if (isInitialized()) {
// persist new configuration and reinitialize handler
dispose();
updateConfiguration(configuration);
initialize();
} else {
// persist new configuration and notify Thing Manager
updateConfiguration(configuration);
@Nullable ThingHandlerCallback callback = getCallback();
if (callback != null) {
callback.configurationUpdated(this.getThing());
} else {
logger.warn("Handler {} tried updating its configuration although the handler was already disposed.", this.getClass().getSimpleName());
}
}
}
}
Aggregations