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.

[View source]

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

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.

[View source]

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

def config
  @config
end

#labelObject

Returns the value of attribute label.

[View source]

239
240
241
# File 'lib/openhab/dsl/things/builder.rb', line 239

def label
  @label
end

#typeObject (readonly)

Returns the value of attribute type.

[View source]

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

def type
  @type
end

#uidObject (readonly)

Returns the value of attribute uid.

[View source]

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

def uid
  @uid
end