Java源码示例:org.eclipse.smarthome.core.thing.ThingTypeUID

示例1
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);
}
 
示例2
/**
 * 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());
}
 
示例3
@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;
}
 
示例4
@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.");
}
 
示例5
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);
}
 
示例6
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));

    }
}
 
示例7
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);
    }
}
 
示例8
/**
 * 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;
}
 
示例9
/**
 * 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);
}
 
示例10
@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;
}
 
示例11
@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;
    }
}
 
示例12
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;
}
 
示例13
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];
}
 
示例14
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);
}
 
示例15
private synchronized void onSubscription() {
    if (service.isRegistered(this)) {
        logger.debug("Checking WeMo GENA subscription for '{}'", this);

        ThingTypeUID thingTypeUID = thing.getThingTypeUID();
        String subscription = "basicevent1";

        if ((subscriptionState.get(subscription) == null) || !subscriptionState.get(subscription).booleanValue()) {
            logger.debug("Setting up GENA subscription {}: Subscribing to service {}...", getUDN(), subscription);
            service.addSubscription(this, subscription, SUBSCRIPTION_DURATION);
            subscriptionState.put(subscription, true);
        }

        if (thingTypeUID.equals(THING_TYPE_INSIGHT)) {
            subscription = "insight1";
            if ((subscriptionState.get(subscription) == null)
                    || !subscriptionState.get(subscription).booleanValue()) {
                logger.debug("Setting up GENA subscription {}: Subscribing to service {}...", getUDN(),
                        subscription);
                service.addSubscription(this, subscription, SUBSCRIPTION_DURATION);
                subscriptionState.put(subscription, true);
            }
        }
    } else {
        logger.debug("Setting up WeMo GENA subscription for '{}' FAILED - service.isRegistered(this) is FALSE",
                this);
    }
}
 
示例16
/**
 * Creates a new instance of this class with the specified parameters.
 *
 * @deprecated Use {@link ThingTypeBuilder}.buildBridge() instead.
 *
 * @throws IllegalArgumentException if the UID is null or empty,
 *             or the the meta information is null
 */
@Deprecated
public BridgeType(ThingTypeUID uid, @Nullable List<String> supportedBridgeTypeUIDs, String label,
        @Nullable String description, @Nullable String category, boolean listed,
        @Nullable String representationProperty, @Nullable List<ChannelDefinition> channelDefinitions,
        @Nullable List<ChannelGroupDefinition> channelGroupDefinitions, @Nullable Map<String, String> properties,
        @Nullable URI configDescriptionURI) throws IllegalArgumentException {
    super(uid, supportedBridgeTypeUIDs, label, description, category, listed, representationProperty,
            channelDefinitions, channelGroupDefinitions, properties, configDescriptionURI);
}
 
示例17
@Test
public void createThingWithChannels() {
    ChannelType channelType1 = ChannelTypeBuilder
            .state(new ChannelTypeUID("bindingId:channelTypeId1"), "channelLabel", "Color")
            .withTags(Stream.of("tag1", "tag2").collect(toSet())).build();

    ChannelType channelType2 = ChannelTypeBuilder
            .state(new ChannelTypeUID("bindingId:channelTypeId2"), "channelLabel2", "Dimmer").withTag("tag3")
            .build();

    registerChannelTypes(Stream.of(channelType1, channelType2).collect(toSet()), emptyList());

    ChannelDefinition channelDef1 = new ChannelDefinitionBuilder("ch1", channelType1.getUID()).build();
    ChannelDefinition channelDef2 = new ChannelDefinitionBuilder("ch2", channelType2.getUID()).build();

    ThingType thingType = ThingTypeBuilder.instance(new ThingTypeUID("bindingId:thingType"), "label")
            .withSupportedBridgeTypeUIDs(emptyList())
            .withChannelDefinitions(Stream.of(channelDef1, channelDef2).collect(toList())).build();
    Configuration configuration = new Configuration();

    Thing thing = ThingFactory.createThing(thingType, new ThingUID(thingType.getUID(), "thingId"), configuration);

    assertThat(thing.getChannels().size(), is(2));
    assertThat(thing.getChannels().get(0).getUID().toString(), is(equalTo("bindingId:thingType:thingId:ch1")));
    assertThat(thing.getChannels().get(0).getAcceptedItemType(), is(equalTo("Color")));
    assertThat(thing.getChannels().get(0).getDefaultTags().contains("tag1"), is(true));
    assertThat(thing.getChannels().get(0).getDefaultTags().contains("tag2"), is(true));
    assertThat(thing.getChannels().get(0).getDefaultTags().contains("tag3"), is(false));
    assertThat(thing.getChannels().get(1).getDefaultTags().contains("tag1"), is(false));
    assertThat(thing.getChannels().get(1).getDefaultTags().contains("tag2"), is(false));
    assertThat(thing.getChannels().get(1).getDefaultTags().contains("tag3"), is(true));
}
 
示例18
private Map<String, Object> normalizeConfiguration(Map<String, Object> properties, ThingTypeUID thingTypeUID,
        ThingUID thingUID) {
    if (properties == null || properties.isEmpty()) {
        return properties;
    }

    ThingType thingType = thingTypeRegistry.getThingType(thingTypeUID);
    if (thingType == null) {
        return properties;
    }

    List<ConfigDescription> configDescriptions = new ArrayList<>(2);
    if (thingType.getConfigDescriptionURI() != null) {
        ConfigDescription typeConfigDesc = configDescRegistry
                .getConfigDescription(thingType.getConfigDescriptionURI());
        if (typeConfigDesc != null) {
            configDescriptions.add(typeConfigDesc);
        }
    }
    if (getConfigDescriptionURI(thingUID) != null) {
        ConfigDescription thingConfigDesc = configDescRegistry
                .getConfigDescription(getConfigDescriptionURI(thingUID));
        if (thingConfigDesc != null) {
            configDescriptions.add(thingConfigDesc);
        }
    }

    if (configDescriptions.isEmpty()) {
        return properties;
    }

    return ConfigUtil.normalizeTypes(properties, configDescriptions);
}
 
