Class: OpenHAB::DSL::Rules::Triggers::Conditions::Generic

Inherits:
Object
  • Object
show all
Defined in:
lib/openhab/dsl/rules/triggers/conditions/generic.rb

Overview

This creates trigger conditions that work on procs

Constant Summary collapse

ANY =

this needs to be defined after initialize so its instance variables are set

Generic.new.freeze

Instance Method Summary collapse

Constructor Details

#initialize(from: nil, to: nil, command: nil) ⇒ Generic

Create a new Condition that executes only if procs return true

Parameters:

  • from (#===, nil) (defaults to: nil)

    Value to check against ‘from` state

  • to (#===, nil) (defaults to: nil)

    Value to check against ‘to` state

  • command (#===, nil) (defaults to: nil)

    Value to check against received command



19
20
21
22
23
# File 'lib/openhab/dsl/rules/triggers/conditions/generic.rb', line 19

def initialize(from: nil, to: nil, command: nil)
  @from = from
  @to = to
  @command = command
end

Instance Method Details

#from?Boolean

Returns true if a ‘from` condition was specified

Returns:

  • (Boolean)


47
48
49
# File 'lib/openhab/dsl/rules/triggers/conditions/generic.rb', line 47

def from?
  !@from.nil?
end

#process(mod:, inputs:) ⇒ true, false

Process rule

Parameters:

  • inputs (Hash)

    inputs from trigger

Returns:

  • (true, false)

    if the conditions passed (and therefore the block was run)



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/openhab/dsl/rules/triggers/conditions/generic.rb', line 32

def process(mod:, inputs:)
  logger.trace("Checking #{inputs} against condition trigger #{self}")
  unless check_value(Conditions.old_state_from(inputs), @from) &&
         check_value(Conditions.new_state_from(inputs), @to) &&
         check_value(inputs["command"], @command)
    return false
  end

  yield if block_given?
  true
end