Module: OpenHAB::Core::Rules::Rule
- Defined in:
- lib/openhab/core/rules/rule.rb
Overview
A Rule is a chunk of code that can execute when certain conditions are met, enabling the core dynamic functionality of openHAB.
Instance Attribute Summary collapse
-
#description ⇒ String?
readonly
The rule’s description.
-
#name ⇒ String?
readonly
The rule’s human-readable name.
- #status ⇒ RuleStatus? readonly
- #status_info ⇒ RuleStatusInfo? readonly
-
#tags ⇒ Array<Tag>
readonly
The rule’s list of tags.
Instance Method Summary collapse
-
#disable ⇒ void
Disable the Rule.
-
#disabled? ⇒ true, false
Check if the rule’s status detail == ‘DISABLED`.
-
#enable(enabled: true) ⇒ void
Enable the Rule.
-
#expert? ⇒ true, false
Check if visibility == ‘EXPERT`.
-
#hidden? ⇒ true, false
Check if visibility == ‘HIDDEN`.
-
#idle? ⇒ true, false
Check if rule status == ‘IDLE`.
-
#initializing? ⇒ true, false
Check if rule status == ‘INITIALIZING`.
- #inspect ⇒ String
-
#running? ⇒ true, false
Check if rule status == ‘RUNNING`.
-
#tagged?(*tags) ⇒ Boolean
Checks if this rule has at least one of the given tags.
- #to_s ⇒ String
-
#trigger(event = nil, consider_conditions: false, **context) ⇒ Hash
(also: #run)
Manually trigger the rule.
-
#uninitialized? ⇒ true, false
Check if rule status == ‘UNINITIALIZED`.
-
#visible? ⇒ true, false
Check if visibility == ‘VISIBLE`.
Instance Attribute Details
#description ⇒ String? (readonly)
Returns The rule’s description.
|
# File 'lib/openhab/core/rules/rule.rb', line 17
|
#name ⇒ String? (readonly)
Returns The rule’s human-readable name.
|
# File 'lib/openhab/core/rules/rule.rb', line 14
|
#status ⇒ RuleStatus? (readonly)
133 134 135 |
# File 'lib/openhab/core/rules/rule.rb', line 133 def status Rules.manager&.get_status(uid) end |
#status_info ⇒ RuleStatusInfo? (readonly)
141 142 143 |
# File 'lib/openhab/core/rules/rule.rb', line 141 def status_info Rules.manager&.get_status_info(uid) end |
#tags ⇒ Array<Tag> (readonly)
Returns The rule’s list of tags.
|
# File 'lib/openhab/core/rules/rule.rb', line 20
|
Instance Method Details
#disable ⇒ void
This method returns an undefined value.
Disable the Rule
100 101 102 |
# File 'lib/openhab/core/rules/rule.rb', line 100 def disable enable(enabled: false) end |
#disabled? ⇒ true, false
Check if the rule’s status detail == ‘DISABLED`
109 110 111 112 |
# File 'lib/openhab/core/rules/rule.rb', line 109 def disabled? info = status_info info.nil? || info.status_detail == RuleStatusDetail::DISABLED end |
#enable(enabled: true) ⇒ void
This method returns an undefined value.
Enable the Rule
91 92 93 |
# File 'lib/openhab/core/rules/rule.rb', line 91 def enable(enabled: true) Rules.manager.set_enabled(uid, enabled) end |
#expert? ⇒ true, false
Check if visibility == ‘EXPERT`
|
# File 'lib/openhab/core/rules/rule.rb', line 35
|
#hidden? ⇒ true, false
Check if visibility == ‘HIDDEN`
|
# File 'lib/openhab/core/rules/rule.rb', line 29
|
#idle? ⇒ true, false
Check if rule status == ‘IDLE`
57 58 59 60 61 62 63 |
# File 'lib/openhab/core/rules/rule.rb', line 57 Visibility.constants.each do |visibility| class_eval <<~RUBY, __FILE__, __LINE__ + 1 def #{visibility.to_s.downcase}? # def visibile? visibility == Visibility::#{visibility} # visibility == Visibility::VISIBLE end # end RUBY end |
#initializing? ⇒ true, false
Check if rule status == ‘INITIALIZING`
57 58 59 60 61 62 63 |
# File 'lib/openhab/core/rules/rule.rb', line 57 Visibility.constants.each do |visibility| class_eval <<~RUBY, __FILE__, __LINE__ + 1 def #{visibility.to_s.downcase}? # def visibile? visibility == Visibility::#{visibility} # visibility == Visibility::VISIBLE end # end RUBY end |
#inspect ⇒ String
146 147 148 149 150 151 152 153 154 155 |
# File 'lib/openhab/core/rules/rule.rb', line 146 def inspect r = "#<OpenHAB::Core::Rules::Rule #{uid}" r += " #{name.inspect}" if name r += " #{visibility}" unless visible? r += " #{status || "<detached>"}" r += " (#{status_info.status_detail})" if status_info && status_info.status_detail != RuleStatusDetail::NONE r += " tags=#{.to_a.inspect}" unless .empty? r += " configuration=#{configuration.properties.to_h}" if configuration && !configuration.properties.empty? "#{r}>" end |
#running? ⇒ true, false
Check if rule status == ‘RUNNING`
57 58 59 60 61 62 63 |
# File 'lib/openhab/core/rules/rule.rb', line 57 Visibility.constants.each do |visibility| class_eval <<~RUBY, __FILE__, __LINE__ + 1 def #{visibility.to_s.downcase}? # def visibile? visibility == Visibility::#{visibility} # visibility == Visibility::VISIBLE end # end RUBY end |
#tagged?(*tags) ⇒ Boolean
Checks if this rule has at least one of the given tags.
(see Items::Item#tagged)
122 123 124 125 126 127 |
# File 'lib/openhab/core/rules/rule.rb', line 122 def tagged?(*) .map! do |tag| tag.is_a?(::Module) ? tag.simple_name : tag # ::Module to distinguish against Rule::Module! end !(self..to_a & ).empty? end |
#to_s ⇒ String
158 159 160 |
# File 'lib/openhab/core/rules/rule.rb', line 158 def to_s uid end |
#trigger(event = nil, consider_conditions: false, **context) ⇒ Hash Also known as: run
Manually trigger the rule
170 171 172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/openhab/core/rules/rule.rb', line 170 def trigger(event = nil, consider_conditions: false, **context) begin event ||= org.openhab.core.automation.events.AutomationEventFactory .createExecutionEvent(uid, nil, "manual") rescue NameError # @deprecated OH3.4 doesn't have AutomationEventFactory end context.transform_keys!(&:to_s) # Unwrap any proxies and pass raw objects (items, things) context.transform_values! { |value| value.is_a?(Delegator) ? value.__getobj__ : value } context["event"] = event if event # @deprecated OH3.4 - remove if guard. In OH4 `event` will never be nil Rules.manager.run_now(uid, consider_conditions, context) end |
#uninitialized? ⇒ true, false
Check if rule status == ‘UNINITIALIZED`
80 81 82 83 |
# File 'lib/openhab/core/rules/rule.rb', line 80 def uninitialized? s = status s.nil? || s == RuleStatus::UNINITIALIZED end |
#visible? ⇒ true, false
Check if visibility == ‘VISIBLE`
|
# File 'lib/openhab/core/rules/rule.rb', line 23
|