org.eclipse.smarthome.core.thing.ThingUID Java Examples
The following examples show how to use
org.eclipse.smarthome.core.thing.ThingUID.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ThingResource.java From smarthome with Eclipse Public License 2.0 | 6 votes |
@PUT @RolesAllowed({ Role.USER, Role.ADMIN }) @Path("/{thingUID}/enable") @ApiOperation(value = "Sets the thing enabled status.") @ApiResponses(value = { @ApiResponse(code = 200, message = "OK", response = String.class), @ApiResponse(code = 404, message = "Thing not found.") }) public Response setEnabled(@HeaderParam(HttpHeaders.ACCEPT_LANGUAGE) String language, @PathParam("thingUID") @ApiParam(value = "thing") String thingUID, @ApiParam(value = "enabled") String enabled) throws IOException { final Locale locale = localeService.getLocale(language); ThingUID thingUIDObject = new ThingUID(thingUID); // Check if the Thing exists, 404 if not Thing thing = thingRegistry.get(thingUIDObject); if (null == thing) { logger.info("Received HTTP PUT request for set enabled at '{}' for the unknown thing '{}'.", uriInfo.getPath(), thingUID); return getThingNotFoundResponse(thingUID); } thingManager.setEnabled(thingUIDObject, Boolean.valueOf(enabled)); // everything went well return getThingResponse(Status.OK, thing, locale, null); }
Example #2
Source File: InboxOSGITest.java From smarthome with Eclipse Public License 2.0 | 6 votes |
@Test public void assertThatDiscoveryResultIsAddedToInboxWhenThingWithDifferentUIDexists() { assertThat(inbox.getAll().size(), is(0)); ThingTypeUID thingTypeUID = new ThingTypeUID("dummyBindingId2", "dummyThingType"); ThingUID thingUID = new ThingUID(thingTypeUID, "dummyThingId"); managedThingProvider.add(ThingBuilder.create(thingTypeUID, "dummyThingId").build()); Map<String, Object> props = new HashMap<>(); props.put("property1", "property1value1"); props.put("property2", "property2value1"); DiscoveryResult discoveryResult = new DiscoveryResultImpl(thingTypeUID, thingUID, null, null, null, "DummyLabel1", DEFAULT_TTL); inbox.add(discoveryResult); assertThat(inbox.getAll().size(), is(0)); }
Example #3
Source File: ComponentAlarmControlPanel.java From smarthome with Eclipse Public License 2.0 | 6 votes |
public ComponentAlarmControlPanel(ThingUID thing, HaID haID, String configJSON, @Nullable ChannelStateUpdateListener channelStateUpdateListener, Gson gson) { super(thing, haID, configJSON, gson); config = gson.fromJson(configJSON, Config.class); final String[] state_enum = { config.state_disarmed, config.state_armed_home, config.state_armed_away, config.state_pending, config.state_triggered }; channels.put(stateChannelID, new CChannel(this, stateChannelID, new TextValue(state_enum), config.state_topic, null, config.name, "", channelStateUpdateListener)); channels.put(switchDisarmChannelID, new CChannel(this, switchDisarmChannelID, new TextValue(new String[] { config.payload_disarm }), config.state_topic, null, config.name, "", channelStateUpdateListener)); channels.put(switchArmHomeChannelID, new CChannel(this, switchArmHomeChannelID, new TextValue(new String[] { config.payload_arm_home }), config.state_topic, null, config.name, "", channelStateUpdateListener)); channels.put(switchArmAwayChannelID, new CChannel(this, switchArmAwayChannelID, new TextValue(new String[] { config.payload_arm_away }), config.state_topic, null, config.name, "", channelStateUpdateListener)); }
Example #4
Source File: FirmwareUpdateServiceImpl.java From smarthome with Eclipse Public License 2.0 | 6 votes |
@Override @Nullable public FirmwareStatusInfo getFirmwareStatusInfo(ThingUID thingUID) { ParameterChecks.checkNotNull(thingUID, "Thing UID"); FirmwareUpdateHandler firmwareUpdateHandler = getFirmwareUpdateHandler(thingUID); if (firmwareUpdateHandler == null) { logger.trace("No firmware update handler available for thing with UID {}.", thingUID); return null; } Firmware latestFirmware = getLatestSuitableFirmware(firmwareUpdateHandler.getThing()); FirmwareStatusInfo firmwareStatusInfo = getFirmwareStatusInfo(firmwareUpdateHandler, latestFirmware); processFirmwareStatusInfo(firmwareUpdateHandler, firmwareStatusInfo, latestFirmware); return firmwareStatusInfo; }
Example #5
Source File: GenericWemoLightOSGiTest.java From smarthome with Eclipse Public License 2.0 | 6 votes |
@Override protected Thing createThing(ThingTypeUID thingTypeUID, String channelID, String itemAcceptedType, WemoHttpCall wemoHttpCaller) { Configuration configuration = new Configuration(); configuration.put(WemoBindingConstants.DEVICE_ID, WEMO_LIGHT_ID); ThingUID thingUID = new ThingUID(thingTypeUID, TEST_THING_ID); ChannelUID channelUID = new ChannelUID(thingUID, channelID); Channel channel = ChannelBuilder.create(channelUID, itemAcceptedType).withType(DEFAULT_CHANNEL_TYPE_UID) .withKind(ChannelKind.STATE).withLabel("label").build(); ThingUID bridgeUID = new ThingUID(BRIDGE_TYPE_UID, WEMO_BRIDGE_ID); thing = ThingBuilder.create(thingTypeUID, thingUID).withConfiguration(configuration).withChannel(channel) .withBridge(bridgeUID).build(); managedThingProvider.add(thing); ThingHandler handler = thing.getHandler(); if (handler != null) { AbstractWemoHandler h = (AbstractWemoHandler) handler; h.setWemoHttpCaller(wemoHttpCaller); } return thing; }
Example #6
Source File: DiscoveryResultImplTest.java From smarthome with Eclipse Public License 2.0 | 6 votes |
@Test public void testInvalidSynchronize() { ThingTypeUID thingTypeUID = new ThingTypeUID("bindingId", "thingType"); Map<String, Object> discoveryResultSourceMap = new HashMap<>(); discoveryResultSourceMap.put("ipAddress", "127.0.0.1"); DiscoveryResultImpl discoveryResult = new DiscoveryResultImpl(thingTypeUID, new ThingUID(thingTypeUID, "thingId"), null, discoveryResultSourceMap, "ipAddress", "TARGET", DEFAULT_TTL); discoveryResult.setFlag(DiscoveryResultFlag.IGNORED); discoveryResult.synchronize(null); assertEquals("127.0.0.1", discoveryResult.getProperties().get("ipAddress")); assertEquals("ipAddress", discoveryResult.getRepresentationProperty()); assertEquals("TARGET", discoveryResult.getLabel()); assertEquals(DiscoveryResultFlag.IGNORED, discoveryResult.getFlag()); }
Example #7
Source File: CcuDiscoveryService.java From smarthome with Eclipse Public License 2.0 | 6 votes |
/** * Extracts the CCU infos from the UDP response. */ private void extractGatewayInfos() throws IOException { try { DatagramPacket packet = new DatagramPacket(new byte[265], 256); socket.receive(packet); Eq3UdpResponse response = new Eq3UdpResponse(packet.getData()); logger.trace("Eq3UdpResponse: {}", response); if (response.isValid()) { logger.debug("Discovered a CCU gateway with serial number '{}'", response.getSerialNumber()); String address = packet.getAddress().getHostAddress(); ThingUID thingUid = new ThingUID(THING_TYPE_BRIDGE, response.getSerialNumber()); thingDiscovered(DiscoveryResultBuilder.create(thingUid).withProperty("gatewayAddress", address) .withRepresentationProperty("gatewayAddress") .withLabel(response.getDeviceTypeId() + " - " + address).build()); } } catch (SocketTimeoutException ex) { // ignore } }
Example #8
Source File: ThingResource.java From smarthome with Eclipse Public License 2.0 | 6 votes |
@GET @RolesAllowed({ Role.ADMIN }) @Path("/{thingUID}") @Produces(MediaType.APPLICATION_JSON) @ApiOperation(value = "Gets thing by UID.") @ApiResponses(value = { @ApiResponse(code = 200, message = "OK", response = ThingDTO.class), @ApiResponse(code = 404, message = "Thing not found.") }) public Response getByUID(@HeaderParam(HttpHeaders.ACCEPT_LANGUAGE) @ApiParam(value = "language") String language, @PathParam("thingUID") @ApiParam(value = "thingUID") String thingUID) { final Locale locale = localeService.getLocale(language); Thing thing = thingRegistry.get((new ThingUID(thingUID))); // return Thing data if it does exist if (thing != null) { return getThingResponse(Status.OK, thing, locale, null); } else { return getThingNotFoundResponse(thingUID); } }
Example #9
Source File: ThingFactory.java From smarthome with Eclipse Public License 2.0 | 6 votes |
public static @Nullable Thing createThing(ThingUID thingUID, Configuration configuration, @Nullable Map<String, String> properties, @Nullable ThingUID bridgeUID, ThingTypeUID thingTypeUID, List<ThingHandlerFactory> thingHandlerFactories) { for (ThingHandlerFactory thingHandlerFactory : thingHandlerFactories) { if (thingHandlerFactory.supportsThingType(thingTypeUID)) { Thing thing = thingHandlerFactory.createThing(thingTypeUID, configuration, thingUID, bridgeUID); if (thing == null) { LOGGER.error( "Thing factory ({}) returned null on create thing when it reports to support the thing type ({}).", thingHandlerFactory.getClass(), thingTypeUID); } else { if (properties != null) { for (String key : properties.keySet()) { thing.setProperty(key, properties.get(key)); } } } return thing; } } return null; }
Example #10
Source File: DiscoveryServiceRegistryImpl.java From smarthome with Eclipse Public License 2.0 | 6 votes |
@Override public @Nullable Collection<ThingUID> removeOlderResults(final DiscoveryService source, final long timestamp, final @Nullable Collection<ThingTypeUID> thingTypeUIDs, @Nullable ThingUID bridgeUID) { HashSet<ThingUID> removedResults = new HashSet<>(); for (final DiscoveryListener listener : this.listeners) { try { Collection<ThingUID> olderResults = AccessController .doPrivileged(new PrivilegedAction<@Nullable Collection<ThingUID>>() { @Override public @Nullable Collection<ThingUID> run() { return listener.removeOlderResults(source, timestamp, thingTypeUIDs, bridgeUID); } }); if (olderResults != null) { removedResults.addAll(olderResults); } } catch (Exception ex) { logger.error("Cannot notify the DiscoveryListener '{}' on all things removed event!", listener.getClass().getName(), ex); } } return removedResults; }
Example #11
Source File: BridgeDiscoveryService.java From smarthome with Eclipse Public License 2.0 | 6 votes |
private ThingUID getThingUID() { DsAPI digitalSTROMClient = new DsAPIImpl(HOST_ADDRESS, Config.DEFAULT_CONNECTION_TIMEOUT, Config.DEFAULT_READ_TIMEOUT, true); String dSID = null; switch (digitalSTROMClient.checkConnection("123")) { case HttpURLConnection.HTTP_OK: case HttpURLConnection.HTTP_UNAUTHORIZED: case HttpURLConnection.HTTP_FORBIDDEN: Map<String, String> dsidMap = digitalSTROMClient.getDSID(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 ThingUID. Please add the server manually."); } } return null; }
Example #12
Source File: SonyAudioDiscoveryParticipant.java From smarthome with Eclipse Public License 2.0 | 6 votes |
@Override public DiscoveryResult createResult(RemoteDevice device) { DiscoveryResult result = null; ThingUID thingUid = getThingUID(device); if (thingUid != null) { String label = StringUtils.isEmpty(device.getDetails().getFriendlyName()) ? device.getDisplayString() : device.getDetails().getFriendlyName(); String host = device.getIdentity().getDescriptorURL().getHost(); int port = device.getIdentity().getDescriptorURL().getPort(); String path = device.getIdentity().getDescriptorURL().getPath(); try { Map<String, Object> properties = getDescription(host, port, path); properties.put(SonyAudioBindingConstants.HOST_PARAMETER, device.getIdentity().getDescriptorURL().getHost()); result = DiscoveryResultBuilder.create(thingUid).withLabel(label).withProperties(properties).build(); } catch (IOException e) { return null; } } return result; }
Example #13
Source File: HueBridgeDiscoveryParticipant.java From smarthome with Eclipse Public License 2.0 | 6 votes |
@Override public @Nullable ThingUID getThingUID(RemoteDevice device) { DeviceDetails details = device.getDetails(); if (details != null) { ModelDetails modelDetails = details.getModelDetails(); if (modelDetails != null) { String modelName = modelDetails.getModelName(); if (modelName != null) { if (modelName.startsWith("Philips hue bridge")) { return new ThingUID(THING_TYPE_BRIDGE, details.getSerialNumber()); } } } } return null; }
Example #14
Source File: TradfriDiscoveryParticipant.java From smarthome with Eclipse Public License 2.0 | 6 votes |
@Override public DiscoveryResult createResult(ServiceInfo service) { ThingUID thingUID = getThingUID(service); if (thingUID != null) { if (service.getHostAddresses() != null && service.getHostAddresses().length > 0 && !service.getHostAddresses()[0].isEmpty()) { logger.debug("Discovered Tradfri gateway: {}", service); Map<String, Object> properties = new HashMap<>(4); properties.put(PROPERTY_VENDOR, "IKEA of Sweden"); properties.put(GATEWAY_CONFIG_HOST, service.getHostAddresses()[0]); properties.put(GATEWAY_CONFIG_PORT, service.getPort()); properties.put(PROPERTY_SERIAL_NUMBER, service.getName()); String fwVersion = service.getPropertyString("version"); if (fwVersion != null) { properties.put(PROPERTY_FIRMWARE_VERSION, fwVersion); } return DiscoveryResultBuilder.create(thingUID).withProperties(properties).withLabel("TRÅDFRI Gateway") .withRepresentationProperty(GATEWAY_CONFIG_HOST).build(); } else { logger.warn("Discovered Tradfri gateway doesn't have an IP address: {}", service); } } return null; }
Example #15
Source File: FirmwareUpdateConsoleCommandExtension.java From smarthome with Eclipse Public License 2.0 | 6 votes |
private void listFirmwareStatus(Console console, String[] args) { if (args.length != 2) { console.println("Specify the thing id to get its firmware status: firmware status <thingUID>"); return; } ThingUID thingUID = new ThingUID(args[1]); FirmwareStatusInfo firmwareStatusInfo = firmwareUpdateService.getFirmwareStatusInfo(thingUID); if (firmwareStatusInfo != null) { StringBuffer sb = new StringBuffer(); sb.append(String.format("Firmware status for thing with UID %s is %s.", thingUID, firmwareStatusInfo.getFirmwareStatus())); if (firmwareStatusInfo.getUpdatableFirmwareVersion() != null) { sb.append(String.format(" The latest updatable firmware version is %s.", firmwareStatusInfo.getUpdatableFirmwareVersion())); } console.println(sb.toString()); } else { console.println( String.format("The firmware status for thing with UID %s could not be determined.", thingUID)); } }
Example #16
Source File: ThingConsoleCommandExtension.java From smarthome with Eclipse Public License 2.0 | 6 votes |
private void printThings(Console console, Collection<Thing> things) { if (things.isEmpty()) { console.println("No things found."); } for (Thing thing : things) { String id = thing.getUID().toString(); String thingType = thing instanceof Bridge ? "Bridge" : "Thing"; ThingStatusInfo status = thingStatusInfoI18nLocalizationService.getLocalizedThingStatusInfo(thing, null); ThingUID bridgeUID = thing.getBridgeUID(); String label = thing.getLabel(); console.println(String.format("%s (Type=%s, Status=%s, Label=%s, Bridge=%s)", id, thingType, status, label, bridgeUID)); } }
Example #17
Source File: DiscoveryResultImpl.java From smarthome with Eclipse Public License 2.0 | 5 votes |
@Override public String getBindingId() { ThingUID thingId = this.thingUID; if (thingId != null) { return thingId.getBindingId(); } return ""; }
Example #18
Source File: ThingManagerImpl.java From smarthome with Eclipse Public License 2.0 | 5 votes |
private void addThingsToBridge(Bridge bridge) { Collection<Thing> things = thingRegistry.getAll(); for (Thing thing : things) { ThingUID bridgeUID = thing.getBridgeUID(); if (bridgeUID != null && bridgeUID.equals(bridge.getUID())) { if (bridge instanceof BridgeImpl && !bridge.getThings().contains(thing)) { ((BridgeImpl) bridge).addThing(thing); } } } }
Example #19
Source File: FSInternetRadioDiscoveryParticipantJavaTest.java From smarthome with Eclipse Public License 2.0 | 5 votes |
/** * Verify valid DiscoveryResult with completeFSInterntRadioDevice. * * @throws ValidationException */ @SuppressWarnings("null") @Test public void validDiscoveryResultWithComplete() throws ValidationException { RemoteDevice completeFSInternetRadioDevice = createDefaultFSInternetRadioDevice(DEFAULT_RADIO_BASE_URL); final DiscoveryResult result = discoveryParticipant.createResult(completeFSInternetRadioDevice); assertEquals(new ThingUID(DEFAULT_RADIO_THING_UID), result.getThingUID()); assertEquals(FSInternetRadioBindingConstants.THING_TYPE_RADIO, result.getThingTypeUID()); assertEquals(DEFAULT_RADIO_MANIFACTURER, result.getProperties().get(FSInternetRadioBindingConstants.PROPERTY_MANUFACTURER)); assertEquals(DEFAULT_RADIO_MODEL_NUMBER, result.getProperties().get(FSInternetRadioBindingConstants.PROPERTY_MODEL)); }
Example #20
Source File: InboxFilterCriteria.java From smarthome with Eclipse Public License 2.0 | 5 votes |
/** * Creates a new instance of this class with the specified parameters. * * @param thingUID the Thing UID to be filtered (could be null or empty) * @param flag the discovery result flag to be filtered (could be null) */ public InboxFilterCriteria(ThingUID thingUID, DiscoveryResultFlag flag) { this.bindingId = null; this.thingTypeUID = null; this.thingUID = thingUID; this.flag = flag; }
Example #21
Source File: LIRCRemoteDiscoveryService.java From smarthome with Eclipse Public License 2.0 | 5 votes |
@Override public void onMessageReceived(ThingUID bridge, LIRCResponse message) { LIRCResponse response = message; String command = response.getCommand(); if ("LIST".equals(command) && response.isSuccess()) { for (String remoteID : response.getData()) { addRemote(bridge, remoteID); } } }
Example #22
Source File: BridgeDiscoveryService.java From smarthome with Eclipse Public License 2.0 | 5 votes |
private void createResult() { ThingUID uid = getThingUID(); if (uid != null) { Map<String, Object> properties = new HashMap<>(2); properties.put(DigitalSTROMBindingConstants.HOST, HOST_ADDRESS); DiscoveryResult result = DiscoveryResultBuilder.create(uid).withProperties(properties) .withLabel("digitalSTROM-Server").build(); thingDiscovered(result); } }
Example #23
Source File: HueLightDiscoveryService.java From smarthome with Eclipse Public License 2.0 | 5 votes |
private void onLightAddedInternal(FullLight light) { ThingUID thingUID = getThingUID(light); ThingTypeUID thingTypeUID = getThingTypeUID(light); String modelId = light.getNormalizedModelID(); if (thingUID != null && thingTypeUID != null) { ThingUID bridgeUID = hueBridgeHandler.getThing().getUID(); Map<String, Object> properties = new HashMap<>(); properties.put(LIGHT_ID, light.getId()); if (modelId != null) { properties.put(Thing.PROPERTY_MODEL_ID, modelId); } String uniqueID = light.getUniqueID(); if (uniqueID != null) { properties.put(UNIQUE_ID, uniqueID); } DiscoveryResult discoveryResult = DiscoveryResultBuilder.create(thingUID).withThingType(thingTypeUID) .withProperties(properties).withBridge(bridgeUID).withRepresentationProperty(UNIQUE_ID) .withLabel(light.getName()).build(); thingDiscovered(discoveryResult); } else { logger.debug("discovered unsupported light of type '{}' and model '{}' with id {}", light.getType(), modelId, light.getId()); } }
Example #24
Source File: HueLightHandlerTest.java From smarthome with Eclipse Public License 2.0 | 5 votes |
private void assertSendCommand(String channel, Command command, HueLightState currentState, String expectedReply, String expectedModel, String expectedVendor) { FullLight light = gson.fromJson(currentState.toString(), FullConfig.class).getLights().get(0); Bridge mockBridge = mock(Bridge.class); when(mockBridge.getStatus()).thenReturn(ThingStatus.ONLINE); Thing mockThing = mock(Thing.class); when(mockThing.getConfiguration()).thenReturn(new Configuration(Collections.singletonMap(LIGHT_ID, "1"))); HueClient mockClient = mock(HueClient.class); when(mockClient.getLightById(any())).thenReturn(light); HueLightHandler hueLightHandler = new HueLightHandler(mockThing) { @Override protected synchronized HueClient getHueClient() { return mockClient; } @Override protected Bridge getBridge() { return mockBridge; } }; hueLightHandler.initialize(); verify(mockThing).setProperty(eq(Thing.PROPERTY_MODEL_ID), eq(expectedModel)); verify(mockThing).setProperty(eq(Thing.PROPERTY_VENDOR), eq(expectedVendor)); hueLightHandler.handleCommand(new ChannelUID(new ThingUID("hue::test"), channel), command); ArgumentCaptor<StateUpdate> captorStateUpdate = ArgumentCaptor.forClass(StateUpdate.class); verify(mockClient).updateLightState(any(FullLight.class), captorStateUpdate.capture()); assertJson(expectedReply, captorStateUpdate.getValue().toJson()); }
Example #25
Source File: CFactory.java From smarthome with Eclipse Public License 2.0 | 5 votes |
/** * Create a HA MQTT component. The configuration JSon string is required. * * @param thingUID The Thing UID that this component will belong to. * @param haID The location of this component. The HomeAssistant ID contains the object-id, node-id and * component-id. * @param configJSON Most components expect a "name", a "state_topic" and "command_topic" like with * "{name:'Name',state_topic:'homeassistant/switch/0/object/state',command_topic:'homeassistant/switch/0/object/set'". * @param updateListener A channel state update listener * @return A HA MQTT Component */ public static @Nullable AbstractComponent createComponent(ThingUID thingUID, HaID haID, String configJSON, @Nullable ChannelStateUpdateListener updateListener, Gson gson) { try { switch (haID.component) { case "alarm_control_panel": return new ComponentAlarmControlPanel(thingUID, haID, configJSON, updateListener, gson); case "binary_sensor": return new ComponentBinarySensor(thingUID, haID, configJSON, updateListener, gson); case "camera": return new ComponentCamera(thingUID, haID, configJSON, updateListener, gson); case "cover": return new ComponentCover(thingUID, haID, configJSON, updateListener, gson); case "fan": return new ComponentFan(thingUID, haID, configJSON, updateListener, gson); case "climate": return new ComponentClimate(thingUID, haID, configJSON, updateListener, gson); case "light": return new ComponentLight(thingUID, haID, configJSON, updateListener, gson); case "lock": return new ComponentLock(thingUID, haID, configJSON, updateListener, gson); case "sensor": return new ComponentSensor(thingUID, haID, configJSON, updateListener, gson); case "switch": return new ComponentSwitch(thingUID, haID, configJSON, updateListener, gson); } } catch (UnsupportedOperationException e) { logger.warn("Not supported", e); } return null; }
Example #26
Source File: ThingRegistryImpl.java From smarthome with Eclipse Public License 2.0 | 5 votes |
@Override public Channel getChannel(ChannelUID channelUID) { ThingUID thingUID = channelUID.getThingUID(); Thing thing = get(thingUID); if (thing != null) { return thing.getChannel(channelUID.getId()); } return null; }
Example #27
Source File: HueLightDiscoveryService.java From smarthome with Eclipse Public License 2.0 | 5 votes |
@Override public void onLightRemoved(@Nullable HueBridge bridge, FullLight light) { ThingUID thingUID = getThingUID(light); if (thingUID != null) { thingRemoved(thingUID); } }
Example #28
Source File: SonosHandlerFactory.java From smarthome with Eclipse Public License 2.0 | 5 votes |
private ThingUID getPlayerUID(ThingTypeUID thingTypeUID, ThingUID thingUID, Configuration configuration) { if (thingUID != null) { return thingUID; } else { String udn = (String) configuration.get(UDN); return new ThingUID(thingTypeUID, udn); } }
Example #29
Source File: ThingFactoryTest.java From smarthome with Eclipse Public License 2.0 | 5 votes |
@Test public void createThingWithBridge() { ThingUID bridgeUID = new ThingUID("binding:bridge:1"); ThingType thingType = ThingTypeBuilder.instance("bindingId", "thingTypeId", "label").build(); Configuration configuration = new Configuration(); Thing thing = ThingFactory.createThing(thingType, new ThingUID(thingType.getUID(), "thingId"), configuration, bridgeUID); assertThat(thing.getBridgeUID(), is(equalTo(bridgeUID))); }
Example #30
Source File: SonosHandlerFactory.java From smarthome with Eclipse Public License 2.0 | 5 votes |
@Override public Thing createThing(ThingTypeUID thingTypeUID, Configuration configuration, ThingUID thingUID, ThingUID bridgeUID) { if (SonosBindingConstants.SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID)) { ThingUID sonosDeviceUID = getPlayerUID(thingTypeUID, thingUID, configuration); logger.debug("Creating a sonos thing with ID '{}'", sonosDeviceUID); return super.createThing(thingTypeUID, configuration, sonosDeviceUID, null); } throw new IllegalArgumentException( "The thing type " + thingTypeUID + " is not supported by the sonos binding."); }