org.eclipse.smarthome.core.thing.ThingTypeUID Java Examples
The following examples show how to use
org.eclipse.smarthome.core.thing.ThingTypeUID.
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: ThingTypeBuilder.java From smarthome with Eclipse Public License 2.0 | 6 votes |
/** * Builds and returns a new {@link BridgeType} according to the given values from this builder. * * @return a new {@link BridgeType} according to the given values from this builder. * @throws IllegalStateException if one of {@code bindingId}, {@code thingTypeId} or {@code label} are not given. */ public BridgeType buildBridge() { if (StringUtils.isBlank(bindingId)) { throw new IllegalArgumentException("The bindingId must neither be null nor empty."); } if (StringUtils.isBlank(thingTypeId)) { throw new IllegalArgumentException("The thingTypeId must neither be null nor empty."); } if (StringUtils.isBlank(label)) { throw new IllegalArgumentException("The label must neither be null nor empty."); } return new BridgeType(new ThingTypeUID(bindingId, thingTypeId), supportedBridgeTypeUIDs, label, description, category, listed, representationProperty, channelDefinitions, channelGroupDefinitions, properties, configDescriptionURI, extensibleChannelTypeIds); }
Example #2
Source File: TradfriHandlerFactory.java From smarthome with Eclipse Public License 2.0 | 6 votes |
@Override protected ThingHandler createHandler(Thing thing) { ThingTypeUID thingTypeUID = thing.getThingTypeUID(); if (GATEWAY_TYPE_UID.equals(thingTypeUID)) { TradfriGatewayHandler handler = new TradfriGatewayHandler((Bridge) thing); registerDiscoveryService(handler); return handler; } else if (THING_TYPE_DIMMER.equals(thingTypeUID) || THING_TYPE_REMOTE_CONTROL.equals(thingTypeUID)) { return new TradfriControllerHandler(thing); } else if (THING_TYPE_MOTION_SENSOR.equals(thingTypeUID)) { return new TradfriSensorHandler(thing); } else if (SUPPORTED_LIGHT_TYPES_UIDS.contains(thingTypeUID)) { return new TradfriLightHandler(thing); } else if (SUPPORTED_PLUG_TYPES_UIDS.contains(thingTypeUID)) { return new TradfriPlugHandler(thing); } return null; }
Example #3
Source File: HueThingHandlerFactory.java From smarthome with Eclipse Public License 2.0 | 6 votes |
@Override public @Nullable Thing createThing(ThingTypeUID thingTypeUID, Configuration configuration, @Nullable ThingUID thingUID, @Nullable ThingUID bridgeUID) { if (HueBridgeHandler.SUPPORTED_THING_TYPES.contains(thingTypeUID)) { return super.createThing(thingTypeUID, configuration, thingUID, null); } else if (HueLightHandler.SUPPORTED_THING_TYPES.contains(thingTypeUID)) { ThingUID hueLightUID = getLightUID(thingTypeUID, thingUID, configuration, bridgeUID); return super.createThing(thingTypeUID, configuration, hueLightUID, bridgeUID); } else if (DimmerSwitchHandler.SUPPORTED_THING_TYPES.contains(thingTypeUID) || TapSwitchHandler.SUPPORTED_THING_TYPES.contains(thingTypeUID) || PresenceHandler.SUPPORTED_THING_TYPES.contains(thingTypeUID) || TemperatureHandler.SUPPORTED_THING_TYPES.contains(thingTypeUID) || LightLevelHandler.SUPPORTED_THING_TYPES.contains(thingTypeUID)) { ThingUID hueSensorUID = getSensorUID(thingTypeUID, thingUID, configuration, bridgeUID); return super.createThing(thingTypeUID, configuration, hueSensorUID, bridgeUID); } throw new IllegalArgumentException("The thing type " + thingTypeUID + " is not supported by the hue binding."); }
Example #4
Source File: DiscoveryResultImpl.java From smarthome with Eclipse Public License 2.0 | 6 votes |
/** * Creates a new instance of this class with the specified parameters. * * @param thingTypeUID the {@link ThingTypeUID} * @param thingUID the Thing UID to be set (must not be null). If a {@code Thing} disappears and is discovered * again, the same {@code Thing} ID must be created. A typical {@code Thing} ID could be the serial * number. It's usually <i>not</i> a product name. * @param properties the properties to be set (could be null or empty) * @param representationProperty the representationProperty to be set (could be null or empty) * @param label the human readable label to set (could be null or empty) * @param bridgeUID the unique bridge ID to be set * @param timeToLive time to live in seconds * * @throws IllegalArgumentException * if the Thing type UID or the Thing UID is null */ public DiscoveryResultImpl(ThingTypeUID thingTypeUID, ThingUID thingUID, ThingUID bridgeUID, Map<String, Object> properties, String representationProperty, String label, long timeToLive) throws IllegalArgumentException { if (thingUID == null) { throw new IllegalArgumentException("The thing UID must not be null!"); } if (timeToLive < 1 && timeToLive != TTL_UNLIMITED) { throw new IllegalArgumentException("The ttl must not be 0 or negative!"); } this.thingUID = thingUID; this.thingTypeUID = thingTypeUID; this.bridgeUID = bridgeUID; this.properties = Collections .unmodifiableMap((properties != null) ? new HashMap<>(properties) : new HashMap<String, Object>()); this.representationProperty = representationProperty; this.label = label == null ? "" : label; this.timestamp = new Date().getTime(); this.timeToLive = timeToLive; this.flag = DiscoveryResultFlag.NEW; }
Example #5
Source File: GenericWemoOSGiTest.java From smarthome with Eclipse Public License 2.0 | 6 votes |
protected Thing createThing(ThingTypeUID thingTypeUID, String channelID, String itemAcceptedType, WemoHttpCall wemoHttpCaller) { Configuration configuration = new Configuration(); configuration.put(WemoBindingConstants.UDN, DEVICE_UDN); 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(); thing = ThingBuilder.create(thingTypeUID, thingUID).withConfiguration(configuration).withChannel(channel) .build(); managedThingProvider.add(thing); ThingHandler handler = thing.getHandler(); if (handler != null) { AbstractWemoHandler h = (AbstractWemoHandler) handler; h.setWemoHttpCaller(wemoHttpCaller); } return thing; }
Example #6
Source File: BindingBaseClassesOSGiTest.java From smarthome with Eclipse Public License 2.0 | 6 votes |
private void registerThingTypeAndConfigDescription() { ThingType thingType = ThingTypeBuilder.instance(new ThingTypeUID(BINDING_ID, THING_TYPE_ID), "label") .withConfigDescriptionURI(configDescriptionUri()).build(); ConfigDescription configDescription = new ConfigDescription(configDescriptionUri(), singletonList(ConfigDescriptionParameterBuilder .create("parameter", ConfigDescriptionParameter.Type.TEXT).withRequired(true).build())); ThingTypeProvider thingTypeProvider = mock(ThingTypeProvider.class); when(thingTypeProvider.getThingType(ArgumentMatchers.any(ThingTypeUID.class), ArgumentMatchers.any(Locale.class))).thenReturn(thingType); registerService(thingTypeProvider); ThingTypeRegistry thingTypeRegistry = mock(ThingTypeRegistry.class); when(thingTypeRegistry.getThingType(ArgumentMatchers.any(ThingTypeUID.class))).thenReturn(thingType); registerService(thingTypeRegistry); ConfigDescriptionProvider configDescriptionProvider = mock(ConfigDescriptionProvider.class); when(configDescriptionProvider.getConfigDescription(ArgumentMatchers.any(URI.class), ArgumentMatchers.nullable(Locale.class))).thenReturn(configDescription); registerService(configDescriptionProvider); }
Example #7
Source File: ZonePlayerHandler.java From smarthome with Eclipse Public License 2.0 | 6 votes |
protected ZonePlayerHandler getHandlerByName(String remotePlayerName) throws IllegalStateException { if (thingRegistry != null) { for (ThingTypeUID supportedThingType : SonosBindingConstants.SUPPORTED_THING_TYPES_UIDS) { Thing thing = thingRegistry.get(new ThingUID(supportedThingType, remotePlayerName)); if (thing != null) { return (ZonePlayerHandler) thing.getHandler(); } } Collection<Thing> allThings = thingRegistry.getAll(); for (Thing aThing : allThings) { if (SonosBindingConstants.SUPPORTED_THING_TYPES_UIDS.contains(aThing.getThingTypeUID()) && aThing.getConfiguration().get(ZonePlayerConfiguration.UDN).equals(remotePlayerName)) { return (ZonePlayerHandler) aThing.getHandler(); } } } throw new IllegalStateException("Could not find handler for " + remotePlayerName); }
Example #8
Source File: OpenWeatherMapHandlerFactory.java From smarthome with Eclipse Public License 2.0 | 6 votes |
@Override protected @Nullable ThingHandler createHandler(Thing thing) { ThingTypeUID thingTypeUID = thing.getThingTypeUID(); if (THING_TYPE_WEATHER_API.equals(thingTypeUID)) { OpenWeatherMapAPIHandler handler = new OpenWeatherMapAPIHandler((Bridge) thing, httpClient, localeProvider); // register discovery service OpenWeatherMapDiscoveryService discoveryService = new OpenWeatherMapDiscoveryService(handler, locationProvider, localeProvider, i18nProvider); discoveryServiceRegs.put(handler.getThing().getUID(), bundleContext .registerService(DiscoveryService.class.getName(), discoveryService, new Hashtable<>())); return handler; } else if (THING_TYPE_WEATHER_AND_FORECAST.equals(thingTypeUID)) { return new OpenWeatherMapWeatherAndForecastHandler(thing); } else if (THING_TYPE_UVINDEX.equals(thingTypeUID)) { return new OpenWeatherMapUVIndexHandler(thing); } return null; }
Example #9
Source File: SonyAudioHandlerFactory.java From smarthome with Eclipse Public License 2.0 | 6 votes |
@Override protected ThingHandler createHandler(Thing thing) { ThingTypeUID thingTypeUID = thing.getThingTypeUID(); switch (thingTypeUID.getId()) { case SonyAudioBindingConstants.SONY_TYPE_STRDN1080: return new StrDn1080Handler(thing, webSocketClient); case SonyAudioBindingConstants.SONY_TYPE_HTCT800: return new HtCt800Handler(thing, webSocketClient); case SonyAudioBindingConstants.SONY_TYPE_HTST5000: return new HtSt5000Handler(thing, webSocketClient); case SonyAudioBindingConstants.SONY_TYPE_HTZ9F: return new HtZ9fHandler(thing, webSocketClient); case SonyAudioBindingConstants.SONY_TYPE_HTZF9: return new HtZf9Handler(thing, webSocketClient); case SonyAudioBindingConstants.SONY_TYPE_HTMT500: return new HtMt500Handler(thing, webSocketClient); case SonyAudioBindingConstants.SONY_TYPE_SRSZR5: return new SrsZr5Handler(thing, webSocketClient); default: return null; } }
Example #10
Source File: ThingTypeXmlResult.java From smarthome with Eclipse Public License 2.0 | 6 votes |
public ThingTypeXmlResult(ThingTypeUID thingTypeUID, List<String> supportedBridgeTypeUIDs, String label, String description, String category, boolean listed, List<String> extensibleChannelTypeIds, List<ChannelXmlResult>[] channelTypeReferenceObjects, List<NodeValue> properties, String representationProperty, Object[] configDescriptionObjects) { this.thingTypeUID = thingTypeUID; this.supportedBridgeTypeUIDs = supportedBridgeTypeUIDs; this.label = label; this.description = description; this.category = category; this.listed = listed; this.extensibleChannelTypeIds = extensibleChannelTypeIds; this.representationProperty = representationProperty; this.channelTypeReferences = channelTypeReferenceObjects[0]; this.channelGroupTypeReferences = channelTypeReferenceObjects[1]; this.properties = properties; this.configDescriptionURI = (URI) configDescriptionObjects[0]; this.configDescription = (ConfigDescription) configDescriptionObjects[1]; }
Example #11
Source File: InboxConsoleCommandExtension.java From smarthome with Eclipse Public License 2.0 | 6 votes |
private void clearInboxEntries(Console console, List<DiscoveryResult> discoveryResults) { if (discoveryResults.isEmpty()) { console.println("No inbox entries found."); } for (DiscoveryResult discoveryResult : discoveryResults) { ThingTypeUID thingTypeUID = discoveryResult.getThingTypeUID(); ThingUID thingUID = discoveryResult.getThingUID(); String label = discoveryResult.getLabel(); DiscoveryResultFlag flag = discoveryResult.getFlag(); ThingUID bridgeId = discoveryResult.getBridgeUID(); Map<String, Object> properties = discoveryResult.getProperties(); console.println(String.format("REMOVED [%s]: %s [label=%s, thingId=%s, bridgeId=%s, properties=%s]", flag.name(), thingTypeUID, label, thingUID, bridgeId, properties)); inbox.remove(thingUID); } }
Example #12
Source File: FirmwareImpl.java From smarthome with Eclipse Public License 2.0 | 6 votes |
/** * Constructs new firmware by the given meta information. * * @param thingTypeUID thing type UID, that this firmware is associated with (not null) * @param vendor the vendor of the firmware (can be null) * @param model the model of the firmware (can be null) * @param modelRestricted whether the firmware is restricted to a particular model * @param description the description of the firmware (can be null) * @param version the version of the firmware (not null) * @param prerequisiteVersion the prerequisite version of the firmware (can be null) * @param firmwareRestriction {@link FirmwareRestriction} for applying an additional restriction on * the firmware (can be null). If null, a default function will be used to return always true * @param changelog the changelog of the firmware (can be null) * @param onlineChangelog the URL the an online changelog of the firmware (can be null) * @param inputStream the input stream for the binary content of the firmware (can be null) * @param md5Hash the MD5 hash value of the firmware (can be null) * @param properties the immutable properties of the firmware (can be null) * @throws IllegalArgumentException if the ThingTypeUID or the firmware version are null */ public FirmwareImpl(ThingTypeUID thingTypeUID, @Nullable String vendor, @Nullable String model, boolean modelRestricted, @Nullable String description, String version, @Nullable String prerequisiteVersion, @Nullable FirmwareRestriction firmwareRestriction, @Nullable String changelog, @Nullable URL onlineChangelog, @Nullable InputStream inputStream, @Nullable String md5Hash, @Nullable Map<String, String> properties) { ParameterChecks.checkNotNull(thingTypeUID, "ThingTypeUID"); this.thingTypeUID = thingTypeUID; ParameterChecks.checkNotNullOrEmpty(version, "Firmware version"); this.version = new Version(version); this.vendor = vendor; this.model = model; this.modelRestricted = modelRestricted; this.description = description; this.prerequisiteVersion = prerequisiteVersion != null ? new Version(prerequisiteVersion) : null; this.firmwareRestriction = firmwareRestriction != null ? firmwareRestriction : t -> true; this.changelog = changelog; this.onlineChangelog = onlineChangelog; this.inputStream = inputStream; this.md5Hash = md5Hash; this.properties = Collections.unmodifiableMap(properties != null ? properties : Collections.emptyMap()); }
Example #13
Source File: InboxConsoleCommandExtension.java From smarthome with Eclipse Public License 2.0 | 6 votes |
private void printInboxEntries(Console console, List<DiscoveryResult> discoveryResults) { if (discoveryResults.isEmpty()) { console.println("No inbox entries found."); } for (DiscoveryResult discoveryResult : discoveryResults) { ThingTypeUID thingTypeUID = discoveryResult.getThingTypeUID(); ThingUID thingUID = discoveryResult.getThingUID(); String label = discoveryResult.getLabel(); DiscoveryResultFlag flag = discoveryResult.getFlag(); ThingUID bridgeId = discoveryResult.getBridgeUID(); Map<String, Object> properties = discoveryResult.getProperties(); String representationProperty = discoveryResult.getRepresentationProperty(); String timestamp = new Date(discoveryResult.getTimestamp()).toString(); String timeToLive = discoveryResult.getTimeToLive() == DiscoveryResult.TTL_UNLIMITED ? "UNLIMITED" : "" + discoveryResult.getTimeToLive(); console.println(String.format( "%s [%s]: %s [thingId=%s, bridgeId=%s, properties=%s, representationProperty=%s, timestamp=%s, timeToLive=%s]", flag.name(), thingTypeUID, label, thingUID, bridgeId, properties, representationProperty, timestamp, timeToLive)); } }
Example #14
Source File: DiscoveryServiceRegistryOSGiTest.java From smarthome with Eclipse Public License 2.0 | 5 votes |
@Test public void testThingDiscovered() { ScanListener mockScanListener = mock(ScanListener.class); discoveryServiceRegistry.addDiscoveryListener(mockDiscoveryListener); discoveryServiceRegistry.startScan(new ThingTypeUID(ANY_BINDING_ID_1, ANY_THING_TYPE_1), mockScanListener); waitForAssert(() -> verify(mockScanListener, times(1)).onFinished()); verify(mockDiscoveryListener, times(1)).thingDiscovered(any(), any()); verifyNoMoreInteractions(mockScanListener); verifyNoMoreInteractions(mockDiscoveryListener); }
Example #15
Source File: ThingTypeConverter.java From smarthome with Eclipse Public License 2.0 | 5 votes |
@Override protected ThingTypeXmlResult unmarshalType(HierarchicalStreamReader reader, UnmarshallingContext context, Map<String, String> attributes, NodeIterator nodeIterator) throws ConversionException { ThingTypeXmlResult thingTypeXmlResult = new ThingTypeXmlResult( new ThingTypeUID(super.getUID(attributes, context)), readSupportedBridgeTypeUIDs(nodeIterator, context), super.readLabel(nodeIterator), super.readDescription(nodeIterator), readCategory(nodeIterator), getListed(attributes), getExtensibleChannelTypeIds(attributes), getChannelTypeReferenceObjects(nodeIterator), getProperties(nodeIterator), getRepresentationProperty(nodeIterator), super.getConfigDescriptionObjects(nodeIterator)); return thingTypeXmlResult; }
Example #16
Source File: DsDeviceThingTypeProvider.java From smarthome with Eclipse Public License 2.0 | 5 votes |
@Override public Collection<ThingType> getThingTypes(Locale locale) { List<ThingType> thingTypes = new LinkedList<ThingType>(); for (SupportedThingTypes supportedThingType : SupportedThingTypes.values()) { thingTypes.add(getThingType( new ThingTypeUID(DigitalSTROMBindingConstants.BINDING_ID, supportedThingType.toString()), locale)); } return thingTypes; }
Example #17
Source File: DigitalSTROMHandlerFactory.java From smarthome with Eclipse Public License 2.0 | 5 votes |
private ThingUID getDeviceUID(ThingTypeUID thingTypeUID, ThingUID thingUID, Configuration configuration, ThingUID bridgeUID) { if (thingUID == null && StringUtils.isNotBlank((String) configuration.get(DEVICE_DSID))) { return new ThingUID(thingTypeUID, bridgeUID, configuration.get(DEVICE_DSID).toString()); } return thingUID; }
Example #18
Source File: UidUtils.java From smarthome with Eclipse Public License 2.0 | 5 votes |
/** * Generates the ThingTypeUID for the given device. If it's a Homegear device, add a prefix because a Homegear * device has more datapoints. */ public static ThingTypeUID generateThingTypeUID(HmDevice device) { if (!device.isGatewayExtras() && device.getGatewayId().equals(HmGatewayInfo.ID_HOMEGEAR)) { return new ThingTypeUID(BINDING_ID, String.format("HG-%s", device.getType())); } else { return new ThingTypeUID(BINDING_ID, device.getType()); } }
Example #19
Source File: IpCameraDiscoveryService.java From IpCamera with Eclipse Public License 2.0 | 5 votes |
public void newCameraFound(String brand, String hostname, int onvifPort) { ThingTypeUID thingtypeuid = new ThingTypeUID("ipcamera", brand); ThingUID thingUID = new ThingUID(thingtypeuid, hostname.replace(".", "")); DiscoveryResult discoveryResult = DiscoveryResultBuilder.create(thingUID) .withProperty(CONFIG_IPADDRESS, hostname).withProperty(CONFIG_ONVIF_PORT, onvifPort) .withLabel(brand + " Camera @" + hostname).build(); thingDiscovered(discoveryResult); }
Example #20
Source File: ThingManagerOSGiTest.java From smarthome with Eclipse Public License 2.0 | 5 votes |
@Test public void thingManagerCallsRegisterHandlerForAddedThing() { ThingHandler thingHandler = mock(ThingHandler.class); when(thingHandler.getThing()).thenReturn(thing); ThingHandlerFactory thingHandlerFactory = mock(ThingHandlerFactory.class); when(thingHandlerFactory.supportsThingType(any(ThingTypeUID.class))).thenReturn(true); when(thingHandlerFactory.registerHandler(any(Thing.class))).thenReturn(thingHandler); registerService(thingHandlerFactory); managedThingProvider.add(thing); verify(thingHandlerFactory, times(1)).registerHandler(thing); }
Example #21
Source File: DiscoveryServiceRegistryOSGiTest.java From smarthome with Eclipse Public License 2.0 | 5 votes |
@Test public void testAbortScan_known() { ScanListener mockScanListener = mock(ScanListener.class); assertTrue(discoveryServiceRegistry.startScan(new ThingTypeUID(ANY_BINDING_ID_1, ANY_THING_TYPE_1), mockScanListener)); assertTrue(discoveryServiceRegistry.abortScan(new ThingTypeUID(ANY_BINDING_ID_1, ANY_THING_TYPE_1))); waitForAssert(() -> verify(mockScanListener, times(1)).onErrorOccurred(isA(Exception.class))); verifyNoMoreInteractions(mockScanListener); }
Example #22
Source File: WemoDiscoveryParticipantTest.java From smarthome with Eclipse Public License 2.0 | 5 votes |
public void testDiscoveryResult(ThingTypeUID thingTypeUid) throws MalformedURLException, ValidationException, URISyntaxException { String thingTypeId = thingTypeUid.getId(); RemoteDevice device = createUpnpDevice(thingTypeId); DiscoveryResult result = participant.createResult(device); assertNotNull(result); assertThat(result.getThingUID(), is(new ThingUID(thingTypeUid, DEVICE_UDN))); assertThat(result.getThingTypeUID(), is(thingTypeUid)); assertThat(result.getBridgeUID(), is(nullValue())); assertThat(result.getProperties().get(WemoBindingConstants.UDN), is(DEVICE_UDN.toString())); assertThat(result.getRepresentationProperty(), is(WemoBindingConstants.UDN)); }
Example #23
Source File: PersistentInbox.java From smarthome with Eclipse Public License 2.0 | 5 votes |
@Override public @Nullable Thing approve(ThingUID thingUID, @Nullable String label) { if (thingUID == null) { throw new IllegalArgumentException("Thing UID must not be null"); } List<DiscoveryResult> results = stream().filter(forThingUID(thingUID)).collect(Collectors.toList()); if (results.isEmpty()) { throw new IllegalArgumentException("No Thing with UID " + thingUID.getAsString() + " in inbox"); } DiscoveryResult result = results.get(0); final Map<String, String> properties = new HashMap<>(); final Map<String, Object> configParams = new HashMap<>(); getPropsAndConfigParams(result, properties, configParams); final Configuration config = new Configuration(configParams); ThingTypeUID thingTypeUID = result.getThingTypeUID(); Thing newThing = ThingFactory.createThing(thingUID, config, properties, result.getBridgeUID(), thingTypeUID, this.thingHandlerFactories); if (newThing == null) { logger.warn("Cannot create thing. No binding found that supports creating a thing" + " of type {}.", thingTypeUID); return null; } if (label != null && !label.isEmpty()) { newThing.setLabel(label); } else { newThing.setLabel(result.getLabel()); } addThingSafely(newThing); return newThing; }
Example #24
Source File: PersistentInbox.java From smarthome with Eclipse Public License 2.0 | 5 votes |
private boolean synchronizeConfiguration(ThingTypeUID thingTypeUID, Map<String, Object> properties, Configuration config) { boolean configUpdated = false; final Set<Map.Entry<String, Object>> propertySet = properties.entrySet(); final ThingType thingType = thingTypeRegistry.getThingType(thingTypeUID); final List<ConfigDescriptionParameter> configDescParams = getConfigDescParams(thingType); for (Map.Entry<String, Object> propertyEntry : propertySet) { final String propertyKey = propertyEntry.getKey(); final Object propertyValue = propertyEntry.getValue(); // Check if the key is present in the configuration. if (!config.containsKey(propertyKey)) { continue; } // Normalize first ConfigDescriptionParameter configDescParam = getConfigDescriptionParam(configDescParams, propertyKey); Object normalizedValue = ConfigUtil.normalizeType(propertyValue, configDescParam); // If the value is equal to the one of the configuration, there is nothing to do. if (Objects.equals(normalizedValue, config.get(propertyKey))) { continue; } // - the given key is part of the configuration // - the values differ // update value config.put(propertyKey, normalizedValue); configUpdated = true; } return configUpdated; }
Example #25
Source File: BridgeTypeXmlResult.java From smarthome with Eclipse Public License 2.0 | 5 votes |
public BridgeTypeXmlResult(ThingTypeUID bridgeTypeUID, List<String> supportedBridgeTypeUIDs, String label, String description, String category, boolean listed, List<String> extensibleChannelTypeIds, List<ChannelXmlResult>[] channelTypeReferenceObjects, List<NodeValue> properties, String representationProperty, Object[] configDescriptionObjects) { super(bridgeTypeUID, supportedBridgeTypeUIDs, label, description, category, listed, extensibleChannelTypeIds, channelTypeReferenceObjects, properties, representationProperty, configDescriptionObjects); }
Example #26
Source File: ThingManagerOSGiTest.java From smarthome with Eclipse Public License 2.0 | 5 votes |
@Test public void thingManagerHandlesThingStatusUpdatesUninitializedAndInitializingCorrectly() { registerThingTypeProvider(); ThingHandler thingHandler = mock(ThingHandler.class); when(thingHandler.getThing()).thenReturn(thing); ThingHandlerFactory thingHandlerFactory = mock(ThingHandlerFactory.class); when(thingHandlerFactory.supportsThingType(any(ThingTypeUID.class))).thenReturn(true); when(thingHandlerFactory.registerHandler(any(Thing.class))).thenReturn(thingHandler); registerService(thingHandlerFactory); final ThingStatusInfo uninitializedNone = ThingStatusInfoBuilder .create(ThingStatus.UNINITIALIZED, ThingStatusDetail.NONE).build(); assertThat(thing.getStatusInfo(), is(uninitializedNone)); managedThingProvider.add(thing); final ThingStatusInfo initializingNone = ThingStatusInfoBuilder .create(ThingStatus.INITIALIZING, ThingStatusDetail.NONE).build(); waitForAssert(() -> assertThat(thing.getStatusInfo(), is(initializingNone))); unregisterService(thingHandlerFactory); final ThingStatusInfo uninitializedHandlerMissing = ThingStatusInfoBuilder .create(ThingStatus.UNINITIALIZED, ThingStatusDetail.HANDLER_MISSING_ERROR).build(); waitForAssert(() -> assertThat(thing.getStatusInfo(), is(uninitializedHandlerMissing))); }
Example #27
Source File: AutomaticInboxProcessor.java From smarthome with Eclipse Public License 2.0 | 5 votes |
private void ignoreInInbox(ThingTypeUID thingtypeUID, String representationValue) { List<DiscoveryResult> results = inbox.stream().filter(withRepresentationPropertyValue(representationValue)) .filter(forThingTypeUID(thingtypeUID)).collect(Collectors.toList()); if (results.size() == 1) { logger.debug("Auto-ignoring the inbox entry for the representation value {}", representationValue); inbox.setFlag(results.get(0).getThingUID(), DiscoveryResultFlag.IGNORED); } }
Example #28
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."); }
Example #29
Source File: HomematicTypeGeneratorImpl.java From smarthome with Eclipse Public License 2.0 | 5 votes |
/** * Creates the ThingType for the given device. */ private ThingType createThingType(HmDevice device, List<ChannelGroupType> groupTypes) { String label = MetadataUtils.getDeviceName(device); String description = String.format("%s (%s)", label, device.getType()); List<String> supportedBridgeTypeUids = new ArrayList<String>(); supportedBridgeTypeUids.add(THING_TYPE_BRIDGE.toString()); ThingTypeUID thingTypeUID = UidUtils.generateThingTypeUID(device); Map<String, String> properties = new HashMap<String, String>(); properties.put(Thing.PROPERTY_VENDOR, PROPERTY_VENDOR_NAME); properties.put(Thing.PROPERTY_MODEL_ID, device.getType()); URI configDescriptionURI = getConfigDescriptionURI(device); if (configDescriptionProvider.getInternalConfigDescription(configDescriptionURI) == null) { generateConfigDescription(device, configDescriptionURI); } List<ChannelGroupDefinition> groupDefinitions = new ArrayList<ChannelGroupDefinition>(); for (ChannelGroupType groupType : groupTypes) { String id = StringUtils.substringAfterLast(groupType.getUID().getId(), "_"); groupDefinitions.add(new ChannelGroupDefinition(id, groupType.getUID())); } return ThingTypeBuilder.instance(thingTypeUID, label).withSupportedBridgeTypeUIDs(supportedBridgeTypeUids) .withDescription(description).withChannelGroupDefinitions(groupDefinitions).withProperties(properties) .withRepresentationProperty(Thing.PROPERTY_SERIAL_NUMBER).withConfigDescriptionURI(configDescriptionURI) .build(); }
Example #30
Source File: HueThingHandlerFactory.java From smarthome with Eclipse Public License 2.0 | 5 votes |
private ThingUID getLightUID(ThingTypeUID thingTypeUID, @Nullable ThingUID thingUID, Configuration configuration, @Nullable ThingUID bridgeUID) { if (thingUID != null) { return thingUID; } else { return getThingUID(thingTypeUID, configuration.get(LIGHT_ID).toString(), bridgeUID); } }