Module: OpenHAB::Core::Things::Thing

Defined in:
lib/openhab/core/things/thing.rb

Overview

A Thing is a representation of a connected part (e.g. physical device or cloud service) from the real world. It contains a list of Channels, which can be bound to Items.

Examples:

thing = things["chromecast:audiogroup:dd9f8622-eee-4eaf-b33f-cdcdcdeee001121"]
logger.info("Audiogroup Status: #{thing&.status}")
logger.info("Audiogroup Online? #{thing&.online?}")
logger.info("Channel ids: #{thing.channels.map(&:uid)}")
logger.info("Items linked to volume channel: #{thing.channels['volume']&.items&.map(&:name)&.join(', ')}")
logger.info("Item linked to volume channel: #{thing.channels['volume']&.item&.name}")

Thing actions can be called directly through a Thing object

things["mqtt:broker:mosquitto"].publish_mqtt("zigbee2mqttt/bridge/config/permit_join", "true")
things["mail:smtp:local"].send_mail("me@example.com", "Subject", "Email body")

Thing can be accessed directly through entity lookup

# replace ':' with '_' in thing uid
mqtt_broker_mosquitto.online? # is mqtt:broker:mosquitto thing online?

See Also:

Defined Under Namespace

Classes: ChannelsArray

Instance Attribute Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object

Delegate missing methods to the thing's default actions scope.

Examples:

things['mail:smtp:local'].send_email('me@example.com', 'subject', 'message')


251
252
253
254
255
# File 'lib/openhab/core/things/thing.rb', line 251

def method_missing(method, *args, &block)
  return actions.public_send(method, *args, &block) if actions.respond_to?(method)

  super
end

Instance Attribute Details

#bridgeThing? (readonly)

Returns:



178
179
180
# File 'lib/openhab/core/things/thing.rb', line 178

def bridge
  bridge_uid && EntityLookup.lookup_thing(bridge_uid)
end

#bridge_uidThingUID? (readonly)

Return the Bridge UID when available.

Returns:



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
# File 'lib/openhab/core/things/thing.rb', line 74

module Thing
  # Array wrapper class to allow searching a list of channels
  # by channel id
  class ChannelsArray < Array
    def initialize(thing, array)
      super(array)
      @thing = thing
    end

    # Allows indexing by both integer as an array or channel id acting like a hash.
    # @param [Integer, String, ChannelUID] index
    #   Numeric index, string channel id, or a {ChannelUID} to search for.
    # @return [Channel, nil]
    def [](index)
      return @thing.get_channel(index) if index.is_a?(ChannelUID)
      return @thing.get_channel(index.to_str) if index.respond_to?(:to_str)

      super
    end
  end

  class << self
    # @!visibility private
    #
    # Override to support Proxy
    #
    def ===(other)
      other.is_a?(self)
    end
  end

  #
  # @!method uninitialized?
  #   Check if thing status == UNINITIALIZED
  #   @return [true,false]
  #

  #
  # @!method initialized?
  #   Check if thing status == INITIALIZED
  #   @return [true,false]
  #

  #
  # @!method unknown?
  #   Check if thing status == UNKNOWN
  #   @return [true,false]
  #

  #
  # @!method online?
  #   Check if thing status == ONLINE
  #   @return [true,false]
  #

  #
  # @!method offline?
  #   Check if thing status == OFFLINE
  #   @return [true,false]
  #

  #
  # @!method removing?
  #   Check if thing status == REMOVING
  #   @return [true,false]
  #

  #
  # @!method removed?
  #   Check if thing status == REMOVED
  #   @return [true,false]
  #

  ThingStatus.constants.each do |thingstatus|
    define_method(:"#{thingstatus.to_s.downcase}?") { status == ThingStatus.value_of(thingstatus) }
  end

  #
  # Enable the Thing
  #
  # @param [true, false] enabled
  # @return [void]
  #
  def enable(enabled: true)
    Things.manager.set_enabled(uid, enabled)
  end

  #
  # Disable the Thing
  #
  # @return [void]
  #
  def disable
    enable(enabled: false)
  end

  # @!attribute [r] thing_type
  # @return [ThingType]
  def thing_type
    ThingType.registry.get_thing_type(thing_type_uid)
  end

  # @!attribute [r] bridge
  # @return [Thing, nil]
  def bridge
    bridge_uid && EntityLookup.lookup_thing(bridge_uid)
  end

  # @return [true,false] true if this Thing is a bridge
  def bridge?
    is_a?(org.openhab.core.thing.Bridge)
  end

  # @return [String]
  def inspect
    r = "#<OpenHAB::Core::Things::Thing #{uid}"
    r += " #{label.inspect}" if label
    r += " (#{location.inspect})" if location
    r += " #{status}"
    unless status_info.status_detail == org.openhab.core.thing.ThingStatusDetail::NONE
      r += " (#{status_info.status_detail})"
    end
    r += " configuration=#{configuration.properties.to_h}" unless configuration.properties.empty?
    r += " properties=#{properties.to_h}" unless properties.empty?
    "#{r}>"
  end

  #
  # Return Thing's uid as a string
  #
  # @return [String]
  #
  def to_s
    uid.to_s
  end

  # @return [org.openhab.core.common.registry.Provider, nil]
  def provider
    Provider.registry.provider_for(uid)
  end

  #
  # Fetches the actions available for this thing.
  #
  # Default scope actions are available directly on the thing object, via
  # {#method_missing}.
  #
  # @param [String, nil] scope The action scope. Default's to the thing's binding.
  # @return [Object, nil]
  #
  # @example
  #   things["max:thermostat:mybridge:thermostat"].actions("max-devices").delete_from_cube
  #
  # @example (see #method_missing)
  #
  def actions(scope = nil)
    $actions.get(scope || uid.binding_id, uid.to_s)
  end

  #
  # Compares all attributes of the thing with another thing.
  #
  # @param other [Thing] The thing to compare with
  # @return [true,false] true if all attributes are equal, false otherwise
  #
  def config_eql?(other)
    # @deprecated OH3.4 - in OH4, channels can be included in the array and do not need to be compared separately
    channels.to_a == other.channels.to_a &&
      %i[uid label bridge_uid location configuration].all? { |method| send(method) == other.send(method) }
  end

  #
  # Delegate missing methods to the thing's default actions scope.
  #
  # @example
  #   things['mail:smtp:local'].send_email('me@example.com', 'subject', 'message')
  #
  def method_missing(method, *args, &block)
    return actions.public_send(method, *args, &block) if actions.respond_to?(method)

    super
  end

  # @!visibility private
  def respond_to_missing?(method_name, _include_private = false)
    logger.trace { "Checking if Thing #{uid} supports #{method_name} action" }
    return true if actions.respond_to?(method_name)

    super
  end
