Search in sources :

Example 31 with ThingTypeUID

use of org.eclipse.smarthome.core.thing.ThingTypeUID in project smarthome by eclipse.

the class FirmwareTest method testFirmwareIsNotSuitableForThingWithDifferentThingType.

@Test
public void testFirmwareIsNotSuitableForThingWithDifferentThingType() {
    Firmware firmware = new Firmware.Builder(new FirmwareUID(new ThingTypeUID("binding:thingTypeA"), "version")).build();
    Thing thing = ThingBuilder.create(new ThingTypeUID("binding:thingTypeB"), "thing").build();
    assertThat(firmware.isSuitableFor(thing), is(false));
}
Also used : ThingTypeUID(org.eclipse.smarthome.core.thing.ThingTypeUID) Thing(org.eclipse.smarthome.core.thing.Thing) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

Example 32 with ThingTypeUID

use of org.eclipse.smarthome.core.thing.ThingTypeUID in project smarthome by eclipse.

the class FirmwareUpdateServiceTest method testGetFirmwareStatusInfo_firmwareProviderAddedLate.

@Test
public void testGetFirmwareStatusInfo_firmwareProviderAddedLate() {
    assertThat(firmwareUpdateService.getFirmwareStatusInfo(THING3_UID), is(unknownInfo));
    FirmwareProvider firmwareProvider2 = mock(FirmwareProvider.class);
    when(firmwareProvider2.getFirmware(eq(FWALPHA_EN.getUID()), any(Locale.class))).thenReturn(FWALPHA_EN);
    when(firmwareProvider2.getFirmwares(any(ThingTypeUID.class), any(Locale.class))).thenAnswer(invocation -> {
        ThingTypeUID thingTypeUID = (ThingTypeUID) invocation.getArguments()[0];
        if (THING_TYPE_UID_WITHOUT_FW.equals(thingTypeUID) || THING_TYPE_UID1.equals(thingTypeUID)) {
            return Collections.emptySet();
        } else {
            return Collections.singleton(FWALPHA_EN);
        }
    });
    firmwareRegistry.addFirmwareProvider(firmwareProvider2);
    assertThat(firmwareUpdateService.getFirmwareStatusInfo(THING3_UID), is(upToDateInfo));
    // verify that the corresponding events are sent
    ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
    verify(mockPublisher, times(2)).post(eventCaptor.capture());
    assertFirmwareStatusInfoEvent(THING3_UID, eventCaptor.getAllValues().get(0), unknownInfo);
    assertFirmwareStatusInfoEvent(THING3_UID, eventCaptor.getAllValues().get(1), upToDateInfo);
}
Also used : Locale(java.util.Locale) Event(org.eclipse.smarthome.core.events.Event) ThingTypeUID(org.eclipse.smarthome.core.thing.ThingTypeUID) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

Example 33 with ThingTypeUID

use of org.eclipse.smarthome.core.thing.ThingTypeUID in project smarthome by eclipse.

the class FirmwareUpdateServiceTest method testUpdateFirmware_wrongThingType.

@Test
public void testUpdateFirmware_wrongThingType() {
    FirmwareProvider firmwareProvider2 = mock(FirmwareProvider.class);
    when(firmwareProvider2.getFirmware(eq(FWALPHA_EN.getUID()), any(Locale.class))).thenReturn(FWALPHA_EN);
    when(firmwareProvider2.getFirmwares(any(ThingTypeUID.class), any(Locale.class))).thenAnswer(invocation -> {
        ThingTypeUID thingTypeUID = (ThingTypeUID) invocation.getArguments()[0];
        if (THING_TYPE_UID_WITHOUT_FW.equals(thingTypeUID) || THING_TYPE_UID1.equals(thingTypeUID)) {
            return Collections.emptySet();
        } else {
            return Collections.singleton(FWALPHA_EN);
        }
    });
    firmwareRegistry.addFirmwareProvider(firmwareProvider2);
    thrown.expect(IllegalArgumentException.class);
    thrown.expectMessage(equalTo(String.format("Firmware with UID %s is not suitable for thing with UID %s.", FWALPHA_EN.getUID(), THING1_UID)));
    firmwareUpdateService.updateFirmware(THING1_UID, FWALPHA_EN.getUID(), null);
}
Also used : Locale(java.util.Locale) ThingTypeUID(org.eclipse.smarthome.core.thing.ThingTypeUID) JavaOSGiTest(org.eclipse.smarthome.test.java.JavaOSGiTest) Test(org.junit.Test)

Example 34 with ThingTypeUID

use of org.eclipse.smarthome.core.thing.ThingTypeUID in project smarthome by eclipse.

the class DigitalSTROMHandlerFactory method createHandler.

