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:, description: nil, group: nil, config: nil, properties: nil, default_tags: nil, auto_update_policy: nil, accepted_item_type: nil) ⇒ 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.

  • description (String) (defaults to: nil)

    The channel description.

  • group (String) (defaults to: nil)

    The group name.

  • config (Hash) (defaults to: nil)

    Channel configuration. The keys can be strings or symbols.

  • properties (Hash) (defaults to: nil)

    The channel properties.

  • default_tags (String, Symbol, Semantics::Tag, Array<String,Symbol,Semantics::Tag>) (defaults to: nil)

    The default tags for this channel.

  • auto_update_policy (:default, :recommend, :veto, org.openhab.core.thing.type.AutoUpdatePolicy) (defaults to: nil)

    The channel's auto update policy.

  • accepted_item_type (String) (defaults to: nil)

    The accepted item type. If nil, infer the item type from the channel type.



298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
# File 'lib/openhab/dsl/things/builder.rb', line 298

def initialize(uid,
               type,
               label = nil,
               thing:,
               description: nil,
               group: nil,
               config: nil,
               properties: nil,
               default_tags: nil,
               auto_update_policy: nil,
               accepted_item_type: nil)
  @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)
  @default_tags = Items::ItemBuilder.normalize_tags(*Array.wrap(default_tags))
  @properties = properties&.transform_keys(&:to_s)
  @description = description
  @accepted_item_type = accepted_item_type
  return unless auto_update_policy

  @auto_update_policy = org.openhab.core.thing.type.AutoUpdatePolicy.value_of(auto_update_policy.to_s.upcase)
end

Instance Attribute Details

#accepted_item_typeString (readonly)

Returns The accepted item type.

Returns:

  • (String)

    The accepted item type.



357
358
359
# File 'lib/openhab/dsl/things/builder.rb', line 357

def accepted_item_type
  @accepted_item_type ||= self.class.channel_type_registry.get_channel_type(type)&.item_type
end

#auto_update_policyObject (readonly)

Returns the value of attribute auto_update_policy.



263
264
265
# File 'lib/openhab/dsl/things/builder.rb', line 263

def auto_update_policy
  @auto_update_policy
end

#configObject (readonly)

Returns the value of attribute config.



263
264
265
# File 'lib/openhab/dsl/things/builder.rb', line 263

def config
  @config
end

#default_tagsObject (readonly)

Returns the value of attribute default_tags.



263
264
265
# File 'lib/openhab/dsl/things/builder.rb', line 263

def default_tags
  @default_tags
end

#descriptionObject (readonly)

Returns the value of attribute description.



263
264
265
# File 'lib/openhab/dsl/things/builder.rb', line 263

def description
  @description
end

#labelObject

Returns the value of attribute label.



262
263
264
# File 'lib/openhab/dsl/things/builder.rb', line 262

def label
  @label
end

#propertiesObject (readonly)

Returns the value of attribute properties.



263
264
265
# File 'lib/openhab/dsl/things/builder.rb', line 263

def properties
  @properties
end

#typeObject (readonly)

Returns the value of attribute type.



263
264
265
# File 'lib/openhab/dsl/things/builder.rb', line 263

def type
  @type
end

#uidObject (readonly)

Returns the value of attribute uid.



263
264
265
# File 'lib/openhab/dsl/things/builder.rb', line 263

def uid
  @uid
end