end

#channelsChannelsArray (readonly)

Returns:



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
# File 'lib/openhab/core/things/thing.rb', line 74

module Thing
  # Array wrapper class to allow searching a list of channels
  # by channel id
  class ChannelsArray < Array
    def initialize(thing, array)
      super(array)
      @thing = thing
    end

    # Allows indexing by both integer as an array or channel id acting like a hash.
    # @param [Integer, String, ChannelUID] index
    #   Numeric index, string channel id, or a {ChannelUID} to search for.
    # @return [Channel, nil]
    def [](index)
      return @thing.get_channel(index) if index.is_a?(ChannelUID)
      return @thing.get_channel(index.to_str) if index.respond_to?(:to_str)

      super
    end
  end

  class << self
    # @!visibility private
    #
    # Override to support Proxy
    #
    def ===(other)
      other.is_a?(self)
    end
  end

  #
  # @!method uninitialized?
  #   Check if thing status == UNINITIALIZED
  #   @return [true,false]
  #

  #
  # @!method initialized?
  #   Check if thing status == INITIALIZED
  #   @return [true,false]
  #

  #
  # @!method unknown?
  #   Check if thing status == UNKNOWN
  #   @return [true,false]
  #

  #
  # @!method online?
  #   Check if thing status == ONLINE
  #   @return [true,false]
  #

  #
  # @!method offline?
  #   Check if thing status == OFFLINE
  #   @return [true,false]
  #

  #
  # @!method removing?
  #   Check if thing status == REMOVING
  #   @return [true,false]
  #

  #
  # @!method removed?
  #   Check if thing status == REMOVED
  #   @return [true,false]
  #

  ThingStatus.constants.each do |thingstatus|
    define_method(:"#{thingstatus.to_s.downcase}?") { status == ThingStatus.value_of(thingstatus) }
  end

  #
  # Enable the Thing
  #
  # @param [true, false] enabled
  # @return [void]
  #
  def enable(enabled: true)
    Things.manager.set_enabled(uid, enabled)
  end

  #
  # Disable the Thing
  #
  # @return [void]
  #
  def disable
    enable(enabled: false)
  end

  # @!attribute [r] thing_type
  # @return [ThingType]
  def thing_type
    ThingType.registry.get_thing_type(thing_type_uid)
  end

  # @!attribute [r] bridge
  # @return [Thing, nil]
  def bridge
    bridge_uid && EntityLookup.lookup_thing(bridge_uid)
  end

  # @return [true,false] true if this Thing is a bridge
  def bridge?
    is_a?(org.openhab.core.thing.Bridge)
  end

  # @return [String]
  def inspect
    r = "#<OpenHAB::Core::Things::Thing #{uid}"
    r += " #{label.inspect}" if label
    r += " (#{location.inspect})" if location
    r += " #{status}"
    unless status_info.status_detail == org.openhab.core.thing.ThingStatusDetail::NONE
      r += " (#{status_info.status_detail})"
    end
    r += " configuration=#{configuration.properties.to_h}" unless configuration.properties.empty?
    r += " properties=#{properties.to_h}" unless properties.empty?
    "#{r}>"
  end

  #
  # Return Thing's uid as a string
  #
  # @return [String]
  #
  def to_s
    uid.to_s
  end

  # @return [org.openhab.core.common.registry.Provider, nil]
  def provider
    Provider.registry.provider_for(uid)
  end

  #
  # Fetches the actions available for this thing.
  #
  # Default scope actions are available directly on the thing object, via
  # {#method_missing}.
  #
  # @param [String, nil] scope The action scope. Default's to the thing's binding.
  # @return [Object, nil]
  #
  # @example
  #   things["max:thermostat:mybridge:thermostat"].actions("max-devices").delete_from_cube
  #
  # @example (see #method_missing)
  #
  def actions(scope = nil)
    $actions.get(scope || uid.binding_id, uid.to_s)
  end

  #
  # Compares all attributes of the thing with another thing.
  #
  # @param other [Thing] The thing to compare with
  # @return [true,false] true if all attributes are equal, false otherwise
  #
  def config_eql?(other)
    # @deprecated OH3.4 - in OH4, channels can be included in the array and do not need to be compared separately
    channels.to_a == other.channels.to_a &&
      %i[uid label bridge_uid location configuration].all? { |method| send(method) == other.send(method) }
  end

  #
  # Delegate missing methods to the thing's default actions scope.
  #
  # @example
  #   things['mail:smtp:local'].send_email('me@example.com', 'subject', 'message')
  #
  def method_missing(method, *args, &block)
    return actions.public_send(method, *args, &block) if actions.respond_to?(method)

    super
  end

  # @!visibility private
  def respond_to_missing?(method_name, _include_private = false)
    logger.trace { "Checking if Thing #{uid} supports #{method_name} action" }
    return true if actions.respond_to?(method_name)

    super
  end
end

#configurationOpenHAB::Core::Configuration (readonly)

Return the thing's configuration.

Examples:

logger.info things["smtp:mail:local"].configuration["hostname"]
logger.info things["ipcamera:dahua:frontporch"].configuration["ipAddress"]

Returns:



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
# File 'lib/openhab/core/things/thing.rb', line 74

