Class: OpenHAB::DSL::Rules::Triggers::Conditions::Duration
- Inherits:
-
Object
- Object
- OpenHAB::DSL::Rules::Triggers::Conditions::Duration
- Defined in:
- lib/openhab/dsl/rules/triggers/conditions/duration.rb
Overview
Struct capturing data necessary for a conditional trigger
Instance Attribute Summary collapse
-
#rule ⇒ Object
Returns the value of attribute rule.
Instance Method Summary collapse
-
#cleanup ⇒ Object
Cleanup any resources from the condition.
-
#initialize(to:, from:, duration:) ⇒ Duration
constructor
Create a new duration condition.
-
#process(mod:, inputs:, &block) ⇒ Object
Process rule.
Constructor Details
#initialize(to:, from:, duration:) ⇒ Duration
Create a new duration condition
21 22 23 24 25 26 27 28 29 |
# File 'lib/openhab/dsl/rules/triggers/conditions/duration.rb', line 21 def initialize(to:, from:, duration:) @conditions = Generic.new(to: to, from: from) @duration = duration @timers = {} logger.trace do "Created Duration Condition To(#{to}) From(#{from}) " \ "Conditions(#{@conditions}) Duration(#{@duration})" end end |
Instance Attribute Details
#rule ⇒ Object
Returns the value of attribute rule.
13 14 15 |
# File 'lib/openhab/dsl/rules/triggers/conditions/duration.rb', line 13 def rule @rule end |
Instance Method Details
#cleanup ⇒ Object
Cleanup any resources from the condition
Cancels the timer, if it’s active
52 53 54 |
# File 'lib/openhab/dsl/rules/triggers/conditions/duration.rb', line 52 def cleanup @timers.each_value(&:cancel) end |
#process(mod:, inputs:, &block) ⇒ Object
Process rule
34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/openhab/dsl/rules/triggers/conditions/duration.rb', line 34 def process(mod:, inputs:, &block) timer = @timers[inputs["triggeringItem"]&.name] if timer&.active? process_active_timer(timer, inputs, mod, &block) elsif @conditions.process(mod: mod, inputs: inputs) logger.trace { "Trigger Guards Matched for #{self}, delaying rule execution" } # Add timer and attach timer to delay object, and also state being tracked to so # timer can be cancelled if state changes # Also another timer should not be created if changed to same value again but instead rescheduled create_trigger_delay_timer(inputs, mod, &block) else logger.trace { "Trigger Guards did not match for #{self}, ignoring trigger." } end end |