Class: OpenHAB::Core::Things::Channel

Inherits:
Object
  • Object
show all
Defined in:
lib/openhab/core/things/channel.rb

Overview

Channel is a part of a Thing that represents a functionality of it. Therefore Items can be linked a to a channel.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#channel_typeChannelType (readonly)

Returns:



51
52
53
# File 'lib/openhab/core/things/channel.rb', line 51

def channel_type
  ChannelType.registry.get_channel_type(channel_type_uid)
end

#channel_type_uidChannelTypeUID (readonly)

Returns:



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/openhab/core/things/channel.rb', line 29

class Channel
  extend Forwardable

  delegate %i[item items thing] => :uid

  # @return [String]
  def inspect
    r = "#<OpenHAB::Core::Things::Channel #{uid}"
    r += " #{label.inspect}" if label
    r += " description=#{description.inspect}" if description
    r += " kind=#{kind.inspect}"
    r += " channel_type_uid=#{channel_type_uid.inspect}" if channel_type_uid
    r += " configuration=#{configuration.properties.to_h}" unless configuration.properties.empty?
    r += " properties=#{properties.to_h}" unless properties.empty?
    r += " default_tags=#{default_tags.to_a}" unless default_tags.empty?
    r += " auto_update_policy=#{auto_update_policy}" if auto_update_policy
    r += " accepted_item_type=#{accepted_item_type}" if accepted_item_type
    "#{r}>"
  end

  # @!attribute [r] channel_type
  # @return [ChannelType]
  def channel_type
    ChannelType.registry.get_channel_type(channel_type_uid)
  end

  # @return [String]
  def to_s
    uid.to_s
  end

  # @deprecated OH3.4 this whole section is not needed in OH4+. Also see Thing#config_eql?
  if Core.version < Core::V4_0
    # @!visibility private
    module ChannelComparable
      # @!visibility private
      # This is only needed in OH3 because it is implemented in OH4 core
      def ==(other)
        return true if equal?(other)
        return false unless other.is_a?(Channel)

        %i[class
           uid
           label
           description
           kind
           channel_type_uid
           configuration
           properties
           default_tags
           auto_update_policy
           accepted_item_type].all? do |attr|
          send(attr) == other.send(attr)
        end
      end
    end
    org.openhab.core.thing.binding.builder.ChannelBuilder.const_get(:ChannelImpl).prepend(ChannelComparable)
  end
end

#itemItem? (readonly)

Return the item if this channel is linked with an item. If a channel is linked to more than one item, this method only returns the first item.

Returns:



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/openhab/core/things/channel.rb', line 29

class Channel
  extend Forwardable

  delegate %i[item items thing] => :uid

  # @return [String]
  def inspect
    r = "#<OpenHAB::Core::Things::Channel #{uid}"
    r += " #{label.inspect}" if label
    r += " description=#{description.inspect}" if description
    r += " kind=#{kind.inspect}"
    r += " channel_type_uid=#{channel_type_uid.inspect}" if channel_type_uid
    r += " configuration=#{configuration.properties.to_h}" unless configuration.properties.empty?
    r += " properties=#{properties.to_h}" unless properties.empty?
    r += " default_tags=#{default_tags.to_a}" unless default_tags.empty?
    r += " auto_update_policy=#{auto_update_policy}" if auto_update_policy
    r += " accepted_item_type=#{accepted_item_type}" if accepted_item_type
    "#{r}>"
  end

  # @!attribute [r] channel_type
  # @return [ChannelType]
  def channel_type
    ChannelType.registry.get_channel_type(channel_type_uid)
  end

  # @return [String]
  def to_s
    uid.to_s
  end

  # @deprecated OH3.4 this whole section is not needed in OH4+. Also see Thing#config_eql?
  if Core.version < Core::V4_0
    # @!visibility private
    module ChannelComparable
      # @!visibility private
      # This is only needed in OH3 because it is implemented in OH4 core
      def ==(other)
        return true if equal?(other)
        return false unless other.is_a?(Channel)

        %i[class
           uid
           label
           description
           kind
           channel_type_uid
           configuration
           properties
           default_tags
           auto_update_policy
           accepted_item_type].all? do |attr|
          send(attr) == other.send(attr)
        end
      end
    end
    org.openhab.core.thing.binding.builder.ChannelBuilder.const_get(:ChannelImpl).prepend(ChannelComparable)
  end
end

#itemsArray<Item> (readonly)

Returns all of the channel’s linked items.

Returns:

  • (Array<Item>)

    An array of things or an empty array



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/openhab/core/things/channel.rb', line 29

class Channel
  extend Forwardable

  delegate %i[item items thing] => :uid

  # @return [String]
  def inspect
    r = "#<OpenHAB::Core::Things::Channel #{uid}"
    r += " #{label.inspect}" if label
    r += " description=#{description.inspect}" if description
    r += " kind=#{kind.inspect}"
    r += " channel_type_uid=#{channel_type_uid.inspect}" if channel_type_uid
    r += " configuration=#{configuration.properties.to_h}" unless configuration.properties.empty?
    r += " properties=#{properties.to_h}" unless properties.empty?
    r += " default_tags=#{default_tags.to_a}" unless default_tags.empty?
    r += " auto_update_policy=#{auto_update_policy}" if auto_update_policy
    r += " accepted_item_type=#{accepted_item_type}" if accepted_item_type
    "#{r}>"
  end

  # @!attribute [r] channel_type
  # @return [ChannelType]
  def channel_type
    ChannelType.registry.get_channel_type(channel_type_uid)
  end

  # @return [String]
  def to_s
    uid.to_s
  end

  # @deprecated OH3.4 this whole section is not needed in OH4+. Also see Thing#config_eql?
  if Core.version < Core::V4_0
    # @!visibility private
    module ChannelComparable
      # @!visibility private
      # This is only needed in OH3 because it is implemented in OH4 core
      def ==(other)
        return true if equal?(other)
        return false unless other.is_a?(Channel)

        %i[class
           uid
           label
           description
           kind
           channel_type_uid
           configuration
           properties
           default_tags
           auto_update_policy
           accepted_item_type].all? do |attr|
          send(attr) == other.send(attr)
        end
      end
    end
    org.openhab.core.thing.binding.builder.ChannelBuilder.const_get(:ChannelImpl).prepend(ChannelComparable)
  end