module Thing
  # Array wrapper class to allow searching a list of channels
  # by channel id
  class ChannelsArray < Array
    def initialize(thing, array)
      super(array)
      @thing = thing
    end

    # Allows indexing by both integer as an array or channel id acting like a hash.
    # @param [Integer, String, ChannelUID] index
    #   Numeric index, string channel id, or a {ChannelUID} to search for.
    # @return [Channel, nil]
    def [](index)
      return @thing.get_channel(index) if index.is_a?(ChannelUID)
      return @thing.get_channel(index.to_str) if index.respond_to?(:to_str)

      super
    end
  end

  class << self
    # @!visibility private
    #
    # Override to support Proxy
    #
    def ===(other)
      other.is_a?(self)
    end
  end

  #
  # @!method uninitialized?
  #   Check if thing status == UNINITIALIZED
  #   @return [true,false]
  #

  #
  # @!method initialized?
  #   Check if thing status == INITIALIZED
  #   @return [true,false]
  #

  #
  # @!method unknown?
  #   Check if thing status == UNKNOWN
  #   @return [true,false]
  #

  #
  # @!method online?
  #   Check if thing status == ONLINE
  #   @return [true,false]
  #

  #
  # @!method offline?
  #   Check if thing status == OFFLINE
  #   @return [true,false]
  #

  #
  # @!method removing?
  #   Check if thing status == REMOVING
  #   @return [true,false]
  #

  #
  # @!method removed?
  #   Check if thing status == REMOVED
  #   @return [true,false]
  #

  ThingStatus.constants.each do |thingstatus|
    define_method(:"#{thingstatus.to_s.downcase}?") { status == ThingStatus.value_of(thingstatus) }
  end

  #
  # Enable the Thing
  #
  # @param [true, false] enabled
  # @return [void]
  #
  def enable(enabled: true)
    Things.manager.set_enabled(uid, enabled)
  end

  #
  # Disable the Thing
  #
  # @return [void]
  #
  def disable
    enable(enabled: false)
  end

  # @!attribute [r] thing_type
  # @return [ThingType]
  def thing_type
    ThingType.registry.get_thing_type(thing_type_uid)
  end

  # @!attribute [r] bridge
  # @return [Thing, nil]
  def bridge
    bridge_uid && EntityLookup.lookup_thing(bridge_uid)
  end

  # @return [true,false] true if this Thing is a bridge
  def bridge?
    is_a?(org.openhab.core.thing.Bridge)
  end

  # @return [String]
  def inspect
    r = "#<OpenHAB::Core::Things::Thing #{uid}"
    r += " #{label.inspect}" if label
    r += " (#{location.inspect})" if location
    r += " #{status}"
    unless status_info.status_detail == org.openhab.core.thing.ThingStatusDetail::NONE
      r += " (#{status_info.status_detail})"
    end
    r += " configuration=#{configuration.properties.to_h}" unless configuration.properties.empty?
    r += " properties=#{properties.to_h}" unless properties.empty?
    "#{r}>"
  end

  #
  # Return Thing's uid as a string
  #
  # @return [String]
  #
  def to_s
    uid.to_s
  end

  # @return [org.openhab.core.common.registry.Provider, nil]
  def provider
    Provider.registry.provider_for(uid)
  end

  #
  # Fetches the actions available for this thing.
  #
  # Default scope actions are available directly on the thing object, via
  # {#method_missing}.
  #
  # @param [String, nil] scope The action scope. Default's to the thing's binding.
  # @return [Object, nil]
  #
  # @example
  #   things["max:thermostat:mybridge:thermostat"].actions("max-devices").delete_from_cube
  #
  # @example (see #method_missing)
  #
  def actions(scope = nil)
    $actions.get(scope || uid.binding_id, uid.to_s)
  end

  #
  # Compares all attributes of the thing with another thing.
  #
  # @param other [Thing] The thing to compare with
  # @return [true,false] true if all attributes are equal, false otherwise
  #
  def config_eql?(other)
    # @deprecated OH3.4 - in OH4, channels can be included in the array and do not need to be compared separately
    channels.to_a == other.channels.to_a &&
      %i[uid label bridge_uid location configuration].all? { |method| send(method) == other.send(method) }
  end

  #
  # Delegate missing methods to the thing's default actions scope.
  #
  # @example
  #   things['mail:smtp:local'].send_email('me@example.com', 'subject', 'message')
  #
  def method_missing(method, *args, &block)
    return actions.public_send(method, *args, &block) if actions.respond_to?(method)

    super
  end

  # @!visibility private
  def respond_to_missing?(method_name, _include_private = false)
    logger.trace { "Checking if Thing #{uid} supports #{method_name} action" }
    return true if actions.respond_to?(method_name)

    super
  end
end

#labelString

Return the thing label

Returns:

  • (String)


74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
# File 'lib/openhab/core/things/thing.rb', line 74

