Search in sources :

Example 6 with Thing

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

the class ThingResource method updateFirmware.

@PUT
@Path("/{thingUID}/firmware/{firmwareVersion}")
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Update thing firmware.")
@ApiResponses(value = { @ApiResponse(code = 200, message = "OK"), @ApiResponse(code = 400, message = "Firmware update preconditions not satisfied."), @ApiResponse(code = 404, message = "Thing not found.") })
public Response updateFirmware(@HeaderParam(HttpHeaders.ACCEPT_LANGUAGE) @ApiParam(value = "language") String language, @PathParam("thingUID") @ApiParam(value = "thing") String thingUID, @PathParam("firmwareVersion") @ApiParam(value = "version") String firmwareVersion) throws IOException {
    Thing thing = thingRegistry.get(new ThingUID(thingUID));
    if (thing == null) {
        return getThingNotFoundResponse(thingUID);
    }
    FirmwareUID firmwareUID = new FirmwareUID(thing.getThingTypeUID(), firmwareVersion);
    try {
        firmwareUpdateService.updateFirmware(thing.getUID(), firmwareUID, LocaleUtil.getLocale(language));
    } catch (IllegalArgumentException | NullPointerException | IllegalStateException ex) {
        return JSONResponse.createResponse(Status.BAD_REQUEST, null, "Firmware update preconditions not satisfied.");
    }
    return Response.status(Status.OK).build();
}
Also used : FirmwareUID(org.eclipse.smarthome.core.thing.binding.firmware.FirmwareUID) ThingUID(org.eclipse.smarthome.core.thing.ThingUID) Thing(org.eclipse.smarthome.core.thing.Thing) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) ApiOperation(io.swagger.annotations.ApiOperation) PUT(javax.ws.rs.PUT) ApiResponses(io.swagger.annotations.ApiResponses)

Example 7 with Thing

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

the class CommunicationManager method receiveTrigger.

private void receiveTrigger(ChannelTriggeredEvent channelTriggeredEvent) {
    final ChannelUID channelUID = channelTriggeredEvent.getChannel();
    final String event = channelTriggeredEvent.getEvent();
    final Thing thing = getThing(channelUID.getThingUID());
    handleCallFromHandler(channelUID, thing, profile -> {
        if (profile instanceof TriggerProfile) {
            ((TriggerProfile) profile).onTriggerFromHandler(event);
        }
    });
}
Also used : ChannelUID(org.eclipse.smarthome.core.thing.ChannelUID) TriggerProfile(org.eclipse.smarthome.core.thing.profiles.TriggerProfile) Thing(org.eclipse.smarthome.core.thing.Thing)

Example 8 with Thing

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

the class CommunicationManager method handleEvent.

private <T extends Type> void handleEvent(String itemName, T type, String source, Function<@Nullable String, @Nullable List<Class<? extends T>>> acceptedTypesFunction, ProfileAction<T> action) {
    final Item item = getItem(itemName);
    if (item == null) {
        logger.debug("Received an event for item {} which does not exist", itemName);
        return;
    }
    itemChannelLinkRegistry.stream().filter(link -> {
        // all links for the item
        return link.getItemName().equals(itemName);
    }).filter(link -> {
        // make sure the command event is not sent back to its source
        return !link.getLinkedUID().toString().equals(source);
    }).forEach(link -> {
        ChannelUID channelUID = link.getLinkedUID();
        Thing thing = getThing(channelUID.getThingUID());
        if (thing != null) {
            Channel channel = thing.getChannel(channelUID.getId());
            if (channel != null) {
                @Nullable T convertedType = toAcceptedType(type, channel, acceptedTypesFunction);
                if (convertedType != null) {
                    if (thing.getHandler() != null) {
                        Profile profile = getProfile(link, item, thing);
                        action.handle(profile, thing, convertedType);
                    }
                } else {
                    logger.debug("Received event '{}' ({}) could not be converted to any type accepted by item '{}' ({})", type, type.getClass().getSimpleName(), itemName, item.getType());
                }
            } else {
                logger.debug("Received  event '{}' for non-existing channel '{}', not forwarding it to the handler", type, channelUID);
            }
        } else {
            logger.debug("Received  event '{}' for non-existing thing '{}', not forwarding it to the handler", type, channelUID.getThingUID());
        }
    });
}
Also used : Channel(org.eclipse.smarthome.core.thing.Channel) Arrays(java.util.Arrays) ItemFactory(org.eclipse.smarthome.core.items.ItemFactory) ProfileFactory(org.eclipse.smarthome.core.thing.profiles.ProfileFactory) LoggerFactory(org.slf4j.LoggerFactory) Command(org.eclipse.smarthome.core.types.Command) ItemChannelLinkConfigDescriptionProvider(org.eclipse.smarthome.core.thing.internal.link.ItemChannelLinkConfigDescriptionProvider) ChannelUID(org.eclipse.smarthome.core.thing.ChannelUID) Nullable(org.eclipse.jdt.annotation.Nullable) Map(java.util.Map) Thing(org.eclipse.smarthome.core.thing.Thing) UID(org.eclipse.smarthome.core.thing.UID) State(org.eclipse.smarthome.core.types.State) NonNullByDefault(org.eclipse.jdt.annotation.NonNullByDefault) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) EventPublisher(org.eclipse.smarthome.core.events.EventPublisher) ItemStateConverter(org.eclipse.smarthome.core.items.ItemStateConverter) ReferencePolicy(org.osgi.service.component.annotations.ReferencePolicy) CopyOnWriteArraySet(java.util.concurrent.CopyOnWriteArraySet) ThingEventFactory(org.eclipse.smarthome.core.thing.events.ThingEventFactory) List(java.util.List) StateProfile(org.eclipse.smarthome.core.thing.profiles.StateProfile) Entry(java.util.Map.Entry) NonNull(org.eclipse.jdt.annotation.NonNull) SystemProfileFactory(org.eclipse.smarthome.core.thing.internal.profiles.SystemProfileFactory) ThingUID(org.eclipse.smarthome.core.thing.ThingUID) ItemCommandEvent(org.eclipse.smarthome.core.items.events.ItemCommandEvent) EventFilter(org.eclipse.smarthome.core.events.EventFilter) EventSubscriber(org.eclipse.smarthome.core.events.EventSubscriber) Function(java.util.function.Function) RegistryChangeListener(org.eclipse.smarthome.core.common.registry.RegistryChangeListener) HashSet(java.util.HashSet) ProfileCallbackImpl(org.eclipse.smarthome.core.thing.internal.profiles.ProfileCallbackImpl) Component(org.osgi.service.component.annotations.Component) SafeCaller(org.eclipse.smarthome.core.common.SafeCaller) Type(org.eclipse.smarthome.core.types.Type) ProfileCallback(org.eclipse.smarthome.core.thing.profiles.ProfileCallback) TriggerProfile(org.eclipse.smarthome.core.thing.profiles.TriggerProfile) Logger(org.slf4j.Logger) Profile(org.eclipse.smarthome.core.thing.profiles.Profile) Item(org.eclipse.smarthome.core.items.Item) ItemStateEvent(org.eclipse.smarthome.core.items.events.ItemStateEvent) ItemChannelLink(org.eclipse.smarthome.core.thing.link.ItemChannelLink) ItemRegistry(org.eclipse.smarthome.core.items.ItemRegistry) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) ThingRegistry(org.eclipse.smarthome.core.thing.ThingRegistry) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) ProfileAdvisor(org.eclipse.smarthome.core.thing.profiles.ProfileAdvisor) ChannelTriggeredEvent(org.eclipse.smarthome.core.thing.events.ChannelTriggeredEvent) ItemChannelLinkRegistry(org.eclipse.smarthome.core.thing.link.ItemChannelLinkRegistry) Event(org.eclipse.smarthome.core.events.Event) ProfileTypeUID(org.eclipse.smarthome.core.thing.profiles.ProfileTypeUID) Reference(org.osgi.service.component.annotations.Reference) Collections(java.util.Collections) Item(org.eclipse.smarthome.core.items.Item) ChannelUID(org.eclipse.smarthome.core.thing.ChannelUID) Channel(org.eclipse.smarthome.core.thing.Channel) Thing(org.eclipse.smarthome.core.thing.Thing) Nullable(org.eclipse.jdt.annotation.Nullable) StateProfile(org.eclipse.smarthome.core.thing.profiles.StateProfile) TriggerProfile(org.eclipse.smarthome.core.thing.profiles.TriggerProfile) Profile(org.eclipse.smarthome.core.thing.profiles.Profile)

