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.



257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
# File 'lib/openhab/dsl/things/builder.rb', line 257

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.



242
243
244
# File 'lib/openhab/dsl/things/builder.rb', line 242

def config
  @config
end

#labelObject

Returns the value of attribute label.



241
242
243
# File 'lib/openhab/dsl/things/builder.rb', line 241

def label
  @label
end

#typeObject (readonly)

Returns the value of attribute type.



242
243
244
# File 'lib/openhab/dsl/things/builder.rb', line 242

def type
  @type
end

#uidObject (readonly)

Returns the value of attribute uid.



242
243
244
# File 'lib/openhab/dsl/things/builder.rb', line 242

def uid
  @uid
end