use of org.eclipse.smarthome.core.thing.ThingUID in project smarthome by eclipse.
the class BridgeMDNSDiscoveryParticipant method getThingUID.
@Override
public ThingUID getThingUID(ServiceInfo service) {
if (service.getApplication().contains("dssweb")) {
String hostAddress = service.getName() + "." + service.getDomain() + ".";
DsAPI digitalSTROMClient = new DsAPIImpl(hostAddress, Config.DEFAULT_CONNECTION_TIMEOUT, Config.DEFAULT_READ_TIMEOUT, true);
Map<String, String> dsidMap = digitalSTROMClient.getDSID(null);
String dSID = null;
if (dsidMap != null) {
dSID = dsidMap.get(JSONApiResponseKeysEnum.DSID.getKey());
}
if (StringUtils.isNotBlank(dSID)) {
return new ThingUID(DigitalSTROMBindingConstants.THING_TYPE_DSS_BRIDGE, dSID);
} else {
logger.error("Can't get server dSID to generate thing UID. Please add the server manually.");
}
}
return null;
}
use of org.eclipse.smarthome.core.thing.ThingUID in project smarthome by eclipse.
the class DeviceDiscoveryService method onDeviceAddedInternal.
private void onDeviceAddedInternal(GeneralDeviceInformation device) {
boolean isSupported = false;
if (device instanceof Device) {
Device tempDevice = (Device) device;
if ((tempDevice.isSensorDevice() && deviceType.equals(tempDevice.getHWinfo().replaceAll("-", ""))) || (deviceType.equals(tempDevice.getHWinfo().substring(0, 2)) && (tempDevice.isDeviceWithOutput() || tempDevice.isBinaryInputDevice()) && tempDevice.isPresent())) {
isSupported = true;
}
} else if (device instanceof Circuit && DsDeviceThingTypeProvider.SupportedThingTypes.circuit.toString().equals(deviceType)) {
isSupported = true;
}
if (isSupported) {
ThingUID thingUID = getThingUID(device);
if (thingUID != null) {
Map<String, Object> properties = new HashMap<>(1);
properties.put(DigitalSTROMBindingConstants.DEVICE_DSID, device.getDSID().getValue());
String deviceName = null;
if (StringUtils.isNotBlank(device.getName())) {
deviceName = device.getName();
} else {
// if no name is set, the dSID will be used as name
deviceName = device.getDSID().getValue();
}
DiscoveryResult discoveryResult = DiscoveryResultBuilder.create(thingUID).withProperties(properties).withBridge(bridgeUID).withLabel(deviceName).build();
thingDiscovered(discoveryResult);
} else {
if (device instanceof Device) {
logger.debug("Discovered unsupported device hardware type '{}' with uid {}", ((Device) device).getHWinfo(), device.getDSUID());
}
}
} else {
if (device instanceof Device) {
logger.debug("Discovered device with disabled or no output mode. Device was not added to inbox. " + "Device information: hardware info: {}, dSUID: {}, device-name: {}, output value: {}", ((Device) device).getHWinfo(), device.getDSUID(), device.getName(), ((Device) device).getOutputMode());
}
}
}
use of org.eclipse.smarthome.core.thing.ThingUID in project smarthome by eclipse.
the class DeviceDiscoveryService method getThingUID.
private ThingUID getThingUID(GeneralDeviceInformation device) {
ThingUID bridgeUID = bridgeHandler.getThing().getUID();
ThingTypeUID thingTypeUID = null;
if (device instanceof Device) {
Device tempDevice = (Device) device;
thingTypeUID = new ThingTypeUID(BINDING_ID, tempDevice.getHWinfo().substring(0, 2));
if (tempDevice.isSensorDevice() && deviceType.equals(tempDevice.getHWinfo().replaceAll("-", ""))) {
thingTypeUID = new ThingTypeUID(BINDING_ID, deviceType);
}
} else {
thingTypeUID = new ThingTypeUID(BINDING_ID, DsDeviceThingTypeProvider.SupportedThingTypes.circuit.toString());
}
if (getSupportedThingTypes().contains(thingTypeUID)) {
String thingDeviceId = device.getDSID().toString();
ThingUID thingUID = new ThingUID(thingTypeUID, bridgeUID, thingDeviceId);
return thingUID;
} else {
return null;
}
}
use of org.eclipse.smarthome.core.thing.ThingUID in project smarthome by eclipse.
the class SceneDiscoveryService method getThingUID.
private ThingUID getThingUID(InternalScene scene) {
ThingUID bridgeUID = bridgeHandler.getThing().getUID();
ThingTypeUID thingTypeUID = new ThingTypeUID(BINDING_ID, sceneType);
if (getSupportedThingTypes().contains(thingTypeUID)) {
String thingSceneId = scene.getID();
ThingUID thingUID = new ThingUID(thingTypeUID, bridgeUID, thingSceneId);
return thingUID;
} else {
return null;
}
}
use of org.eclipse.smarthome.core.thing.ThingUID in project smarthome by eclipse.
the class SceneDiscoveryService method onSceneAddedInternal.
private void onSceneAddedInternal(InternalScene scene) {
logger.debug("{}", scene.getSceneType());
if (scene != null && scene.getSceneType().equals(sceneType)) {
if (!ignoredScene(scene.getSceneID()) && !ignoreGroup(scene.getGroupID())) {
ThingUID thingUID = getThingUID(scene);
if (thingUID != null) {
ThingUID bridgeUID = bridgeHandler.getThing().getUID();
Map<String, Object> properties = new HashMap<>();
properties.put(ZONE_ID, scene.getZoneID());
properties.put(GROUP_ID, scene.getGroupID());
if (SceneEnum.containsScene(scene.getSceneID())) {
properties.put(SCENE_ID, SceneEnum.getScene(scene.getSceneID()).toString());
} else {
logger.debug("discovered scene: name '{}' with id {} have an invalid scene-ID", scene.getSceneName(), scene.getID());
}
DiscoveryResult discoveryResult = DiscoveryResultBuilder.create(thingUID).withProperties(properties).withBridge(bridgeUID).withLabel(scene.getSceneName()).build();
thingDiscovered(discoveryResult);
} else {
logger.debug("discovered unsupported scene: name '{}' with id {}", scene.getSceneName(), scene.getID());
}
}
}
}
Aggregations