use of org.openhab.core.config.core.Configuration in project openhab-addons by openhab.
the class SmartherBridgeHandler method registerNotification.
@Override
public synchronized void registerNotification(String plantId) throws SmartherGatewayException {
if (!config.isUseNotifications()) {
return;
}
final ExpiringCache<List<Location>> localLocationCache = this.locationCache;
if (localLocationCache != null) {
List<Location> locations = localLocationCache.getValue();
if (locations != null) {
final Optional<Location> maybeLocation = locations.stream().filter(l -> l.getPlantId().equals(plantId)).findFirst();
if (maybeLocation.isPresent()) {
Location location = maybeLocation.get();
if (!location.hasSubscription()) {
// Validate notification Url (must be non-null and https)
final String notificationUrl = config.getNotificationUrl();
if (isValidNotificationUrl(notificationUrl)) {
// Call gateway to register plant subscription
String subscriptionId = subscribePlant(plantId, config.getNotificationUrl());
logger.debug("Bridge[{}] Notification registered: [plantId={}, subscriptionId={}]", thing.getUID(), plantId, subscriptionId);
// Add the new subscription to notifications list
List<String> notifications = config.addNotification(subscriptionId);
// Save the updated notifications list back to bridge config
Configuration configuration = editConfiguration();
configuration.put(PROPERTY_NOTIFICATIONS, notifications);
updateConfiguration(configuration);
// Update the local locationCache with the added data
locations.stream().forEach(l -> {
if (l.getPlantId().equals(plantId)) {
l.setSubscription(subscriptionId, config.getNotificationUrl());
}
});
localLocationCache.putValue(locations);
} else {
logger.warn("Bridge[{}] Invalid notification Url [{}]: must be non-null, public https address", thing.getUID(), notificationUrl);
}
}
}
}
}
}
use of org.openhab.core.config.core.Configuration in project openhab-addons by openhab.
the class DmxBridgeHandlerTest method setUp.
@BeforeEach
public void setUp() {
bridgeProperties = new HashMap<>();
bridge = BridgeBuilder.create(THING_TYPE_TEST_BRIDGE, "testbridge").withLabel("Test Bridge").withChannel(ChannelBuilder.create(CHANNEL_UID_MUTE, "Switch").withType(MUTE_CHANNEL_TYPEUID).build()).withConfiguration(new Configuration(bridgeProperties)).build();
ThingHandlerCallback mockCallback = mock(ThingHandlerCallback.class);
doAnswer(answer -> {
((Thing) answer.getArgument(0)).setStatusInfo(answer.getArgument(1));
return null;
}).when(mockCallback).statusUpdated(any(), any());
bridgeHandler = Mockito.spy(new DmxBridgeHandlerImpl(bridge));
bridgeHandler.getThing().setHandler(bridgeHandler);
bridgeHandler.setCallback(mockCallback);
bridgeHandler.initialize();
}
use of org.openhab.core.config.core.Configuration in project openhab-addons by openhab.
the class Lib485BridgeHandlerTest method setUp.
@BeforeEach
public void setUp() {
bridgeProperties = new HashMap<>();
bridgeProperties.put(CONFIG_ADDRESS, TEST_ADDRESS);
bridge = BridgeBuilder.create(THING_TYPE_LIB485_BRIDGE, "lib485bridge").withLabel("Lib485 Bridge").withChannel(ChannelBuilder.create(CHANNEL_UID_MUTE, "Switch").withType(MUTE_CHANNEL_TYPEUID).build()).withConfiguration(new Configuration(bridgeProperties)).build();
ThingHandlerCallback mockCallback = mock(ThingHandlerCallback.class);
doAnswer(answer -> {
((Thing) answer.getArgument(0)).setStatusInfo(answer.getArgument(1));
return null;
}).when(mockCallback).statusUpdated(any(), any());
bridgeHandler = new Lib485BridgeHandler(bridge) {
@Override
protected void validateConfigurationParameters(Map<String, Object> configurationParameters) {
}
};
bridgeHandler.getThing().setHandler(bridgeHandler);
bridgeHandler.setCallback(mockCallback);
bridgeHandler.initialize();
}
use of org.openhab.core.config.core.Configuration in project openhab-addons by openhab.
the class ArtnetBridgeHandlerTest method setUp.
@BeforeEach
public void setUp() {
bridgeProperties = new HashMap<>();
bridgeProperties.put(CONFIG_ADDRESS, TEST_ADDRESS);
bridgeProperties.put(CONFIG_UNIVERSE, TEST_UNIVERSE);
bridge = BridgeBuilder.create(THING_TYPE_ARTNET_BRIDGE, "artnetbridge").withLabel("Artnet Bridge").withChannel(ChannelBuilder.create(CHANNEL_UID_MUTE, "Switch").withType(MUTE_CHANNEL_TYPEUID).build()).withConfiguration(new Configuration(bridgeProperties)).build();
ThingHandlerCallback mockCallback = mock(ThingHandlerCallback.class);
doAnswer(answer -> {
((Thing) answer.getArgument(0)).setStatusInfo(answer.getArgument(1));
return null;
}).when(mockCallback).statusUpdated(any(), any());
bridgeHandler = new ArtnetBridgeHandler(bridge) {
@Override
protected void validateConfigurationParameters(Map<String, Object> configurationParameters) {
}
};
bridgeHandler.getThing().setHandler(bridgeHandler);
bridgeHandler.setCallback(mockCallback);
bridgeHandler.initialize();
}
use of org.openhab.core.config.core.Configuration in project openhab-addons by openhab.
the class EnOceanBaseSensorHandler method packetReceived.
@Override
public void packetReceived(BasePacket packet) {
ERP1Message msg = (ERP1Message) packet;
EEPType receivingEEPType = receivingEEPTypes.get(msg.getRORG());
if (receivingEEPType == null) {
return;
}
EEP eep = EEPFactory.buildEEP(receivingEEPType, (ERP1Message) packet);
logger.debug("ESP Packet payload {} for {} received", HexUtils.bytesToHex(packet.getPayload()), HexUtils.bytesToHex(msg.getSenderId()));
if (eep.isValid()) {
byte[] senderId = msg.getSenderId();
// try to interpret received message for all linked or trigger channels
getThing().getChannels().stream().filter(channelFilter(receivingEEPType, senderId)).sorted(// handle state channels first
Comparator.comparing(Channel::getKind)).forEachOrdered(channel -> {
ChannelTypeUID channelTypeUID = channel.getChannelTypeUID();
String channelTypeId = (channelTypeUID != null) ? channelTypeUID.getId() : "";
String channelId = channel.getUID().getId();
Configuration channelConfig = channel.getConfiguration();
switch(channel.getKind()) {
case STATE:
State result = eep.convertToState(channelId, channelTypeId, channelConfig, this::getCurrentState);
// if message can be interpreted (result != UnDefType.UNDEF) => update item state
if (result != null && result != UnDefType.UNDEF) {
updateState(channelId, result);
}
break;
case TRIGGER:
String lastEvent = lastEvents.get(channelId);
String event = eep.convertToEvent(channelId, channelTypeId, lastEvent, channelConfig);
if (event != null) {
triggerChannel(channel.getUID(), event);
lastEvents.put(channelId, event);
}
break;
}
});
if (receivingEEPType.getRequstesResponse()) {
// fire trigger for receive
triggerChannel(prepareAnswer, "requestAnswer");
// Send response after 100ms
if (responseFuture == null || responseFuture.isDone()) {
responseFuture = scheduler.schedule(this::sendRequestResponse, 100, TimeUnit.MILLISECONDS);
}
}
}
}
Aggregations