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)  ⇒ Core::Things::Channel 
    
    
  
  
  
  
  
  
  
  
  
    
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
      159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193  | 
    
      # File 'lib/openhab/dsl/things/builder.rb', line 159 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
      105 106 107  | 
    
      # File 'lib/openhab/dsl/things/builder.rb', line 105 def bridge_uid @bridge_uid end  | 
  
#channels ⇒ Array<ChannelBuilder> (readonly)
Explicitly configured channels on this thing
      114 115 116  | 
    
      # File 'lib/openhab/dsl/things/builder.rb', line 114 def channels @channels end  | 
  
#config ⇒ Hash? (readonly)
The config for this thing
      108 109 110  | 
    
      # File 'lib/openhab/dsl/things/builder.rb', line 108 def config @config end  | 
  
#enabled ⇒ true, ... (readonly)
If the thing should be enabled after it is created
      111 112 113  | 
    
      # File 'lib/openhab/dsl/things/builder.rb', line 111 def enabled @enabled end  | 
  
#label ⇒ String?
The label for this thing
      93 94 95  | 
    
      # File 'lib/openhab/dsl/things/builder.rb', line 93 def label @label end  | 
  
#location ⇒ String?
The location for this thing
      96 97 98  | 
    
      # File 'lib/openhab/dsl/things/builder.rb', line 96 def location @location end  | 
  
#thing_type_uid ⇒ ThingTypeUID (readonly)
The type of this thing
      102 103 104  | 
    
      # File 'lib/openhab/dsl/things/builder.rb', line 102 def thing_type_uid @thing_type_uid end  | 
  
#uid ⇒ Core::Things::ThingUID (readonly)
The id for this thing
      99 100 101  | 
    
      # File 'lib/openhab/dsl/things/builder.rb', line 99 def uid @uid end  | 
  
Instance Method Details
#channel(*args, **kwargs, &block) ⇒ Core::Things::Channel
Add an explicitly configured channel to this item
      198 199 200 201 202  | 
    
      # File 'lib/openhab/dsl/things/builder.rb', line 198 def channel(*args, **kwargs, &block) channel = ChannelBuilder.new(*args, thing: self, **kwargs) channel.instance_eval(&block) if block channel.build.tap { |c| @channels << c } end  |