module Thing
  # Array wrapper class to allow searching a list of channels
  # by channel id
  class ChannelsArray < Array
    def initialize(thing, array)
      super(array)
      @thing = thing
    end

    # Allows indexing by both integer as an array or channel id acting like a hash.
    # @param [Integer, String, ChannelUID] index
    #   Numeric index, string channel id, or a {ChannelUID} to search for.
    # @return [Channel, nil]
    def [](index)
      return @thing.get_channel(index) if index.is_a?(ChannelUID)
      return @thing.get_channel(index.to_str) if index.respond_to?(:to_str)

      super
    end
  end

  class << self
    # @!visibility private
    #
    # Override to support Proxy
    #
    def ===(other)
      other.is_a?(self)
    end
  end

  #
  # @!method uninitialized?
  #   Check if thing status == UNINITIALIZED
  #   @return [true,false]
  #

  #
  # @!method initialized?
  #   Check if thing status == INITIALIZED
  #   @return [true,false]
  #

  #
  # @!method unknown?
  #   Check if thing status == UNKNOWN
  #   @return [true,false]
  #

  #
  # @!method online?
  #   Check if thing status == ONLINE
  #   @return [true,false]
  #

  #
  # @!method offline?
  #   Check if thing status == OFFLINE
  #   @return [true,false]
  #

  #
  # @!method removing?
  #   Check if thing status == REMOVING
  #   @return [true,false]
  #

  #
  # @!method removed?
  #   Check if thing status == REMOVED
  #   @return [true,false]
  #

  ThingStatus.constants.each do |thingstatus|
    define_method(:"#{thingstatus.to_s.downcase}?") { status == ThingStatus.value_of(thingstatus) }
  end

  #
  # Enable the Thing
  #
  # @param [true, false] enabled
  # @return [void]
  #
  def enable(enabled: true)
    Things.manager.set_enabled(uid, enabled)
  end

  #
  # Disable the Thing
  #
  # @return [void]
  #
  def disable
    enable(enabled: false)
  end

  # @!attribute [r] thing_type
  # @return [ThingType]
  def thing_type
    ThingType.registry.get_thing_type(thing_type_uid)
  end

  # @!attribute [r] bridge
  # @return [Thing, nil]
  def bridge
    bridge_uid && EntityLookup.lookup_thing(bridge_uid)
  end

  # @return [true,false] true if this Thing is a bridge
  def bridge?
    is_a?(org.openhab.core.thing.Bridge)
  end

  # @return [String]
  def inspect
    r = "#<OpenHAB::Core::Things::Thing #{uid}"
    r += " #{label.inspect}" if label
    r += " (#{location.inspect})" if location
    r += " #{status}"
    unless status_info.status_detail == org.openhab.core.thing.ThingStatusDetail::NONE
      r += " (#{status_info.status_detail})"
    end
    r += " configuration=#{configuration.properties.to_h}" unless configuration.properties.empty?
    r += " properties=#{properties.to_h}" unless properties.empty?
    "#{r}>"
  end

  #
  # Return Thing's uid as a string
  #
  # @return [String]
  #
  def to_s
    uid.to_s
  end

  # @return [org.openhab.core.common.registry.Provider, nil]
  def provider
    Provider.registry.provider_for(uid)
  end

  #
  # Fetches the actions available for this thing.
  #
  # Default scope actions are available directly on the thing object, via
  # {#method_missing}.
  #
  # @param [String, nil] scope The action scope. Default's to the thing's binding.
  # @return [Object, nil]
  #
  # @example
  #   things["max:thermostat:mybridge:thermostat"].actions("max-devices").delete_from_cube
  #
  # @example (see #method_missing)
  #
  def actions(scope = nil)
    $actions.get(scope || uid.binding_id, uid.to_s)
  end

  #
  # Compares all attributes of the thing with another thing.
  #
  # @param other [Thing] The thing to compare with
  # @return [true,false] true if all attributes are equal, false otherwise
  #
  def config_eql?(other)
    # @deprecated OH3.4 - in OH4, channels can be included in the array and do not need to be compared separately
    channels.to_a == other.channels.to_a &&
      %i[uid label bridge_uid location configuration].all? { |method| send(method) == other.send(method) }
  end

  #
  # Delegate missing methods to the thing's default actions scope.
  #
  # @example
  #   things['mail:smtp:local'].send_email('me@example.com', 'subject', 'message')
  #
  def method_missing(method, *args, &block)
    return actions.public_send(method, *args, &block) if actions.respond_to?(method)

    super
  end

  # @!visibility private
  def respond_to_missing?(method_name, _include_private = false)
    logger.trace { "Checking if Thing #{uid} supports #{method_name} action" }
    return true if actions.respond_to?(method_name)

    super
  end
end

#locationString

Return the thing location

Returns:

  • (String)


74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
# File 'lib/openhab/core/things/thing.rb', line 74

module Thing
  # Array wrapper class to allow searching a list of channels
  # by channel id
  class ChannelsArray < Array
    def initialize(thing, array)
      super(array)
      @thing = thing
    end

    # Allows indexing by both integer as an array or channel id acting like a hash.
    # @param [Integer, String, ChannelUID] index
    #   Numeric index, string channel id, or a {ChannelUID} to search for.
    # @return [Channel, nil]
    def [](index)
      return @thing.get_channel(index) if index.is_a?(ChannelUID)
      return @thing.get_channel(index.to_str) if index.respond_to?(:to_str)

      super
    end
  end

  class << self
    # @!visibility private
    #
    # Override to support Proxy
    #
    def ===(other)
      other.is_a?(self)
    end
  end

  #
  # @!method uninitialized?
  #   Check if thing status == UNINITIALIZED
  #   @return [true,false]
  #

  #
  # @!method initialized?
  #   Check if thing status == INITIALIZED
  #   @return [true,false]
  #

  #
  # @!method unknown?
  #   Check if thing status == UNKNOWN
  #   @return [true,false]
  #

  #
  # @!method online?
  #   Check if thing status == ONLINE
  #   @return [true,false]
  #

  #
  # @!method offline?
  #   Check if thing status == OFFLINE
  #   @return [true,false]
  #

  #
  # @!method removing?
  #   Check if thing status == REMOVING
  #   @return [true,false]
  #

  #
  # @!method removed?
  #   Check if thing status == REMOVED
  #   @return [true,false]
  #

  ThingStatus.constants.each do |thingstatus|
    define_method(:"#{thingstatus.to_s.downcase}?") { status == ThingStatus.value_of(thingstatus) }
  end

  #
  # Enable the Thing
  #
  # @param [true, false] enabled
  # @return [void]
  #
  def enable(enabled: true)
    Things.manager.set_enabled(uid, enabled)
  end

  #
  # Disable the Thing
  #
  # @return [void]
  #
  def disable
    enable(enabled: false)
  end

  # @!attribute [r] thing_type
  # @return [ThingType]
  def thing_type
    ThingType.registry.get_thing_type(thing_type_uid)
  end

  # @!attribute [r] bridge
  # @return [Thing, nil]
  def bridge
    bridge_uid && EntityLookup.lookup_thing(bridge_uid)
  end

  # @return [true,false] true if this Thing is a bridge
  def bridge?
    is_a?(org.openhab.core.thing.Bridge)
  end

  # @return [String]
  def inspect
    r = "#<OpenHAB::Core::Things::Thing #{uid}"
    r += " #{label.inspect}" if label
    r += " (#{location.inspect})" if location
    r += " #{status}"
    unless status_info.status_detail == org.openhab.core.thing.ThingStatusDetail::NONE
      r += " (#{status_info.status_detail})"
    end
    r += " configuration=#{configuration.properties.to_h}" unless configuration.properties.empty?
    r += " properties=#{properties.to_h}" unless properties.empty?
    "#{r}>"
  end

  #
  # Return Thing's uid as a string
  #
  # @return [String]
  #
  def to_s
    uid.to_s
  end

  # @return [org.openhab.core.common.registry.Provider, nil]
  def provider
    Provider.registry.provider_for(uid)
  end

  #
  # Fetches the actions available for this thing.
  #
  # Default scope actions are available directly on the thing object, via
  # {#method_missing}.
  #
  # @param [String, nil] scope The action scope. Default's to the thing's binding.
  # @return [Object, nil]
  #
  # @example
  #   things["max:thermostat:mybridge:thermostat"].actions("max-devices").delete_from_cube
  #
  # @example (see #method_missing)
  #
  def actions(scope = nil)
    $actions.get(scope || uid.binding_id, uid.to_s)
  end

  #
  # Compares all attributes of the thing with another thing.
  #
  # @param other [Thing] The thing to compare with
  # @return [true,false] true if all attributes are equal, false otherwise
  #
  def config_eql?(other)
    # @deprecated OH3.4 - in OH4, channels can be included in the array and do not need to be compared separately
    channels.to_a == other.channels.to_a &&
      %i[uid label bridge_uid location configuration].all? { |method| send(method) == other.send(method) }
  end

  #
  # Delegate missing methods to the thing's default actions scope.
  #
  # @example
  #   things['mail:smtp:local'].send_email('me@example.com', 'subject', 'message')
  #
  def method_missing(method, *args, &block)
    return actions.public_send(method, *args, &block) if actions.respond_to?(method)

    super
  end

  # @!visibility private
  def respond_to_missing?(method_name, _include_private = false)
    logger.trace { "Checking if Thing #{uid} supports #{method_name} action" }
    return true if actions.respond_to?(method_name)

    super
  end
