org.eclipse.smarthome.core.thing.Thing Java Examples

The following examples show how to use org.eclipse.smarthome.core.thing.Thing. 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: AstroValidConfigurationTest.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
private void assertThingStatus(Configuration configuration, ThingStatus expectedStatus) {
    ThingUID thingUID = new ThingUID(THING_TYPE_SUN, TEST_SUN_THING_ID);

    Thing thing = mock(Thing.class);
    when(thing.getConfiguration()).thenReturn(configuration);
    when(thing.getUID()).thenReturn(thingUID);

    ThingHandlerCallback callback = mock(ThingHandlerCallback.class);
    CronScheduler cronScheduler = mock(CronScheduler.class);
    ThingHandler sunHandler = new SunHandler(thing, cronScheduler);
    sunHandler.setCallback(callback);

    sunHandler.initialize();

    ThingStatusInfo expectedThingStatus = new ThingStatusInfo(expectedStatus, ThingStatusDetail.NONE, null);
    verify(callback, times(1)).statusUpdated(thing, expectedThingStatus);
}
 
Example #2
Source File: FirmwareRegistryImpl.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
@Override
@Nullable
public Firmware getLatestFirmware(Thing thing, @Nullable Locale locale) {
    Locale loc = locale != null ? locale : localeProvider.getLocale();
    Collection<Firmware> firmwares = getFirmwares(thing, loc);

    if (firmwares != null) {
        Optional<Firmware> first = firmwares.stream().findFirst();

        // Used as workaround for the NonNull annotation implied to .isElse()
        if (first.isPresent()) {
            return first.get();
        }
    }

    return null;
}
 
Example #3
Source File: BridgeHandler.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void handleRemoval() {
    for (Thing thing : getThing().getThings()) {
        // Inform Thing-Child's about removed bridge.
        final ThingHandler thingHandler = thing.getHandler();
        if (thingHandler != null) {
            thingHandler.bridgeStatusChanged(ThingStatusInfoBuilder.create(ThingStatus.REMOVED).build());
        }
    }
    if (StringUtils.isNotBlank((String) super.getConfig().get(APPLICATION_TOKEN))) {
        if (connMan == null) {
            Config config = loadAndCheckConnectionData(this.getConfig());
            if (config != null) {
                this.connMan = new ConnectionManagerImpl(config, null, false);
            } else {
                updateStatus(ThingStatus.REMOVED);
                return;
            }
        }
        if (connMan.removeApplicationToken()) {
            logger.debug("Application-Token deleted");
        }
    }
    updateStatus(ThingStatus.REMOVED);
}
 
Example #4
Source File: ThingManagerOSGiJavaTest.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
private void assertThingStatus(Map<String, Object> propsThing, Map<String, Object> propsChannel, ThingStatus status,
        ThingStatusDetail statusDetail) {
    Configuration configThing = new Configuration(propsThing);
    Configuration configChannel = new Configuration(propsChannel);

    Thing thing = ThingBuilder.create(THING_TYPE_UID, THING_UID).withChannels(Collections.singletonList( //
            ChannelBuilder.create(CHANNEL_UID, "Switch").withType(CHANNEL_TYPE_UID).withConfiguration(configChannel)
                    .build() //
    )).withConfiguration(configThing).build();

    managedThingProvider.add(thing);

    waitForAssert(() -> {
        assertEquals(status, thing.getStatus());
        assertEquals(statusDetail, thing.getStatusInfo().getStatusDetail());
    });

    managedThingProvider.remove(thing.getUID());
}
 
Example #5
Source File: AutomaticInboxProcessor.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
private @Nullable String getRepresentationPropertyValueForThing(Thing thing) {
    ThingType thingType = thingTypeRegistry.getThingType(thing.getThingTypeUID());
    if (thingType != null) {
        String representationProperty = thingType.getRepresentationProperty();
        if (representationProperty == null) {
            return null;
        }
        Map<String, String> properties = thing.getProperties();
        if (properties.containsKey(representationProperty)) {
            return properties.get(representationProperty);
        }
        Configuration configuration = thing.getConfiguration();
        if (configuration.containsKey(representationProperty)) {
            return String.valueOf(configuration.get(representationProperty));
        }
    }
    return null;
}
 
