Module: OpenHAB::Core::ScriptHandling

Included in:
DSL
Defined in:
lib/openhab/core/script_handling.rb

Overview

Provide callback mechanisms for script handling

Class Method Summary collapse

Class Method Details

.script_loaded(&block) ⇒ void

This method returns an undefined value.

Add a block of code to be executed once the rule script has finished loading.

This can occur on openHAB start up, when the script is first created, or updated.

Multiple hooks can be added by calling #script_loaded multiple times. They can be used to perform final initializations.

Examples:

script_loaded do
  logger.info 'Hi, this script has just finished loading'
end
script_loaded do
  logger.info 'I will be called after the script finished loading too'
end


31
32
33
# File 'lib/openhab/core/script_handling.rb', line 31

def script_loaded(&block)
  ScriptHandlingCallbacks.script_loaded_hooks << block
end

.script_unloaded(priority: nil, &block) ⇒ void

This method returns an undefined value.

Add a block of code to be executed when the script is unloaded.

This can occur when openHAB shuts down, or when the script is being reloaded.

Multiple hooks can be added by calling #script_unloaded multiple times. They can be used to perform final cleanup.

Examples:

script_unloaded do
  logger.info 'Hi, this script has been unloaded'
end

Parameters:

  • priority (Integer, nil) (defaults to: nil)

    The order at which the the given hook will be executed. The higher the number, the lower the priority. Higher priority hooks will be executed first, before the lower priority hooks. When nil, the default priority of zero will be used.



54
55
56
# File 'lib/openhab/core/script_handling.rb', line 54

def script_unloaded(priority: nil, &block)
  ScriptHandlingCallbacks.script_unloaded_hooks[priority || 0] << block
end