end

#propertiesHash (readonly)

Return the properties when available.

Examples:

logger.info things["fronius:meter:mybridge:mymeter"].properties["modelId"]

Returns:

  • (Hash)


74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
# File 'lib/openhab/core/things/thing.rb', line 74

module Thing
  # Array wrapper class to allow searching a list of channels
  # by channel id
  class ChannelsArray < Array
    def initialize(thing, array)
      super(array)
      @thing = thing
    end

    # Allows indexing by both integer as an array or channel id acting like a hash.
    # @param [Integer, String, ChannelUID] index
    #   Numeric index, string channel id, or a {ChannelUID} to search for.
    # @return [Channel, nil]
    def [](index)
      return @thing.get_channel(index) if index.is_a?(ChannelUID)
      return @thing.get_channel(index.to_str) if index.respond_to?(:to_str)

      super
    end
  end

  class << self
    # @!visibility private
    #
    # Override to support Proxy
    #
    def ===(other)
      other.is_a?(self)
    end
  end

  #
  # @!method uninitialized?
  #   Check if thing status == UNINITIALIZED
  #   @return [true,false]
  #

  #
  # @!method initialized?
  #   Check if thing status == INITIALIZED
  #   @return [true,false]
  #

  #
  # @!method unknown?
  #   Check if thing status == UNKNOWN
  #   @return [true,false]
  #

  #
  # @!method online?
  #   Check if thing status == ONLINE
  #   @return [true,false]
  #

  #
  # @!method offline?
  #   Check if thing status == OFFLINE
  #   @return [true,false]
  #

  #
  # @!method removing?
  #   Check if thing status == REMOVING
  #   @return [true,false]
  #

  #
  # @!method removed?
  #   Check if thing status == REMOVED
  #   @return [true,false]
  #

  ThingStatus.constants.each do |thingstatus|
    define_method(:"#{thingstatus.to_s.downcase}?") { status == ThingStatus.value_of(thingstatus) }
  end

  #
  # Enable the Thing
  #
  # @param [true, false] enabled
  # @return [void]
  #
  def enable(enabled: true)
    Things.manager.set_enabled(uid, enabled)
  end

  #
  # Disable the Thing
  #
  # @return [void]
  #
  def disable
    enable(enabled: false)
  end

  # @!attribute [r] thing_type
  # @return [ThingType]
  def thing_type
    ThingType.registry.get_thing_type(thing_type_uid)
  end

  # @!attribute [r] bridge
  # @return [Thing, nil]
  def bridge
    bridge_uid && EntityLookup.lookup_thing(bridge_uid)
  end

  # @return [true,false] true if this Thing is a bridge
  def bridge?
    is_a?(org.openhab.core.thing.Bridge)
  end

  # @return [String]
  def inspect
    r = "#<OpenHAB::Core::Things::Thing #{uid}"
    r += " #{label.inspect}" if label
    r += " (#{location.inspect})" if location
    r += " #{status}"
    unless status_info.status_detail == org.openhab.core.thing.ThingStatusDetail::NONE
      r += " (#{status_info.status_detail})"
    end
    r += " configuration=#{configuration.properties.to_h}" unless configuration.properties.empty?
    r += " properties=#{properties.to_h}" unless properties.empty?
    "#{r}>"
  end

  #
  # Return Thing's uid as a string
  #
  # @return [String]
  #
  def to_s
    uid.to_s
  end

  # @return [org.openhab.core.common.registry.Provider, nil]
  def provider
    Provider.registry.provider_for(uid)
  end

  #
  # Fetches the actions available for this thing.
  #
  # Default scope actions are available directly on the thing object, via
  # {#method_missing}.
  #
  # @param [String, nil] scope The action scope. Default's to the thing's binding.
  # @return [Object, nil]
  #
  # @example
  #   things["max:thermostat:mybridge:thermostat"].actions("max-devices").delete_from_cube
  #
  # @example (see #method_missing)
  #
  def actions(scope = nil)
    $actions.get(scope || uid.binding_id, uid.to_s)
  end

  #
  # Compares all attributes of the thing with another thing.
  #
  # @param other [Thing] The thing to compare with
  # @return [true,false] true if all attributes are equal, false otherwise
  #
  def config_eql?(other)
    # @deprecated OH3.4 - in OH4, channels can be included in the array and do not need to be compared separately
    channels.to_a == other.channels.to_a &&
      %i[uid label bridge_uid location configuration].all? { |method| send(method) == other.send(method) }
  end

  #
  # Delegate missing methods to the thing's default actions scope.
  #
  # @example
  #   things['mail:smtp:local'].send_email('me@example.com', 'subject', 'message')
  #
  def method_missing(method, *args, &block)
    return actions.public_send(method, *args, &block) if actions.respond_to?(method)

    super
  end

  # @!visibility private
  def respond_to_missing?(method_name, _include_private = false)
    logger.trace { "Checking if Thing #{uid} supports #{method_name} action" }
    return true if actions.respond_to?(method_name)

    super
  end
end

#statusorg.openhab.core.thing.ThingStatus (readonly)

Return the thing status



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
# File 'lib/openhab/core/things/thing.rb', line 74

