Class: OpenHAB::DSL::Things::ChannelBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/openhab/dsl/things/builder.rb

Overview

The ChannelBuilder DSL allows you to customize a channel

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uid, type, label = nil, thing:, group: nil, config: {}) ⇒ ChannelBuilder

Constructor for ChannelBuilder

This class is instantiated by the #channel method inside a Builder#thing block.

Parameters:

  • uid (String)

    The channel's ID.

  • type (String, ChannelTypeUID, :trigger)

    The concrete type of the channel.

  • label (String) (defaults to: nil)

    The channel label.

  • thing (thing)

    The thing associated with this channel. This parameter is not needed for the ThingBuilder#channel method.

  • group (String) (defaults to: nil)

    The group name.

  • config (Hash) (defaults to: {})

    Channel configuration. The keys can be strings or symbols.



275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
# File 'lib/openhab/dsl/things/builder.rb', line 275

def initialize(uid, type, label = nil, thing:, group: nil, config: {})
  @thing = thing

  uid = uid.to_s
  uid_segments = uid.split(org.openhab.core.common.AbstractUID::SEPARATOR)
  group_segments = uid_segments.last.split(org.openhab.core.thing.ChannelUID::CHANNEL_GROUP_SEPARATOR)
  if group
    if group_segments.length == 2
      group_segments[0] = group
    else
      group_segments.unshift(group)
    end
    uid_segments[-1] = group_segments.join(org.openhab.core.thing.ChannelUID::CHANNEL_GROUP_SEPARATOR)
  end
  @uid = org.openhab.core.thing.ChannelUID.new(thing.uid, uid_segments.last)
  unless type.is_a?(org.openhab.core.thing.type.ChannelTypeUID)
    type = org.openhab.core.thing.type.ChannelTypeUID.new(thing.uid.binding_id, type)
  end
  @type = type
  @label = label
  @config = config.transform_keys(&:to_s)
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



260
261
262
# File 'lib/openhab/dsl/things/builder.rb', line 260

def config
  @config
end

#labelObject

Returns the value of attribute label.



259
260
261
# File 'lib/openhab/dsl/things/builder.rb', line 259

def label
  @label
end

#typeObject (readonly)

Returns the value of attribute type.



260
261
262
# File 'lib/openhab/dsl/things/builder.rb', line 260

def type
  @type
end

#uidObject (readonly)

Returns the value of attribute uid.



260
261
262
# File 'lib/openhab/dsl/things/builder.rb', line 260

def uid
  @uid
end