@@ -83,82 +83,54 @@ public SystemInfoThingTypeProvider(@Reference ThingTypeRegistry thingTypeRegistr
83
83
* Create thing type with the provided typeUID and add it to the thing type registry.
84
84
*
85
85
* @param typeUID
86
- * @return false if base type UID `systeminfo:computer` cannot be found in the thingTypeRegistry
87
86
*/
88
- public boolean createThingType (ThingTypeUID typeUID ) {
87
+ public void createThingType (ThingTypeUID typeUID ) {
89
88
logger .trace ("Creating thing type {}" , typeUID );
90
- return updateThingType (typeUID , getChannelGroupDefinitions (typeUID ));
89
+ updateThingType (typeUID , getChannelGroupDefinitions (typeUID ));
91
90
}
92
91
93
92
/**
94
93
* Update `ThingType`with `typeUID`, replacing the channel group definitions with `groupDefs`.
95
94
*
96
95
* @param typeUID
97
- * @param groupDefs
98
- * @return false if `typeUID` or its base type UID `systeminfo:computer` cannot be found in the thingTypeRegistry
96
+ * @param channelGroupDefinitions
99
97
*/
100
- public boolean updateThingType (ThingTypeUID typeUID , List <ChannelGroupDefinition > groupDefs ) {
98
+ public void updateThingType (ThingTypeUID typeUID , List <ChannelGroupDefinition > channelGroupDefinitions ) {
101
99
ThingType baseType = thingTypeRegistry .getThingType (typeUID );
102
100
if (baseType == null ) {
103
101
baseType = thingTypeRegistry .getThingType (THING_TYPE_COMPUTER );
104
102
if (baseType == null ) {
105
103
logger .warn ("Could not find base thing type in registry." );
106
- return false ;
104
+ return ;
107
105
}
108
106
}
109
- ThingTypeBuilder builder = createThingTypeBuilder (typeUID , baseType .getUID ());
110
- if (builder != null ) {
111
- logger .trace ("Adding channel group definitions to thing type" );
112
- ThingType type = builder .withChannelGroupDefinitions (groupDefs ).build ();
113
107
114
- putThingType (type );
115
- return true ;
116
- } else {
117
- logger .debug ("Error adding channel groups" );
118
- return false ;
119
- }
120
- }
121
-
122
- /**
123
- * Return a {@link ThingTypeBuilder} that can create an exact copy of the `ThingType` with `baseTypeUID`.
124
- * Further build steps can be performed on the returned object before recreating the `ThingType` from the builder.
125
- *
126
- * @param newTypeUID
127
- * @param baseTypeUID
128
- * @return the ThingTypeBuilder, null if `baseTypeUID` cannot be found in the thingTypeRegistry
129
- */
130
- private @ Nullable ThingTypeBuilder createThingTypeBuilder (ThingTypeUID newTypeUID , ThingTypeUID baseTypeUID ) {
131
- ThingType type = thingTypeRegistry .getThingType (baseTypeUID );
108
+ final ThingTypeBuilder builder = ThingTypeBuilder .instance (THING_TYPE_COMPUTER_IMPL , baseType .getLabel ());
109
+ builder .withChannelGroupDefinitions (baseType .getChannelGroupDefinitions ());
110
+ builder .withChannelDefinitions (baseType .getChannelDefinitions ());
111
+ builder .withExtensibleChannelTypeIds (baseType .getExtensibleChannelTypeIds ());
112
+ builder .withSupportedBridgeTypeUIDs (baseType .getSupportedBridgeTypeUIDs ());
113
+ builder .withProperties (baseType .getProperties ()).isListed (false );
132
114
133
- if (type == null ) {
134
- return null ;
135
- }
136
-
137
- ThingTypeBuilder result = ThingTypeBuilder .instance (newTypeUID , type .getLabel ())
138
- .withChannelGroupDefinitions (type .getChannelGroupDefinitions ())
139
- .withChannelDefinitions (type .getChannelDefinitions ())
140
- .withExtensibleChannelTypeIds (type .getExtensibleChannelTypeIds ())
141
- .withSupportedBridgeTypeUIDs (type .getSupportedBridgeTypeUIDs ()).withProperties (type .getProperties ())
142
- .isListed (false );
143
-
144
- String representationProperty = type .getRepresentationProperty ();
115
+ final String representationProperty = baseType .getRepresentationProperty ();
145
116
if (representationProperty != null ) {
146
- result = result .withRepresentationProperty (representationProperty );
117
+ builder .withRepresentationProperty (representationProperty );
147
118
}
148
- URI configDescriptionURI = type .getConfigDescriptionURI ();
119
+ final URI configDescriptionURI = baseType .getConfigDescriptionURI ();
149
120
if (configDescriptionURI != null ) {
150
- result = result .withConfigDescriptionURI (configDescriptionURI );
121
+ builder .withConfigDescriptionURI (configDescriptionURI );
151
122
}
152
- String category = type .getCategory ();
123
+ final String category = baseType .getCategory ();
153
124
if (category != null ) {
154
- result = result .withCategory (category );
125
+ builder .withCategory (category );
155
126
}
156
- String description = type .getDescription ();
127
+ final String description = baseType .getDescription ();
157
128
if (description != null ) {
158
- result = result .withDescription (description );
129
+ builder .withDescription (description );
159
130
}
160
131
161
- return result ;
132
+ logger .trace ("Adding channel group definitions to thing type" );
133
+ putThingType (builder .withChannelGroupDefinitions (channelGroupDefinitions ).build ());
162
134
}
163
135
164
136
/**
@@ -224,18 +196,19 @@ public List<ChannelGroupDefinition> getChannelGroupDefinitions(ThingTypeUID type
224
196
channelTypeUID != null ? channelTypeUID .getId () : "null" );
225
197
return null ;
226
198
}
227
- ThingUID thingUID = thing . getUID ();
199
+
228
200
String index = String .valueOf (i );
229
- ChannelUID channelUID = new ChannelUID (thingUID , channelID + index );
230
- ChannelBuilder builder = ChannelBuilder .create (channelUID ).withType (channelTypeUID )
231
- .withConfiguration (baseChannel .getConfiguration ());
201
+ ChannelUID channelUID = new ChannelUID (thing . getUID () , channelID + index );
202
+ ChannelBuilder builder = ChannelBuilder .create (channelUID ).withType (channelTypeUID );
203
+ builder .withConfiguration (baseChannel .getConfiguration ());
232
204
builder .withLabel (channelType .getLabel () + " " + index );
233
205
builder .withDefaultTags (channelType .getTags ());
234
- String description = channelType .getDescription ();
206
+
207
+ final String description = channelType .getDescription ();
235
208
if (description != null ) {
236
209
builder .withDescription (description );
237
210
}
238
- String itemType = channelType .getItemType ();
211
+ final String itemType = channelType .getItemType ();
239
212
if (itemType != null ) {
240
213
builder .withAcceptedItemType (itemType );
241
214
}
@@ -252,7 +225,7 @@ public List<ChannelGroupDefinition> getChannelGroupDefinitions(ThingTypeUID type
252
225
*/
253
226
public void storeChannelsConfig (Thing thing ) {
254
227
Map <String , Configuration > channelsConfig = thing .getChannels ().stream ()
255
- .collect (Collectors .toMap (c -> c .getUID ().getId (), c -> c . getConfiguration () ));
228
+ .collect (Collectors .toMap (c -> c .getUID ().getId (), Channel :: getConfiguration ));
256
229
thingChannelsConfig .put (thing .getUID (), channelsConfig );
257
230
}
258
231
0 commit comments