Example #6
Source File: BindingBaseClassesOSGiTest.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void assertConfigurationWillBeUpdatedByDefaultImplementation() {
    SimpleThingHandlerFactory thingHandlerFactory = new SimpleThingHandlerFactory();
    thingHandlerFactory.activate(componentContext);
    registerService(thingHandlerFactory, ThingHandlerFactory.class.getName());

    final ThingRegistryChangeListener listener = new ThingRegistryChangeListener();

    try {
        thingRegistry.addRegistryChangeListener(listener);
        ThingTypeUID thingTypeUID = new ThingTypeUID("bindingId:type");
        ThingUID thingUID = new ThingUID("bindingId:type:thingId");
        Thing thing = ThingBuilder.create(thingTypeUID, thingUID).build();

        managedThingProvider.add(thing);

        thingRegistry.updateConfiguration(thingUID, singletonMap("parameter", "value"));

        waitForAssert(() -> assertThat(listener.isUpdated(), is(true)), 10000, 100);

        assertThat(listener.getThing().getConfiguration().get("parameter"), is("value"));
    } finally {
        thingRegistry.removeRegistryChangeListener(listener);
    }
}
 
Example #7
Source File: GenericThingProviderTest.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
@Test
@SuppressWarnings("null")
public void assertThatThingsCanBeEmbeddedWithinBridgesInLongNotation() {
    assertThat(thingRegistry.getAll().size(), is(0));

    String model = "Bridge hue:bridge:myBridge @ \"basement\" [ ip = \"1.2.3.4\", username = \"123\" ] {" + //
            "    hue:LCT001:bulb1 [ lightId = \"1\" ] { Switch : notification }" + //
            "}";

    modelRepository.addOrRefreshModel(TESTMODEL_NAME, new ByteArrayInputStream(model.getBytes()));
    Collection<Thing> actualThings = thingRegistry.getAll();

    assertThat(actualThings.size(), is(2));

    assertThat(actualThings.stream().filter(t -> "hue:bridge:myBridge".equals(t.getUID().toString())).findFirst()
            .get(), is(notNullValue()));
    assertThat(
            actualThings.stream().filter(t -> "hue:LCT001:bulb1".equals(t.getUID().toString())).findFirst().get(),
            is(notNullValue()));
    assertThat(actualThings.stream().filter(t -> "hue:LCT001:bulb1".equals(t.getUID().toString())).findFirst().get()
            .getBridgeUID().toString(), is(equalTo("hue:bridge:myBridge")));
}
 
Example #8
Source File: GenericWemoLightOSGiTest.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
@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 #9
Source File: TradfriHandlerFactory.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
@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 #10
Source File: CommunicationManager.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
private Profile getProfile(ItemChannelLink link, Item item, @Nullable Thing thing) {
    synchronized (profiles) {
        Profile profile = profiles.get(link.getUID());
        if (profile != null) {
            return profile;
        }
        ProfileTypeUID profileTypeUID = determineProfileTypeUID(link, item, thing);
        if (profileTypeUID != null) {
            profile = getProfileFromFactories(profileTypeUID, link, createCallback(link));
            if (profile != null) {
                profiles.put(link.getUID(), profile);
                return profile;
            }
        }
        return new NoOpProfile();
    }
}
 
Example #11
Source File: WemoHandlerOSGiTest.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void assertThatThingHandlesOnOffCommandCorrectly()
        throws MalformedURLException, URISyntaxException, ValidationException {
    Command command = OnOffType.OFF;

    WemoHttpCall mockCaller = Mockito.spy(new WemoHttpCall());
    Thing thing = createThing(THING_TYPE_UID, DEFAULT_TEST_CHANNEL, DEFAULT_TEST_CHANNEL_TYPE, mockCaller);

    waitForAssert(() -> {
        assertThat(thing.getStatus(), is(ThingStatus.ONLINE));
    });

    // The device is registered as UPnP Device after the initialization, this will ensure that the polling job will
    // not start
    addUpnpDevice(SERVICE_ID, SERVICE_NUMBER, MODEL_NAME);

    WemoHandler handler = (WemoHandler) thing.getHandler();
    assertNotNull(handler);

    ChannelUID channelUID = new ChannelUID(thing.getUID(), DEFAULT_TEST_CHANNEL);
    handler.handleCommand(channelUID, command);

    ArgumentCaptor<String> captur = ArgumentCaptor.forClass(String.class);
    verify(mockCaller, atLeastOnce()).executeCall(any(), any(), captur.capture());

    List<String> results = captur.getAllValues();
    boolean found = false;
    for (String result : results) {
        // Binary state 0 is equivalent to OFF
        if (result.contains("<BinaryState>0</BinaryState>")) {
            found = true;
            break;
        }
    }
    assertTrue(found);
}
 