module Thing
  # Array wrapper class to allow searching a list of channels
  # by channel id
  class ChannelsArray < Array
    def initialize(thing, array)
      super(array)
      @thing = thing
    end

    # Allows indexing by both integer as an array or channel id acting like a hash.
    # @param [Integer, String, ChannelUID] index
    #   Numeric index, string channel id, or a {ChannelUID} to search for.
    # @return [Channel, nil]
    def [](index)
      return @thing.get_channel(index) if index.is_a?(ChannelUID)
      return @thing.get_channel(index.to_str) if index.respond_to?(:to_str)

      super
    end
  end

  class << self
    # @!visibility private
    #
    # Override to support Proxy
    #
    def ===(other)
      other.is_a?(self)
    end
  end

  #
  # @!method uninitialized?
  #   Check if thing status == UNINITIALIZED
  #   @return [true,false]
  #

  #
  # @!method initialized?
  #   Check if thing status == INITIALIZED
  #   @return [true,false]
  #

  #
  # @!method unknown?
  #   Check if thing status == UNKNOWN
  #   @return [true,false]
  #

  #
  # @!method online?
  #   Check if thing status == ONLINE
  #   @return [true,false]
  #

  #
  # @!method offline?
  #   Check if thing status == OFFLINE
  #   @return [true,false]
  #

  #
  # @!method removing?
  #   Check if thing status == REMOVING
  #   @return [true,false]
  #

  #
  # @!method removed?
  #   Check if thing status == REMOVED
  #   @return [true,false]
  #

  ThingStatus.constants.each do |thingstatus|
    define_method(:"#{thingstatus.to_s.downcase}?") { status == ThingStatus.value_of(thingstatus) }
  end

  #
  # Enable the Thing
  #
  # @param [true, false] enabled
  # @return [void]
  #
  def enable(enabled: true)
    Things.manager.set_enabled(uid, enabled)
  end

  #
  # Disable the Thing
  #
  # @return [void]
  #
  def disable
    enable(enabled: false)
  end

  # @!attribute [r] thing_type
  # @return [ThingType]
  def thing_type
    ThingType.registry.get_thing_type(thing_type_uid)
  end

  # @!attribute [r] bridge
  # @return [Thing, nil]
  def bridge
    bridge_uid && EntityLookup.lookup_thing(bridge_uid)
  end

  # @return [true,false] true if this Thing is a bridge
  def bridge?
    is_a?(org.openhab.core.thing.Bridge)
  end

  # @return [String]
  def inspect
    r = "#<OpenHAB::Core::Things::Thing #{uid}"
    r += " #{label.inspect}" if label
    r += " (#{location.inspect})" if location
    r += " #{status}"
    unless status_info.status_detail == org.openhab.core.thing.ThingStatusDetail::NONE
      r += " (#{status_info.status_detail})"
    end
    r += " configuration=#{configuration.properties.to_h}" unless configuration.properties.empty?
    r += " properties=#{properties.to_h}" unless properties.empty?
    "#{r}>"
  end

  #
  # Return Thing's uid as a string
  #
  # @return [String]
  #
  def to_s
    uid.to_s
  end

  # @return [org.openhab.core.common.registry.Provider, nil]
  def provider
    Provider.registry.provider_for(uid)
  end

  #
  # Fetches the actions available for this thing.
  #
  # Default scope actions are available directly on the thing object, via
  # {#method_missing}.
  #
  # @param [String, nil] scope The action scope. Default's to the thing's binding.
  # @return [Object, nil]
  #
  # @example
  #   things["max:thermostat:mybridge:thermostat"].actions("max-devices").delete_from_cube
  #
  # @example (see #method_missing)
  #
  def actions(scope = nil)
    $actions.get(scope || uid.binding_id, uid.to_s)
  end

  #
  # Compares all attributes of the thing with another thing.
  #
  # @param other [Thing] The thing to compare with
  # @return [true,false] true if all attributes are equal, false otherwise
  #
  def config_eql?(other)
    # @deprecated OH3.4 - in OH4, channels can be included in the array and do not need to be compared separately
    channels.to_a == other.channels.to_a &&
      %i[uid label bridge_uid location configuration].all? { |method| send(method) == other.send(method) }
  end

  #
  # Delegate missing methods to the thing's default actions scope.
  #
  # @example
  #   things['mail:smtp:local'].send_email('me@example.com', 'subject', 'message')
  #
  def method_missing(method, *args, &block)
    return actions.public_send(method, *args, &block) if actions.respond_to?(method)

    super
  end

  # @!visibility private
  def respond_to_missing?(method_name, _include_private = false)
    logger.trace { "Checking if Thing #{uid} supports #{method_name} action" }
    return true if actions.respond_to?(method_name)

    super
  end
end

#thing_typeThingType (readonly)

Returns:



172
173
174
# File 'lib/openhab/core/things/thing.rb', line 172

def thing_type
  ThingType.registry.get_thing_type(thing_type_uid)
end

#thing_type_uidThingTypeUID (readonly)

Returns:



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
# File 'lib/openhab/core/things/thing.rb', line 74

