Class: OpenHAB::DSL::Things::ThingBuilder
- Inherits:
-
Object
- Object
- OpenHAB::DSL::Things::ThingBuilder
- Defined in:
- lib/openhab/dsl/things/builder.rb
Overview
The ThingBuilder DSL allows you to customize a thing
Direct Known Subclasses
Instance Attribute Summary collapse
-
#bridge_uid ⇒ Core::Things::ThingUID?
readonly
The bridge of this thing.
-
#channels ⇒ Array<ChannelBuilder>
readonly
Explicitly configured channels on this thing.
-
#config ⇒ Hash?
readonly
The config for this thing.
-
#enabled ⇒ true, ...
readonly
If the thing should be enabled after it is created.
-
#label ⇒ String?
The label for this thing.
-
#location ⇒ String?
The location for this thing.
-
#thing_type_uid ⇒ ThingTypeUID
readonly
The type of this thing.
-
#uid ⇒ Core::Things::ThingUID
readonly
The id for this thing.
Instance Method Summary collapse
-
#channel(*args, **kwargs, &block) ⇒ Object
Add an explicitly configured channel to this item.
-
#initialize(uid, label = nil, binding: nil, type: nil, bridge: nil, location: nil, config: {}, enabled: nil) ⇒ ThingBuilder
constructor
Constructor for ThingBuilder.
Constructor Details
#initialize(uid, label = nil, binding: nil, type: nil, bridge: nil, location: nil, config: {}, enabled: nil) ⇒ ThingBuilder
Constructor for ThingBuilder
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/openhab/dsl/things/builder.rb', line 141 def initialize(uid, label = nil, binding: nil, type: nil, bridge: nil, location: nil, config: {}, enabled: nil) @channels = [] uid = uid.to_s uid_segments = uid.split(org.openhab.core.common.AbstractUID::SEPARATOR) @bridge_uid = nil bridge = bridge.uid if bridge.is_a?(org.openhab.core.thing.Bridge) || bridge.is_a?(BridgeBuilder) bridge = bridge&.to_s bridge_segments = bridge&.split(org.openhab.core.common.AbstractUID::SEPARATOR) || [] type = type&.to_s # infer missing components type ||= uid_segments[0] if uid_segments.length == 2 type ||= uid_segments[1] if uid_segments.length > 2 binding ||= uid_segments[0] if uid_segments.length > 2 binding ||= bridge_segments[0] if bridge_segments && bridge_segments.length > 2 if bridge bridge_segments.unshift(binding) if bridge_segments.length < 3 @bridge_uid = org.openhab.core.thing.ThingUID.new(*bridge_segments) end thinguid = if uid_segments.length > 2 [binding, type, uid_segments.last].compact else [binding, type, @bridge_uid&.id, uid_segments.last].compact end @uid = org.openhab.core.thing.ThingUID.new(*thinguid) @thing_type_uid = org.openhab.core.thing.ThingTypeUID.new(*@uid.all_segments[0..1]) @label = label @location = location @location = location.label if location.is_a?(Item) @config = config.transform_keys(&:to_s) @enabled = enabled end |
Instance Attribute Details
#bridge_uid ⇒ Core::Things::ThingUID? (readonly)
The bridge of this thing
87 88 89 |
# File 'lib/openhab/dsl/things/builder.rb', line 87 def bridge_uid @bridge_uid end |
#channels ⇒ Array<ChannelBuilder> (readonly)
Explicitly configured channels on this thing
96 97 98 |
# File 'lib/openhab/dsl/things/builder.rb', line 96 def channels @channels end |
#config ⇒ Hash? (readonly)
The config for this thing
90 91 92 |
# File 'lib/openhab/dsl/things/builder.rb', line 90 def config @config end |
#enabled ⇒ true, ... (readonly)
If the thing should be enabled after it is created
93 94 95 |
# File 'lib/openhab/dsl/things/builder.rb', line 93 def enabled @enabled end |
#label ⇒ String?
The label for this thing
75 76 77 |
# File 'lib/openhab/dsl/things/builder.rb', line 75 def label @label end |
#location ⇒ String?
The location for this thing
78 79 80 |
# File 'lib/openhab/dsl/things/builder.rb', line 78 def location @location end |
#thing_type_uid ⇒ ThingTypeUID (readonly)
The type of this thing
84 85 86 |
# File 'lib/openhab/dsl/things/builder.rb', line 84 def thing_type_uid @thing_type_uid end |
#uid ⇒ Core::Things::ThingUID (readonly)
The id for this thing
81 82 83 |
# File 'lib/openhab/dsl/things/builder.rb', line 81 def uid @uid end |
Instance Method Details
#channel(*args, **kwargs, &block) ⇒ Object
Add an explicitly configured channel to this item
179 180 181 182 183 |
# File 'lib/openhab/dsl/things/builder.rb', line 179 def channel(*args, **kwargs, &block) channel = ChannelBuilder.new(*args, thing: self, **kwargs) channel.instance_eval(&block) if block @channels << channel.build end |