Example #12
Source File: ThingManagerOSGiTest.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Test
@SuppressWarnings({ "null", "unchecked" })
public void thingManagerAllowsChangesToUnmanagedThings() throws Exception {
    ThingManager thingManager = (ThingManager) getService(ThingTypeMigrationService.class);
    assertThat(thingManager, is(notNullValue()));

    ThingProvider customThingProvider = mock(ThingProvider.class);
    when(customThingProvider.getAll()).thenReturn(Collections.singletonList(thing));

    registerService(customThingProvider);

    ThingRegistry thingRegistry = getService(ThingRegistry.class);
    RegistryChangeListener<Thing> registryChangeListener = mock(RegistryChangeListener.class);

    try {
        thingRegistry.addRegistryChangeListener(registryChangeListener);

        Field field = thingManager.getClass().getDeclaredField("thingHandlerCallback");
        field.setAccessible(true);
        ThingHandlerCallback callback = (ThingHandlerCallback) field.get(thingManager);

        callback.thingUpdated(thing);
        verify(registryChangeListener, times(1)).updated(any(Thing.class), any(Thing.class));
    } finally {
        thingRegistry.removeRegistryChangeListener(registryChangeListener);
    }
}
 
Example #13
Source File: ItemChannelLinkOSGiTest.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void assertThatGetBoundThingsReturnsThing() {
    managedItemChannelLinkProvider.add(ITEM_CHANNEL_LINK);
    Set<Thing> boundThings = itemChannelLinkRegistry.getBoundThings(ITEM);
    assertEquals(1, boundThings.size());
    assertEquals(CHANNEL_UID.getThingUID(), boundThings.stream().findFirst().get().getUID());
}
 
Example #14
Source File: ChannelItemProvider.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void added(Thing element) {
    if (!initialized) {
        return;
    }
    for (Channel channel : element.getChannels()) {
        for (ItemChannelLink link : linkRegistry.getLinks(channel.getUID())) {
            createItemForLink(link);
        }
    }
}
 
Example #15
Source File: FirmwareUpdateServiceFirmwareRestrictionTest.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void firmwareRestrictionAndRestrictedModel() {
    FirmwareRestriction firmwareRestrictionFunction = t -> t.getProperties()
            .get(Thing.PROPERTY_FIRMWARE_VERSION).equals(FIRMWARE_VERSION_1);

    Firmware firmware = FirmwareBuilder.create(thingTypeUID, FIRMWARE_VERSION_2).withModelRestricted(true)
            .withModel(TEST_MODEL).withFirmwareRestriction(firmwareRestrictionFunction).build();

    registerFirmwareProviderWithSingleFirmware(firmware);

    assertThatFirmwareUpdateIsExecutableForThingWithFirmwareVersionAndHardwareVersion(FIRMWARE_VERSION_1, null);
}
 
Example #16
Source File: ThingConfigDescriptionAliasProvider.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
private @Nullable URI getChannelConfigDescriptionURI(URI uri) {
    String stringUID = uri.getSchemeSpecificPart();
    if (uri.getFragment() != null) {
        stringUID = stringUID + "#" + uri.getFragment();
    }
    ChannelUID channelUID = new ChannelUID(stringUID);
    ThingUID thingUID = channelUID.getThingUID();

    // First, get the thing so we get access to the channel type via the channel
    Thing thing = thingRegistry.get(thingUID);
    if (thing == null) {
        return null;
    }

    Channel channel = thing.getChannel(channelUID.getId());
    if (channel == null) {
        return null;
    }

    ChannelType channelType = channelTypeRegistry.getChannelType(channel.getChannelTypeUID());
    if (channelType == null) {
        return null;
    }

    // Get the config description URI for this channel type
    URI configURI = channelType.getConfigDescriptionURI();
    return configURI;
}
 
Example #17
Source File: FirmwareTest.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testNotModelRestrictedFirmwareIsSuitableForThingWithSameThingType() {
    Firmware firmware = FirmwareBuilder.create(new ThingTypeUID("binding:thingTypeA"), "version").build();
    Thing thing = ThingBuilder.create(new ThingTypeUID("binding:thingTypeA"), "thing").build();

    assertThat(firmware.isSuitableFor(thing), is(true));
}
 
Example #18
Source File: FirmwareImpl.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
private boolean firmwareOnThingIsHighEnough(Thing thing) {
    if (prerequisiteVersion == null) {
        return true;
    } else {
        String firmwareOnThing = thing.getProperties().get(PROPERTY_FIRMWARE_VERSION);
        return firmwareOnThing != null && new Version(firmwareOnThing).compare(prerequisiteVersion) >= 0;
    }
}
 
Example #19
Source File: PersistentInbox.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@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 #20
Source File: ThingManagerImpl.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void thingAdded(Thing thing, ThingTrackerEvent thingTrackerEvent) {
    this.things.add(thing);
    logger.debug("Thing '{}' is tracked by ThingManager.", thing.getUID());
    if (!isHandlerRegistered(thing)) {
        registerAndInitializeHandler(thing, getThingHandlerFactory(thing));
    } else {
        logger.debug("Handler of tracked thing '{}' already registered.", thing.getUID());
    }
}
 
Example #21
Source File: PersistentInboxTest.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testConfigUpdateNormalization_withConfigDescription() throws Exception {
    Map<String, Object> props = new HashMap<>();
    props.put("foo", "1");
    Configuration config = new Configuration(props);
    Thing thing = ThingBuilder.create(THING_TYPE_UID, THING_UID).withConfiguration(config).build();
    configureConfigDescriptionRegistryMock("foo", Type.TEXT);
    when(thingRegistry.get(eq(THING_UID))).thenReturn(thing);

    assertTrue(thing.getConfiguration().get("foo") instanceof String);
    inbox.add(DiscoveryResultBuilder.create(THING_UID).withProperty("foo", 3).build());
    assertTrue(thing.getConfiguration().get("foo") instanceof String);
    assertEquals("3", thing.getConfiguration().get("foo"));
}
 
Example #22
Source File: HomematicBridgeHandler.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void onStateUpdated(HmDatapoint dp) {
    Thing hmThing = getThingByUID(UidUtils.generateThingUID(dp.getChannel().getDevice(), getThing()));
    if (hmThing != null) {
        final ThingStatus status = hmThing.getStatus();
        if (status == ThingStatus.ONLINE || status == ThingStatus.OFFLINE) {
            HomematicThingHandler thingHandler = (HomematicThingHandler) hmThing.getHandler();
            if (thingHandler != null) {
                thingHandler.updateDatapointState(dp);
            }
        }
    }
}
 
Example #23
Source File: HomematicBridgeHandler.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void onDeviceLoaded(HmDevice device) {
    typeGenerator.generate(device);
    if (discoveryService != null) {
        discoveryService.deviceDiscovered(device);
    }

    Thing hmThing = getThingByUID(UidUtils.generateThingUID(device, getThing()));
    if (hmThing != null) {
        HomematicThingHandler thingHandler = (HomematicThingHandler) hmThing.getHandler();
        if (thingHandler != null) {
            thingHandler.deviceLoaded(device);
        }
    }
}
 
Example #24
Source File: FSInternetRadioHandlerJavaTest.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Verify the valid and invalid values when updating CHANNEL_VOLUME_PERCENT are handled correctly.
 */
