Skip to content

Commit 65999cf

Browse files
authored
Kotlin DSL example
1 parent c65dbed commit 65999cf

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,5 +337,49 @@ W3C Web of Things (WoT) offers a mechanism that things can propagate metadata us
337337

338338
For more details, refer to the official [W3C Web of Things](https://www.w3.org/WoT/) website.
339339

340+
## Kotlin TD DSL
341+
342+
If you don't like annotations and prefer to build Thing Descriptions in code, you can also make use of a type-safe Kotlin DSL to define Thing Descriptions.
343+
344+
```
345+
wot.produce {
346+
id = "agent"
347+
title = "Agent"
348+
objectType = Type("Agent")
349+
intProperty("propertyName1") {
350+
minimum = 0
351+
maximum = 100
352+
observable = true
353+
unit = "percent"
354+
}
355+
stringSchema("propertyName2") {
356+
title = "Property 2"
357+
minLength = 5
358+
maxLength = 10
359+
}
360+
action<String, Map<*, *>>("inOutAction") {
361+
title = "title"
362+
description = "Description of an action"
363+
input = stringSchema {
364+
title = "Action Input"
365+
minLength = 10
366+
default = "test"
367+
}
368+
output = objectSchema {
369+
stringProperty("output")
370+
}
371+
}
372+
event<String, Nothing, Nothing>("statusUpdated") { data = StringSchema() }
373+
}.apply {
374+
setPropertyReadHandler(propertyName1) { 10.toInteractionInputValue() }
375+
setPropertyReadHandler(propertyName2) { 5.toInteractionInputValue() }
376+
setPropertyWriteHandler(inOutAction) { input, _ ->
377+
}
378+
setActionHandler(ACTION_NAME) { input, _ ->
379+
}
380+
}
381+
}
382+
```
383+
340384

341385

0 commit comments

Comments
 (0)