示例19
@Override
public boolean supportsThingType(ThingTypeUID thingTypeUID) {
    return BridgeHandler.SUPPORTED_THING_TYPES.contains(thingTypeUID)
            || SceneHandler.SUPPORTED_THING_TYPES.contains(thingTypeUID)
            || DeviceHandler.SUPPORTED_THING_TYPES.contains(thingTypeUID)
            || ZoneTemperatureControlHandler.SUPPORTED_THING_TYPES.contains(thingTypeUID)
            || CircuitHandler.SUPPORTED_THING_TYPES.contains(thingTypeUID);
}
 
示例20
@Override
public @Nullable Thing createThing(ThingTypeUID thingTypeUID, Configuration configuration,
        @Nullable ThingUID thingUID, @Nullable ThingUID bridgeUID) {
    if (SUPPORTED_BRIDGE_TYPES.contains(thingTypeUID)) {
        ThingUID hueBridgeUID = getBridgeThingUID(thingTypeUID, thingUID, configuration);
        return super.createThing(thingTypeUID, configuration, hueBridgeUID, null);
    }
    if (SUPPORTED_THING_TYPES.contains(thingTypeUID)) {
        ThingUID hueLightUID = getLightUID(thingTypeUID, thingUID, configuration, bridgeUID);
        return super.createThing(thingTypeUID, configuration, hueLightUID, bridgeUID);
    }
    throw new IllegalArgumentException("The thing type " + thingTypeUID + " is not supported by the hue binding.");
}
 
示例21
public ThingType createLocalizedThingType(Bundle bundle, ThingType thingType, @Nullable Locale locale) {
    ThingTypeUID thingTypeUID = thingType.getUID();
    String label = thingTypeI18nUtil.getLabel(bundle, thingTypeUID, thingType.getLabel(), locale);
    String description = thingTypeI18nUtil.getDescription(bundle, thingTypeUID, thingType.getDescription(), locale);

    List<ChannelDefinition> localizedChannelDefinitions = channelI18nUtil.createLocalizedChannelDefinitions(bundle,
            thingType.getChannelDefinitions(),
            channelDefinition -> thingTypeI18nUtil.getChannelLabel(bundle, thingTypeUID, channelDefinition,
                    channelDefinition.getLabel(), locale),
            channelDefinition -> thingTypeI18nUtil.getChannelDescription(bundle, thingTypeUID, channelDefinition,
                    channelDefinition.getDescription(), locale),
            locale);

    List<ChannelGroupDefinition> localizedChannelGroupDefinitions = createLocalizedChannelGroupDefinitions(bundle,
            thingType.getChannelGroupDefinitions(),
            channelGroupDefinition -> thingTypeI18nUtil.getChannelGroupLabel(bundle, thingTypeUID,
                    channelGroupDefinition, channelGroupDefinition.getLabel(), locale),
            channelGroupDefinition -> thingTypeI18nUtil.getChannelGroupDescription(bundle, thingTypeUID,
                    channelGroupDefinition, channelGroupDefinition.getDescription(), locale),
            locale);

    ThingTypeBuilder builder = ThingTypeBuilder.instance(thingType);
    if (label != null) {
        builder.withLabel(label);
    }
    if (description != null) {
        builder.withDescription(description);
    }
    builder.withChannelDefinitions(localizedChannelDefinitions)
            .withChannelGroupDefinitions(localizedChannelGroupDefinitions);

    if (thingType instanceof BridgeType) {
        return builder.buildBridge();
    }

    return builder.build();
}
 
示例22
private AtomicReference<ThingHandlerCallback> initializeThingHandlerCallback() throws Exception {
    registerThingTypeProvider();
    registerChannelTypeProvider();
    registerChannelGroupTypeProvider();
    AtomicReference<ThingHandlerCallback> thc = new AtomicReference<>();
    ThingHandlerFactory thingHandlerFactory = new BaseThingHandlerFactory() {
        @Override
        public boolean supportsThingType(@NonNull ThingTypeUID thingTypeUID) {
            return true;
        }

        @Override
        protected @Nullable ThingHandler createHandler(@NonNull Thing thing) {
            ThingHandler mockHandler = mock(ThingHandler.class);
            doAnswer(a -> {
                thc.set((ThingHandlerCallback) a.getArguments()[0]);
                return null;
            }).when(mockHandler).setCallback(any(ThingHandlerCallback.class));
            when(mockHandler.getThing()).thenReturn(THING);
            return mockHandler;
        }
    };
    registerService(thingHandlerFactory, ThingHandlerFactory.class.getName());
    new Thread((Runnable) () -> managedThingProvider.add(THING)).start();

    waitForAssert(() -> {
        assertNotNull(thc.get());
    });
    return thc;
}
 
示例23
private ThingUID getLightUID(ThingTypeUID thingTypeUID, @Nullable ThingUID thingUID, Configuration configuration,
        @Nullable ThingUID bridgeUID) {
    if (thingUID != null) {
        return thingUID;
    } else {
        String lightId = (String) configuration.get(LIGHT_ID);
        return new ThingUID(thingTypeUID, lightId, bridgeUID.getId());
    }
}
 
示例24
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;
    }
}
 
示例25
@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;
}
 
示例26
@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);
}
 
示例27
@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);
}
 
示例28
@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);
}
 
示例29
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));
}
 
示例30
@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;
}