Example 9 with Thing

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

the class CommunicationManager method postCommand.

public void postCommand(ChannelUID channelUID, Command command) {
    final Thing thing = getThing(channelUID.getThingUID());
    handleCallFromHandler(channelUID, thing, profile -> {
        if (profile instanceof StateProfile) {
            ((StateProfile) profile).onCommandFromHandler(command);
        }
    });
}
Also used : StateProfile(org.eclipse.smarthome.core.thing.profiles.StateProfile) Thing(org.eclipse.smarthome.core.thing.Thing)

Example 10 with Thing

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

the class ThingConfigDescriptionAliasProvider method getThingConfigDescriptionURI.

@Nullable
private URI getThingConfigDescriptionURI(URI uri) {
    // First, get the thing type so we get the generic config descriptions
    ThingUID thingUID = new ThingUID(uri.getSchemeSpecificPart());
    Thing thing = thingRegistry.get(thingUID);
    if (thing == null) {
        return null;
    }
    ThingType thingType = thingTypeRegistry.getThingType(thing.getThingTypeUID());
    if (thingType == null) {
        return null;
    }
    // Get the config description URI for this thing type
    URI configURI = thingType.getConfigDescriptionURI();
    return configURI;
}
Also used : ThingUID(org.eclipse.smarthome.core.thing.ThingUID) ThingType(org.eclipse.smarthome.core.thing.type.ThingType) URI(java.net.URI) Thing(org.eclipse.smarthome.core.thing.Thing) Nullable(org.eclipse.jdt.annotation.Nullable)

Aggregations

Thing (org.eclipse.smarthome.core.thing.Thing)98 Test (org.junit.Test)43 ThingUID (org.eclipse.smarthome.core.thing.ThingUID)28 ChannelUID (org.eclipse.smarthome.core.thing.ChannelUID)24 Configuration (org.eclipse.smarthome.config.core.Configuration)19 JavaOSGiTest (org.eclipse.smarthome.test.java.JavaOSGiTest)19 JavaTest (org.eclipse.smarthome.test.java.JavaTest)18 ThingHandler (org.eclipse.smarthome.core.thing.binding.ThingHandler)14 ThingTypeUID (org.eclipse.smarthome.core.thing.ThingTypeUID)13 ApiOperation (io.swagger.annotations.ApiOperation)9 ApiResponses (io.swagger.annotations.ApiResponses)9 Item (org.eclipse.smarthome.core.items.Item)9 Path (javax.ws.rs.Path)8 Nullable (org.eclipse.jdt.annotation.Nullable)8 Locale (java.util.Locale)7 RolesAllowed (javax.annotation.security.RolesAllowed)7 Channel (org.eclipse.smarthome.core.thing.Channel)7 ThingHandlerCallback (org.eclipse.smarthome.core.thing.binding.ThingHandlerCallback)7 Command (org.eclipse.smarthome.core.types.Command)7 List (java.util.List)6