module Thing
  # Array wrapper class to allow searching a list of channels
  # by channel id
  class ChannelsArray < Array
    def initialize(thing, array)
      super(array)
      @thing = thing
    end

    # Allows indexing by both integer as an array or channel id acting like a hash.
    # @param [Integer, String, ChannelUID] index
    #   Numeric index, string channel id, or a {ChannelUID} to search for.
    # @return [Channel, nil]
    def [](index)
      return @thing.get_channel(index) if index.is_a?(ChannelUID)
      return @thing.get_channel(index.to_str) if index.respond_to?(:to_str)

      super
    end
  end

  class << self
    # @!visibility private
    #
    # Override to support Proxy
    #
    def ===(other)
      other.is_a?(self)
    end
  end

  #
  # @!method uninitialized?
  #   Check if thing status == UNINITIALIZED
  #   @return [true,false]
  #

  #
  # @!method initialized?
  #   Check if thing status == INITIALIZED
  #   @return [true,false]
  #

  #
  # @!method unknown?
  #   Check if thing status == UNKNOWN
  #   @return [true,false]
  #

  #
  # @!method online?
  #   Check if thing status == ONLINE
  #   @return [true,false]
  #

  #
  # @!method offline?
  #   Check if thing status == OFFLINE
  #   @return [true,false]
  #

  #
  # @!method removing?
  #   Check if thing status == REMOVING
  #   @return [true,false]
  #

  #
  # @!method removed?
  #   Check if thing status == REMOVED
  #   @return [true,false]
  #

  ThingStatus.constants.each do |thingstatus|
    define_method(:"#{thingstatus.to_s.downcase}?") { status == ThingStatus.value_of(thingstatus) }
  end

  #
  # Enable the Thing
  #
  # @param [true, false] enabled
  # @return [void]
  #
  def enable(enabled: true)
    Things.manager.set_enabled(uid, enabled)
  end

  #
  # Disable the Thing
  #
  # @return [void]
  #
  def disable
    enable(enabled: false)
  end

  # @!attribute [r] thing_type
  # @return [ThingType]
  def thing_type
    ThingType.registry.get_thing_type(thing_type_uid)
  end

  # @!attribute [r] bridge
  # @return [Thing, nil]
  def bridge
    bridge_uid && EntityLookup.lookup_thing(bridge_uid)
  end

  # @return [true,false] true if this Thing is a bridge
  def bridge?
    is_a?(org.openhab.core.thing.Bridge)
  end

  # @return [String]
  def inspect
    r = "#<OpenHAB::Core::Things::Thing #{uid}"
    r += " #{label.inspect}" if label
    r += " (#{location.inspect})" if location
    r += " #{status}"
    unless status_info.status_detail == org.openhab.core.thing.ThingStatusDetail::NONE
      r += " (#{status_info.status_detail})"
    end
    r += " configuration=#{configuration.properties.to_h}" unless configuration.properties.empty?
    r += " properties=#{properties.to_h}" unless properties.empty?
    "#{r}>"
  end

  #
  # Return Thing's uid as a string
  #
  # @return [String]
  #
  def to_s
    uid.to_s
  end

  # @return [org.openhab.core.common.registry.Provider, nil]
  def provider
    Provider.registry.provider_for(uid)
  end

  #
  # Fetches the actions available for this thing.
  #
  # Default scope actions are available directly on the thing object, via
  # {#method_missing}.
  #
  # @param [String, nil] scope The action scope. Default's to the thing's binding.
  # @return [Object, nil]
  #
  # @example
  #   things["max:thermostat:mybridge:thermostat"].actions("max-devices").delete_from_cube
  #
  # @example (see #method_missing)
  #
  def actions(scope = nil)
    $actions.get(scope || uid.binding_id, uid.to_s)
  end

  #
  # Compares all attributes of the thing with another thing.
  #
  # @param other [Thing] The thing to compare with
  # @return [true,false] true if all attributes are equal, false otherwise
  #
  def config_eql?(other)
    # @deprecated OH3.4 - in OH4, channels can be included in the array and do not need to be compared separately
    channels.to_a == other.channels.to_a &&
      %i[uid label bridge_uid location configuration].all? { |method| send(method) == other.send(method) }
  end

  #
  # Delegate missing methods to the thing's default actions scope.
  #
  # @example
  #   things['mail:smtp:local'].send_email('me@example.com', 'subject', 'message')
  #
  def method_missing(method, *args, &block)
    return actions.public_send(method, *args, &block) if actions.respond_to?(method)

    super
  end

  # @!visibility private
  def respond_to_missing?(method_name, _include_private = false)
    logger.trace { "Checking if Thing #{uid} supports #{method_name} action" }
    return true if actions.respond_to?(method_name)

    super
  end
end

#uidThingUID (readonly)

Return the UID.

Returns:



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
# File 'lib/openhab/core/things/thing.rb', line 74

module Thing
  # Array wrapper class to allow searching a list of channels
  # by channel id
  class ChannelsArray < Array
    def initialize(thing, array)
      super(array)
      @thing = thing
    end

    # Allows indexing by both integer as an array or channel id acting like a hash.
    # @param [Integer, String, ChannelUID] index
    #   Numeric index, string channel id, or a {ChannelUID} to search for.
    # @return [Channel, nil]
    def [](index)
      return @thing.get_channel(index) if index.is_a?(ChannelUID)
      return @thing.get_channel(index.to_str) if index.respond_to?(:to_str)

      super
    end
  end

  class << self
    # @!visibility private
    #
    # Override to support Proxy
    #
    def ===(other)
      other.is_a?(self)
    end
  end

  #
  # @!method uninitialized?
  #   Check if thing status == UNINITIALIZED
  #   @return [true,false]
  #

  #
  # @!method initialized?
  #   Check if thing status == INITIALIZED
  #   @return [true,false]
  #

  #
  # @!method unknown?
  #   Check if thing status == UNKNOWN
  #   @return [true,false]
  #

  #
  # @!method online?
  #   Check if thing status == ONLINE
  #   @return [true,false]
  #

  #
  # @!method offline?
  #   Check if thing status == OFFLINE
  #   @return [true,false]
  #

  #
  # @!method removing?
  #   Check if thing status == REMOVING
  #   @return [true,false]
  #

  #
  # @!method removed?
  #   Check if thing status == REMOVED
  #   @return [true,false]
  #

  ThingStatus.constants.each do |thingstatus|
    define_method(:"#{thingstatus.to_s.downcase}?") { status == ThingStatus.value_of(thingstatus) }
  end

  #
  # Enable the Thing
  #
  # @param [true, false] enabled
  # @return [void]
  #
  def enable(enabled: true)
    Things.manager.set_enabled(uid, enabled)
  end

  #
  # Disable the Thing
  #
  # @return [void]
  #
  def disable
    enable(enabled: false)
  end

  # @!attribute [r] thing_type
  # @return [ThingType]
  def thing_type
    ThingType.registry.get_thing_type(thing_type_uid)
  end

  # @!attribute [r] bridge
  # @return [Thing, nil]
  def bridge
    bridge_uid && EntityLookup.lookup_thing(bridge_uid)
  end

  # @return [true,false] true if this Thing is a bridge
  def bridge?
    is_a?(org.openhab.core.thing.Bridge)
  end

  # @return [String]
  def inspect
    r = "#<OpenHAB::Core::Things::Thing #{uid}"
    r += " #{label.inspect}" if label
    r += " (#{location.inspect})" if location
    r += " #{status}"
    unless status_info.status_detail == org.openhab.core.thing.ThingStatusDetail::NONE
      r += " (#{status_info.status_detail})"
    end
    r += " configuration=#{configuration.properties.to_h}" unless configuration.properties.empty?
    r += " properties=#{properties.to_h}" unless properties.empty?
    "#{r}>"
  end

  #
  # Return Thing's uid as a string
  #
  # @return [String]
  #
  def to_s
    uid.to_s
  end

  # @return [org.openhab.core.common.registry.Provider, nil]
  def provider
    Provider.registry.provider_for(uid)
  end

  #
  # Fetches the actions available for this thing.
  #
  # Default scope actions are available directly on the thing object, via
  # {#method_missing}.
  #
  # @param [String, nil] scope The action scope. Default's to the thing's binding.
  # @return [Object, nil]
  #
  # @example
  #   things["max:thermostat:mybridge:thermostat"].actions("max-devices").delete_from_cube
  #
  # @example (see #method_missing)
  #
  def actions(scope = nil)
    $actions.get(scope || uid.binding_id, uid.to_s)
  end

  #
  # Compares all attributes of the thing with another thing.
  #
  # @param other [Thing] The thing to compare with
  # @return [true,false] true if all attributes are equal, false otherwise
  #
  def config_eql?(other)
    # @deprecated OH3.4 - in OH4, channels can be included in the array and do not need to be compared separately
    channels.to_a == other.channels.to_a &&
      %i[uid label bridge_uid location configuration].all? { |method| send(method) == other.send(method) }
  end

  #
  # Delegate missing methods to the thing's default actions scope.
  #
  # @example
  #   things['mail:smtp:local'].send_email('me@example.com', 'subject', 'message')
  #
  def method_missing(method, *args, &block)
    return actions.public_send(method, *args, &block) if actions.respond_to?(method)

    super
  end

  # @!visibility private
  def respond_to_missing?(method_name, _include_private = false)
    logger.trace { "Checking if Thing #{uid} supports #{method_name} action" }
    return true if actions.respond_to?(method_name)

    super
  end