@Override
protected ThingHandler createHandler(Thing thing) {
    ThingTypeUID thingTypeUID = thing.getThingTypeUID();
    if (thingTypeUID == null) {
        return null;
    }
    if (BridgeHandler.SUPPORTED_THING_TYPES.contains(thingTypeUID)) {
        BridgeHandler handler = new BridgeHandler((Bridge) thing);
        if (bridgeHandlers == null) {
            bridgeHandlers = new HashMap<ThingUID, BridgeHandler>();
        }
        bridgeHandlers.put(thing.getUID(), handler);
        DiscoveryServiceManager discoveryServiceManager = new DiscoveryServiceManager(handler);
        discoveryServiceManager.registerDiscoveryServices(bundleContext);
        discoveryServiceManagers.put(handler.getThing().getUID().getAsString(), discoveryServiceManager);
        return handler;
    }
    if (DeviceHandler.SUPPORTED_THING_TYPES.contains(thingTypeUID)) {
        return new DeviceHandler(thing);
    }
    if (CircuitHandler.SUPPORTED_THING_TYPES.contains(thingTypeUID)) {
        return new CircuitHandler(thing);
    }
    if (ZoneTemperatureControlHandler.SUPPORTED_THING_TYPES.contains(thingTypeUID)) {
        return new ZoneTemperatureControlHandler(thing);
    }
    if (SceneHandler.SUPPORTED_THING_TYPES.contains(thingTypeUID)) {
        return new SceneHandler(thing);
    }
    return null;
}
Also used : BridgeHandler(org.eclipse.smarthome.binding.digitalstrom.handler.BridgeHandler) CircuitHandler(org.eclipse.smarthome.binding.digitalstrom.handler.CircuitHandler) DiscoveryServiceManager(org.eclipse.smarthome.binding.digitalstrom.internal.discovery.DiscoveryServiceManager) ZoneTemperatureControlHandler(org.eclipse.smarthome.binding.digitalstrom.handler.ZoneTemperatureControlHandler) ThingUID(org.eclipse.smarthome.core.thing.ThingUID) ThingTypeUID(org.eclipse.smarthome.core.thing.ThingTypeUID) DeviceHandler(org.eclipse.smarthome.binding.digitalstrom.handler.DeviceHandler) SceneHandler(org.eclipse.smarthome.binding.digitalstrom.handler.SceneHandler)

Example 35 with ThingTypeUID

use of org.eclipse.smarthome.core.thing.ThingTypeUID in project smarthome by eclipse.

the class DeviceDiscoveryService method getThingUID.

private ThingUID getThingUID(GeneralDeviceInformation device) {
    ThingUID bridgeUID = bridgeHandler.getThing().getUID();
    ThingTypeUID thingTypeUID = null;
    if (device instanceof Device) {
        Device tempDevice = (Device) device;
        thingTypeUID = new ThingTypeUID(BINDING_ID, tempDevice.getHWinfo().substring(0, 2));
        if (tempDevice.isSensorDevice() && deviceType.equals(tempDevice.getHWinfo().replaceAll("-", ""))) {
            thingTypeUID = new ThingTypeUID(BINDING_ID, deviceType);
        }
    } else {
        thingTypeUID = new ThingTypeUID(BINDING_ID, DsDeviceThingTypeProvider.SupportedThingTypes.circuit.toString());
    }
    if (getSupportedThingTypes().contains(thingTypeUID)) {
        String thingDeviceId = device.getDSID().toString();
        ThingUID thingUID = new ThingUID(thingTypeUID, bridgeUID, thingDeviceId);
        return thingUID;
    } else {
        return null;
    }
}
Also used : Device(org.eclipse.smarthome.binding.digitalstrom.internal.lib.structure.devices.Device) ThingUID(org.eclipse.smarthome.core.thing.ThingUID) ThingTypeUID(org.eclipse.smarthome.core.thing.ThingTypeUID)

Aggregations

ThingTypeUID (org.eclipse.smarthome.core.thing.ThingTypeUID)63 ThingUID (org.eclipse.smarthome.core.thing.ThingUID)27 Test (org.junit.Test)27 JavaOSGiTest (org.eclipse.smarthome.test.java.JavaOSGiTest)25 Thing (org.eclipse.smarthome.core.thing.Thing)12 DiscoveryResult (org.eclipse.smarthome.config.discovery.DiscoveryResult)11 Locale (java.util.Locale)10 HashMap (java.util.HashMap)9 Collection (java.util.Collection)5 DiscoveryService (org.eclipse.smarthome.config.discovery.DiscoveryService)5 Before (org.junit.Before)5 Configuration (org.eclipse.smarthome.config.core.Configuration)4 DiscoveryListener (org.eclipse.smarthome.config.discovery.DiscoveryListener)4 ApiOperation (io.swagger.annotations.ApiOperation)3 ApiResponses (io.swagger.annotations.ApiResponses)3 Nullable (org.eclipse.jdt.annotation.Nullable)3 ThingRegistry (org.eclipse.smarthome.core.thing.ThingRegistry)3 BaseThingHandlerFactory (org.eclipse.smarthome.core.thing.binding.BaseThingHandlerFactory)3 Firmware (org.eclipse.smarthome.core.thing.binding.firmware.Firmware)3 ArrayList (java.util.ArrayList)2