end

#thingThing? (readonly)

Return the thing this channel is associated with.

Returns:



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/openhab/core/things/channel.rb', line 29

class Channel
  extend Forwardable

  delegate %i[item items thing] => :uid

  # @return [String]
  def inspect
    r = "#<OpenHAB::Core::Things::Channel #{uid}"
    r += " #{label.inspect}" if label
    r += " description=#{description.inspect}" if description
    r += " kind=#{kind.inspect}"
    r += " channel_type_uid=#{channel_type_uid.inspect}" if channel_type_uid
    r += " configuration=#{configuration.properties.to_h}" unless configuration.properties.empty?
    r += " properties=#{properties.to_h}" unless properties.empty?
    r += " default_tags=#{default_tags.to_a}" unless default_tags.empty?
    r += " auto_update_policy=#{auto_update_policy}" if auto_update_policy
    r += " accepted_item_type=#{accepted_item_type}" if accepted_item_type
    "#{r}>"
  end

  # @!attribute [r] channel_type
  # @return [ChannelType]
  def channel_type
    ChannelType.registry.get_channel_type(channel_type_uid)
  end

  # @return [String]
  def to_s
    uid.to_s
  end

  # @deprecated OH3.4 this whole section is not needed in OH4+. Also see Thing#config_eql?
  if Core.version < Core::V4_0
    # @!visibility private
    module ChannelComparable
      # @!visibility private
      # This is only needed in OH3 because it is implemented in OH4 core
      def ==(other)
        return true if equal?(other)
        return false unless other.is_a?(Channel)

        %i[class
           uid
           label
           description
           kind
           channel_type_uid
           configuration
           properties
           default_tags
           auto_update_policy
           accepted_item_type].all? do |attr|
          send(attr) == other.send(attr)
        end
      end
    end
    org.openhab.core.thing.binding.builder.ChannelBuilder.const_get(:ChannelImpl).prepend(ChannelComparable)
  end
end

#uidChannelUID (readonly)

Returns:



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/openhab/core/things/channel.rb', line 29

class Channel
  extend Forwardable

  delegate %i[item items thing] => :uid

  # @return [String]
  def inspect
    r = "#<OpenHAB::Core::Things::Channel #{uid}"
    r += " #{label.inspect}" if label
    r += " description=#{description.inspect}" if description
    r += " kind=#{kind.inspect}"
    r += " channel_type_uid=#{channel_type_uid.inspect}" if channel_type_uid
    r += " configuration=#{configuration.properties.to_h}" unless configuration.properties.empty?
    r += " properties=#{properties.to_h}" unless properties.empty?
    r += " default_tags=#{default_tags.to_a}" unless default_tags.empty?
    r += " auto_update_policy=#{auto_update_policy}" if auto_update_policy
    r += " accepted_item_type=#{accepted_item_type}" if accepted_item_type
    "#{r}>"
  end

  # @!attribute [r] channel_type
  # @return [ChannelType]
  def channel_type
    ChannelType.registry.get_channel_type(channel_type_uid)
  end

  # @return [String]
  def to_s
    uid.to_s
  end

  # @deprecated OH3.4 this whole section is not needed in OH4+. Also see Thing#config_eql?
  if Core.version < Core::V4_0
    # @!visibility private
    module ChannelComparable
      # @!visibility private
      # This is only needed in OH3 because it is implemented in OH4 core
      def ==(other)
        return true if equal?(other)
        return false unless other.is_a?(Channel)

        %i[class
           uid
           label
           description
           kind
           channel_type_uid
           configuration
           properties
           default_tags
           auto_update_policy
           accepted_item_type].all? do |attr|
          send(attr) == other.send(attr)
        end
      end
    end
    org.openhab.core.thing.binding.builder.ChannelBuilder.const_get(:ChannelImpl).prepend(ChannelComparable)
  end
end

Instance Method Details

#inspectString

Returns:

  • (String)


35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/openhab/core/things/channel.rb', line 35

def inspect
  r = "#<OpenHAB::Core::Things::Channel #{uid}"
  r += " #{label.inspect}" if label
  r += " description=#{description.inspect}" if description
  r += " kind=#{kind.inspect}"
  r += " channel_type_uid=#{channel_type_uid.inspect}" if channel_type_uid
  r += " configuration=#{configuration.properties.to_h}" unless configuration.properties.empty?
  r += " properties=#{properties.to_h}" unless properties.empty?
  r += " default_tags=#{default_tags.to_a}" unless default_tags.empty?
  r += " auto_update_policy=#{auto_update_policy}" if auto_update_policy
  r += " accepted_item_type=#{accepted_item_type}" if accepted_item_type
  "#{r}>"
end

#to_sString

Returns:

  • (String)


56
57
58
# File 'lib/openhab/core/things/channel.rb', line 56

def to_s
  uid.to_s
end