@Test
public void validInvalidPercVolume() {
    String absoluteVolumeChannelID = FSInternetRadioBindingConstants.CHANNEL_VOLUME_ABSOLUTE;
    String absoluteAcceptedItemType = acceptedItemTypes.get(absoluteVolumeChannelID);
    createChannel(DEFAULT_THING_UID, absoluteVolumeChannelID, absoluteAcceptedItemType);

    String percentVolumeChannelID = FSInternetRadioBindingConstants.CHANNEL_VOLUME_PERCENT;
    String percentAcceptedItemType = acceptedItemTypes.get(percentVolumeChannelID);
    createChannel(DEFAULT_THING_UID, percentVolumeChannelID, percentAcceptedItemType);

    Thing radioThing = initializeRadioThing(DEFAULT_COMPLETE_CONFIGURATION);
    testRadioThingConsideringConfiguration(radioThing);

    turnTheRadioOn(radioThing);

    ChannelUID absoluteVolumeChannelUID = getChannelUID(radioThing, absoluteVolumeChannelID);
    initializeItem(absoluteVolumeChannelUID, DEFAULT_TEST_ITEM_NAME, absoluteAcceptedItemType);

    ChannelUID percentVolumeChannelUID = getChannelUID(radioThing, percentVolumeChannelID);

    /*
     * Giving the handler a valid percent value. According to the FrontierSiliconRadio's
     * documentation 100 percents correspond to 32 absolute value
     */
    radioHandler.handleCommand(percentVolumeChannelUID, PercentType.valueOf("50"));
    waitForAssert(() -> {
        assertTrue("We should be able to set the volume correctly using percentages.",
                radioServiceDummy.containsRequestParameter(16, VOLUME));
        radioServiceDummy.clearRequestParameters();
    });

    radioHandler.handleCommand(percentVolumeChannelUID, PercentType.valueOf("15"));

    waitForAssert(() -> {
        assertTrue("We should be able to set the volume correctly using percentages.",
                radioServiceDummy.containsRequestParameter(4, VOLUME));
        radioServiceDummy.clearRequestParameters();
    });
}
 
Example #25
Source File: ThingEventFactory.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Creates a thing added event.
 *
 * @param thing the thing
 * @return the created thing added event
 * @throws IllegalArgumentException if thing is null
 */
public static ThingAddedEvent createAddedEvent(Thing thing) {
    assertValidArgument(thing);
    String topic = buildTopic(THING_ADDED_EVENT_TOPIC, thing.getUID());
    ThingDTO thingDTO = map(thing);
    String payload = serializePayload(thingDTO);
    return new ThingAddedEvent(topic, payload, thingDTO);
}
 
Example #26
Source File: ThingLinkManager.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void removed(Item element) {
    for (final ChannelUID channelUID : itemChannelLinkRegistry.getBoundChannels(element.getName())) {
        final Thing thing = thingRegistry.get(channelUID.getThingUID());
        if (thing != null) {
            final Channel channel = thing.getChannel(channelUID.getId());
            if (channel != null) {
                ThingLinkManager.this.informHandlerAboutUnlinkedChannel(thing, channel);
            }
        }
    }
}
 
Example #27
Source File: MagicDiscoveryService.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void startScan() {
    String serialNumber = createRandomSerialNumber();
    DiscoveryResult discoveryResult = DiscoveryResultBuilder
            .create(new ThingUID(MagicBindingConstants.THING_TYPE_CONFIG_THING, serialNumber))
            .withRepresentationProperty(Thing.PROPERTY_SERIAL_NUMBER)
            .withProperty(Thing.PROPERTY_SERIAL_NUMBER, serialNumber).withLabel("Magic Thing").build();
    thingDiscovered(discoveryResult);
}
 
Example #28
Source File: FirmwareTest.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testModelRestrictedFirmwareIsSuitableForThingWithSameThingTypeAndSameModel() {
    Firmware firmware = FirmwareBuilder.create(new ThingTypeUID("binding:thingTypeA"), "version")
            .withModelRestricted(true).withModel("someModel").build();
    Thing thing = ThingBuilder.create(new ThingTypeUID("binding:thingTypeA"), "thing").build();
    thing.setProperty(Thing.PROPERTY_MODEL_ID, "someModel");

    assertThat(firmware.isSuitableFor(thing), is(true));
}
 
Example #29
Source File: FirmwareUpdateServiceImpl.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@Nullable
private Firmware getLatestSuitableFirmware(Thing thing) {
    Collection<Firmware> firmwares = firmwareRegistry.getFirmwares(thing);
    if (firmwares != null) {
        Optional<Firmware> first = firmwares.stream().findFirst();
        if (first.isPresent()) {
            return first.get();
        }
    }
    return null;
}
 
Example #30
Source File: TestHueThingHandlerFactory.java    From smarthome with Eclipse Public License 2.0 5 votes vote down vote up
@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.");
}