# Things

Things are the entities that can physically be added to a system and which can potentially provide many functionalities in one. It is important to note that Things do not have to be devices, but they can also represent a web service or any other manageable source of information and functionality. From a user perspective, they are relevant for the setup and configuration process, but not for the operation.

Things can have configuration properties, which can be optional or mandatory. Such properties can be basic information like an IP address, an access token for a web service or a device specific configuration that alters its behavior.

# Channels

Things provide "Channels", which represent the different functions the Thing provides. Where the Thing is the physical entity or source of information, the Channel is a concrete function from this Thing. A physical light bulb might have a color temperature Channel and a color Channel, both providing functionality of the one light bulb Thing to the system. For sources of information the Thing might be the local weather with information from a web service with different Channels like temperature, pressure and humidity.

Channels are linked to Items, where such links are the glue between the virtual and the physical layer. Once such a link is established, a Thing reacts to events sent for an item that is linked to one of its Channels. Likewise, it actively sends out events for Items linked to its Channels.

# Bridges

A special type of Thing is a "bridge". Bridges are Things that need to be added to the system in order to gain access to other Things. A typical example of a bridge is an IP gateway for some non-IP based home automation system or a web service configuration with authentication information which every Thing from this web service might need.

# Discovery

As many Things can be automatically discovered, there are special mechanisms available that deal with the handling of automatically discovered Things.

# Thing Status

Each Thing has a status object, which helps to identify possible problems with the device or service. The following table provides an overview of the different statuses:

Status Description
UNINITIALIZED This is the initial status of a Thing, when it is added or the framework is being started. This status is also assigned, if the initializing process failed or the binding is not available. Commands which are sent to Channels will not be processed.
INITIALIZING This status is assigned while the binding initializes the Thing. It depends on the binding how long the initializing process takes. Commands which are sent to Channels will not be processed.
UNKNOWN The handler is fully initialized but due to the nature of the represented device/service it cannot really tell yet whether the Thing is ONLINE or OFFLINE. Therefore the Thing potentially might be working correctly already and may or may not process commands. But the framework is allowed to send commands, because some radio-based devices may go ONLINE if a command is sent to them. The handler should take care to switch the Thing to ONLINE or OFFLINE as soon as possible.
ONLINE The device/service represented by a Thing is assumed to be working correctly and can process commands.
OFFLINE The device/service represented by a Thing is assumed to be not working correctly and may not process commands. But the framework is allowed to send commands, because some radio-based devices may go back to ONLINE if a command is sent to them.
REMOVING The device/service represented by a Thing should be removed, but the binding did not confirm the deletion yet. Some bindings need to communicate with the device to unpair it from the system. Thing is probably not working and commands cannot be processed.
REMOVED This status indicates that the device/service represented by a Thing was removed from the external system after the REMOVING was initiated by the framework. Usually this status is an intermediate status because the Thing gets removed from the database after this status was assigned.

The statuses UNINITIALIZED, INITIALIZING and REMOVING are set by the framework, whereas the statuses UNKNOWN, ONLINE and OFFLINE are assigned from a binding.

Additionally, the REMOVED status is set by the binding to indicate that the removal process has been completed, i.e. the Thing must have been in REMOVING status before.

# Status Transitions

The following diagram shows the allowed status transitions:

Status Transitions

The initial status of a Thing is UNINITIALIZED. From UNINITIALIZED the Thing goes into INITIALIZING. If the initialization fails, the Thing goes back to UNINITIALIZED. If the initialization succeeds, the binding sets the status of the Thing to UNKNOWN, ONLINE or OFFLINE, which all mean that the Thing handler is fully initialized. From one of these statuses the Thing can go back into UNINITIALIZED, REMOVING or REMOVED. The statuses REMOVING and REMOVED can also be reached from any of the other statuses.

# Status Details

A status is detailed further with a status detail object. The following table lists the different status details for each status:

UNINITIALIZEDNONENo further status details available.
HANDLER_MISSING_ERRORThe handler cannot be initialized, because the responsible binding is not available or started.
HANDLER_REGISTERING_ERRORThe handler failed in the service registration phase.
HANDLER_CONFIGURATION_PENDINGThe handler is registered but cannot be initialized because of missing configuration parameters.
HANDLER_INITIALIZING_ERRORThe handler failed in the initialization phase.
BRIDGE_UNINITIALIZEDThe bridge associated with this Thing is not initialized.
DISABLEDThe thing was explicitly disabled.
INITIALIZING NONENo further status details available.
UNKNOWN NONENo further status details available.
ONLINE NONENo further status details available.
CONFIGURATION_PENDINGThe Thing is waiting to transfer configuration information to a device. Some bindings need to communicate with the device to make sure the configuration is accepted.
OFFLINE NONENo further status details available.
COMMUNICATION_ERRORError communicating with the device. This may be only a temporary error.
CONFIGURATION_ERRORAn issue with the configuration of a Thing prevents communication with the represented device or service. This issue might be solved by reconfiguring the Thing.
BRIDGE_OFFLINEAssuming the Thing to be offline because the corresponding bridge is offline.
FIRMWARE_UPDATINGThe Thing is currently undergoing a firmware update.
DUTY_CYCLEThe Thing is currently in DUTY_CYCLE state, which means it is blocked for further usage.
GONEThe Thing has been removed from the bridge or the network to which it belongs and is no longer available for use. The user can now remove the Thing from the system.
REMOVING NONENo further status details available.
REMOVED NONENo further status details available.

# Status Description

To provide additional information about the current status a description is used. The status description is to be specified by the binding. This description can be used for debugging purposes and should not be presented to the user, as it might contain unreadable technical information (e.g. an HTTP status code, or any other protocol specific information, which helps to identify the current problem).

# Thing Status API

The Thing interface defines a method getStatusInfo() to retrieve the current status of the Thing. The following code shows how to print the status of each Thing to the console:

Collection<Thing> things = thingRegistry.getAll();
for (Thing thing : things) {
    ThingStatusInfo statusInfo = thing.getStatusInfo();
    switch (statusInfo.getStatus()) {
        case ONLINE:
            System.out.println("Thing is online");
            break;
        case OFFLINE:
            System.out.println("Thing is offline");
            break;
        default:
            System.out.println("Thing status: " + statusInfo.getStatus());
            break;
    }
    System.out.println("Thing status detail: " + statusInfo.getStatusDetail());
    System.out.println("Thing status description: " + statusInfo.getDescription());
}