-
Notifications
You must be signed in to change notification settings - Fork 779
allow referencing a channel type in the DSL #2343
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -100,3 +100,34 @@ Thing yahooweather:weather:losangeles [ location=2442047, unit="us", refresh=120 | |
``` | ||
|
||
Trigger channels are defined with the keyword `Trigger` and only support the type String. | ||
|
||
### Referencing existing channel types | ||
|
||
Many bindings provide standalone channel type definitions like this: | ||
|
||
``` | ||
<thing:thing-descriptions bindingId="yahooweather" [...]> | ||
<channel-type id="temperature"> | ||
<item-type>Number</item-type> | ||
<label>Temperature</label> | ||
<description>Current temperature in degrees celsius</description> | ||
<category>Temperature</category> | ||
<state readOnly="true" pattern="%.1f °C"> | ||
</state> | ||
</channel-type> | ||
[...] | ||
</thing:thing-descriptions> | ||
``` | ||
|
||
They can be referenced within a thing's channel definition, so that they need to be defined only once and can be reused for many channels. You may do so in the DSL as well: | ||
|
||
``` | ||
Thing yahooweather:weather:losangeles [ location=2442047, unit="us", refresh=120 ] { | ||
Channels: | ||
Type temperature : my_yesterday_temperature | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Question: Shall we actually also allow overriding (or defining) labels on channels (irrespectively whether they are based on a type or not)? Or is it good enough if people define their default label on the item (which probably suffices). Labels on channels are rather meant for bindings to provide them, so it might not be relevant for the DSL - just asking nonetheless. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Very good point. If you have a UI where you bind items to channels, you might want to see a nice name (aka label) instead of just the technical id. Therefore I think we should. |
||
} | ||
``` | ||
|
||
The `Type` keyword indicates a reference to an existing channel definition. The channel kind and accepted item types of course are takes from the channel definition, therefore they don't need to be specified here again. | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know anything about Xtext, but what about channelTypeUID if
it.channelType == null
(the else branch). It seems to be undefined / null. Is the call towithType
okay for a non-defined type?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it is. The ChannelBuilder is implemented in a way that setting it to null is the same as not setting it at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And more important, channels don't need to have a ChannelTypeUID at all: