Module: OpenHAB::Core::Things::Thing
- Defined in:
- lib/openhab/core/things/thing.rb
Overview
Defined Under Namespace
Classes: ChannelsArray
Instance Attribute Summary collapse
- #channels ⇒ ChannelArray readonly
-
#status ⇒ org.openhab.core.thing.ThingStatus
readonly
Return the thing status.
Instance Method Summary collapse
-
#actions(scope = nil) ⇒ Object?
Fetches the actions available for this thing.
-
#disable ⇒ void
Disable the Thing.
-
#enable(enabled: true) ⇒ void
Enable the Thing.
-
#initialized? ⇒ true, false
Check if thing status == INITIALIZED.
- #inspect ⇒ String
-
#method_missing(method, *args, &block) ⇒ Object
Delegate missing methods to the thing's default actions scope.
-
#offline? ⇒ true, false
Check if thing status == OFFLINE.
-
#online? ⇒ true, false
Check if thing status == ONLINE.
-
#removed? ⇒ true, false
Check if thing status == REMOVED.
-
#removing? ⇒ true, false
Check if thing status == REMOVING.
-
#to_s ⇒ String
Return Thing's uid as a string.
-
#uninitialized? ⇒ true, false
Check if thing status == UNINITIALIZED.
-
#unknown? ⇒ true, false
Check if thing status == UNKNOWN.
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.
178 179 180 181 182 |
# File 'lib/openhab/core/things/thing.rb', line 178 def method_missing(method, *args, &block) return actions.public_send(method, *args, &block) if actions.respond_to?(method) super end |
Instance Attribute Details
#channels ⇒ ChannelArray (readonly)
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 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 |
# File 'lib/openhab/core/things/thing.rb', line 40 module Thing # Array wrapper class to allow searching a list of channels # by channel id class ChannelsArray < Array # Allows indexing by both integer as an array or channel id acting like a hash. # @param [Integer, String] index Numeric index or string channel id to search for. def [](index) if index.respond_to?(:to_str) key = index.to_str return find { |channel| channel.uid.id == key } end 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 # @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 # # 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 # # 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 |
#status ⇒ org.openhab.core.thing.ThingStatus (readonly)
Return the thing status
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 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 |
# File 'lib/openhab/core/things/thing.rb', line 40 module Thing # Array wrapper class to allow searching a list of channels # by channel id class ChannelsArray < Array # Allows indexing by both integer as an array or channel id acting like a hash. # @param [Integer, String] index Numeric index or string channel id to search for. def [](index) if index.respond_to?(:to_str) key = index.to_str return find { |channel| channel.uid.id == key } end 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 # @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 # # 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 # # 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.
168 169 170 |
# File 'lib/openhab/core/things/thing.rb', line 168 def actions(scope = nil) $actions.get(scope || uid.binding_id, uid.to_s) end |
#disable ⇒ void
This method returns an undefined value.
Disable the Thing
127 128 129 |
# File 'lib/openhab/core/things/thing.rb', line 127 def disable enable(enabled: false) end |
#enable(enabled: true) ⇒ void
This method returns an undefined value.
Enable the Thing
118 119 120 |
# File 'lib/openhab/core/things/thing.rb', line 118 def enable(enabled: true) Things.manager.set_enabled(uid, enabled) end |
#initialized? ⇒ true, false
Check if thing status == INITIALIZED
|
# File 'lib/openhab/core/things/thing.rb', line 72
|
#inspect ⇒ String
132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/openhab/core/things/thing.rb', line 132 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
|
# File 'lib/openhab/core/things/thing.rb', line 90
|
#online? ⇒ true, false
Check if thing status == ONLINE
|
# File 'lib/openhab/core/things/thing.rb', line 84
|
#removed? ⇒ true, false
Check if thing status == REMOVED
108 109 110 |
# File 'lib/openhab/core/things/thing.rb', line 108 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
|
# File 'lib/openhab/core/things/thing.rb', line 96
|
#to_s ⇒ String
Return Thing's uid as a string
150 151 152 |
# File 'lib/openhab/core/things/thing.rb', line 150 def to_s uid.to_s end |
#uninitialized? ⇒ true, false
Check if thing status == UNINITIALIZED
|
# File 'lib/openhab/core/things/thing.rb', line 66
|
#unknown? ⇒ true, false
Check if thing status == UNKNOWN
|
# File 'lib/openhab/core/things/thing.rb', line 78
|