Metadata is used in order for the application to be able to obtain information for the set of Properties/Operations of particular FI. Annotations are used for defining Functional Items Metadata.
Metadata
Metadata is used in order for the application to be able to obtain information for the set of Properties/Operations of particular FI. Also the type of each property and the types of arguments for the operation and the result. Functional Items may use different metadata types. To obtain specific information about the metadata of Item/Property/Operation the following commands may be executed. They invoke different methods (e.g. getItemMetadata). For more information check the metadata package.
fim>$info 1
Information for Functional Item
-----------------------------------------------------------------------------------------------------------------------
UID
demo:fim:BinarySwitch:1
Name BS Room 1
Version 2.0.0
Tags lamp
Interfaces com.prosyst.mbs.demo.fim.BinarySwitch
Properties
state Switched On
Operations turnOff
toggle
turnOn
fim>$info 1 stateProperty stateValue Switched Onclasses com.prosyst.mbs.demo.fim.BinarySwitch$Stateconsts {name: OFF, value: Switched Off} {name: ON, value: Switched On}description Switch state.getter getStateisEventable truename state
fim>$info 1 turnOnOperation turnOndescription Turns on the binary switch.name turnOnparameters N/Areturn N/A
Different Types of Metadata
The following properties are required for defining all Functional Items:
Key |
Description |
|---|---|
name |
Name of the Functional Item (e.g. Alarm). |
description |
User-friendly description of the FI function. |
type |
The type of FI Metadata that will be used (e.g. Numeric, Enum, Bean, etc.). |
classes |
The Metadata Classes. |
Types of Metadata:
Key |
Description |
|---|---|
min |
The minimum value (inclusive) that is allowed for this numeric. If not specified, the minimum is the minimum number allowed for its type. |
max |
The maximum value (inclusive) that is allowed for this numeric. If not specified, the maximum is the maximum number allowed for its type. |
step |
The step value that is used for this numeric. It must be a positive number. If not specified, the step is the smallest number allowed for its type. |
Key |
Description |
|---|---|
enumConstants |
Array used for the list of Enum Constants (EnumConst[]) that have name/value pair. Each array (EnumConst[]) has name (The name of the enum constant) and value (The value of the enum constant). |
Key |
Description |
|---|---|
version |
The bean version. |
fields |
The fields metadata. The keys in the returned map are the fields names and the values are the metadata for each bean field. |
There are several special cases when:
@Documented@Retention(value=RUNTIME)
@Target(value=TYPE)
public @interface Item
Annotations
The FIM annotations (com.prosyst.mbs.services.fim.annotations) are used for defining Functional Items Metadata. They can be used in java interfaces, their constants and methods or in class (beans) methods.
The table below displays the possible use of annotations. "@" means "annotated".
Annotation |
Item annotated interface |
Interface constant |
Method/Method return |
Method parameter |
Class |
|---|---|---|---|---|---|
Item |
Yes |
No |
No |
No |
No |
Name |
Yes |
No |
No |
No |
No |
Description |
Yes |
Yes if @Property |
Yes if FI @Operation return or Bean field @Getter |
Yes if @Operation |
No |
Version |
Yes |
No |
No |
No |
Yes |
Attribute(s) |
Yes |
Yes if @Property |
Yes if @Operation |
No |
No |
Property |
No |
Yes |
No |
No |
No |
Operation |
No |
No |
Yes in FI Interface |
No |
No |
OperationEvent (since 2.3.0) |
No |
Yes (since 2.3.2000) |
Yes in FI Interface |
No |
No |
OperationEventProperty (since 2.3.0) |
No |
Yes |
No |
No |
No |
Getter |
No |
No |
Yes in FI Interface or Bean |
No |
No |
Setter |
No |
No |
Yes in FI Interface |
No |
No |
Ignore |
Yes |
No |
Yes in FI Interface or Bean |
No |
No |
Regex (since 2.3.0) |
No |
Yes If @Property |
Yes if FI @Operation return or Bean field @Getter |
Yes if @Operation |
No |
Numeric |
No |
Yes if @Property |
Yes if FI @Operation return or Bean field @Getter |
Yes if @Operation |
No |
Enum (deprecated since 2.3.0, automatically detected for java enums) |
No |
Yes if @Property |
Yes if FI @Operation return or Bean field @Getter |
Yes if @Operation |
No |
Constructor |
No |
No |
No |
No |
Yes, for one of the constructors |
Status (deprecated since 2.3.0) |
No |
No |
Yes if FI @Operation or property setter |
No |
No |
Tooling
Add this maven dependency:
<dependency>
<groupId>com.prosyst.mbs.fim</groupId>
<artifactId>com.prosyst.mbs.fim.validator</artifactId>
<version>2.3.0</version>
<scope>compile</scope>
</dependency>
It will validate your annotations. For more information refer to FIM Annotations Validator.
Functional Item Interface Guidelines
Item Interface
@Item
@Name("Binary Switch")
@Version("1.5.0")
@Description("Provides support for binary switches control.")
public interface BinarySwitch extends FunctionalItem {
Property Constant
@Property
@Enum({
@EnumConst(name = "Low Battery", value = "true"), @EnumConst(name = "No Low Battery", value = "false")
})
@Description("Indicates if the battery is low. Value true denotes low battery.")
public static final String PROPERTY_LOW_BATTERY = "lowBattery";
@Property(access = "E", type = Alarm.class)
@Description("Alarm sensor event.")
public static final String PROPERTY_ALARM = "alarm";
Operation Method
@Operation
@Description("Changes the current color with new target HSB.")
public void changeHsb(
@Description("Target HSB color.") HSB hsb,
@Numeric(min = "0")
@Description("The time for which the color is changing. The minimum value of transition time is 0.") long transitionTime)
throws HomeDeviceException;
Bean
@Constructor({
"name", "age"
})
public MemberBean(String name, int age) {