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.
-
#enabled? ⇒ true, false
Check if the rule's status detail !=
DISABLED
. -
#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)
142 143 144 |
# File 'lib/openhab/core/rules/rule.rb', line 142 def status Rules.manager&.get_status(uid) end |
#status_info ⇒ RuleStatusInfo? (readonly)
150 151 152 |
# File 'lib/openhab/core/rules/rule.rb', line 150 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 |
#enabled? ⇒ true, false
Check if the rule's status detail != DISABLED
119 120 121 |
# File 'lib/openhab/core/rules/rule.rb', line 119 def enabled? !disabled? 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
155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/openhab/core/rules/rule.rb', line 155 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 += " description=#{description.inspect}" if description r += " tags=#{tags.to_a.inspect}" unless tags.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)
131 132 133 134 135 136 |
# File 'lib/openhab/core/rules/rule.rb', line 131 def tagged?(*tags) tags.map! do |tag| tag.is_a?(::Module) ? tag.simple_name : tag # ::Module to distinguish against Rule::Module! end !(self.tags.to_a & tags).empty? end |
#to_s ⇒ String
168 169 170 |
# File 'lib/openhab/core/rules/rule.rb', line 168 def to_s uid end |
#trigger(event = nil, consider_conditions: false, **context) ⇒ Hash Also known as: run
Manually trigger the rule
180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/openhab/core/rules/rule.rb', line 180 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
|