end

Instance Method Details

#actions(scope = nil) ⇒ Object?

Fetches the actions available for this thing.

Default scope actions are available directly on the thing object, via #method_missing.

Examples:

things["max:thermostat:mybridge:thermostat"].actions("max-devices").delete_from_cube
things['mail:smtp:local'].send_email('me@example.com', 'subject', 'message')

Parameters:

  • scope (String, nil) (defaults to: nil)

    The action scope. Default's to the thing's binding.

Returns:

  • (Object, nil)


229
230
231
# File 'lib/openhab/core/things/thing.rb', line 229

def actions(scope = nil)
  $actions.get(scope || uid.binding_id, uid.to_s)
end

#bridge?true, false

Returns true if this Thing is a bridge.

Returns:

  • (true, false)

    true if this Thing is a bridge



183
184
185
# File 'lib/openhab/core/things/thing.rb', line 183

def bridge?
  is_a?(org.openhab.core.thing.Bridge)
end

#config_eql?(other) ⇒ true, false

Compares all attributes of the thing with another thing.

Parameters:

  • other (Thing)

    The thing to compare with

Returns:

  • (true, false)

    true if all attributes are equal, false otherwise



239
240
241
242
243
# File 'lib/openhab/core/things/thing.rb', line 239

def config_eql?(other)
  # @deprecated OH3.4 - in OH4, channels can be included in the array and do not need to be compared separately
  channels.to_a == other.channels.to_a &&
    %i[uid label bridge_uid location configuration].all? { |method| send(method) == other.send(method) }
end

#disablevoid

This method returns an undefined value.

Disable the Thing



166
167
168
# File 'lib/openhab/core/things/thing.rb', line 166

def disable
  enable(enabled: false)
end

#enable(enabled: true) ⇒ void

This method returns an undefined value.

Enable the Thing

Parameters:

  • enabled (true, false) (defaults to: true)


157
158
159
# File 'lib/openhab/core/things/thing.rb', line 157

def enable(enabled: true)
  Things.manager.set_enabled(uid, enabled)
end

#initialized?true, false

Check if thing status == INITIALIZED

Returns:

  • (true, false)


# File 'lib/openhab/core/things/thing.rb', line 111

#inspectString

Returns:

  • (String)


188
189
190
191
192
193
194
195
196
197
198
199
# File 'lib/openhab/core/things/thing.rb', line 188

def inspect
  r = "#<OpenHAB::Core::Things::Thing #{uid}"
  r += " #{label.inspect}" if label
  r += " (#{location.inspect})" if location
  r += " #{status}"
  unless status_info.status_detail == org.openhab.core.thing.ThingStatusDetail::NONE
    r += " (#{status_info.status_detail})"
  end
  r += " configuration=#{configuration.properties.to_h}" unless configuration.properties.empty?
  r += " properties=#{properties.to_h}" unless properties.empty?
  "#{r}>"
end

#offline?true, false

Check if thing status == OFFLINE

Returns:

  • (true, false)


# File 'lib/openhab/core/things/thing.rb', line 129

#online?true, false

Check if thing status == ONLINE

Returns:

  • (true, false)


# File 'lib/openhab/core/things/thing.rb', line 123

#providerorg.openhab.core.common.registry.Provider?



211
212
213
# File 'lib/openhab/core/things/thing.rb', line 211

def provider
  Provider.registry.provider_for(uid)
end

#removed?true, false

Check if thing status == REMOVED

Returns:

  • (true, false)


147
148
149
# File 'lib/openhab/core/things/thing.rb', line 147

ThingStatus.constants.each do |thingstatus|
  define_method(:"#{thingstatus.to_s.downcase}?") { status == ThingStatus.value_of(thingstatus) }
end

#removing?true, false

Check if thing status == REMOVING

Returns:

  • (true, false)


# File 'lib/openhab/core/things/thing.rb', line 135

#to_sString

Return Thing's uid as a string

Returns:

  • (String)


206
207
208
# File 'lib/openhab/core/things/thing.rb', line 206

def to_s
  uid.to_s
end

#uninitialized?true, false

Check if thing status == UNINITIALIZED

Returns:

  • (true, false)


# File 'lib/openhab/core/things/thing.rb', line 105

#unknown?true, false

Check if thing status == UNKNOWN

Returns:

  • (true, false)


# File 'lib/openhab/core/things/thing.rb', line 117