Class: OpenHAB::Core::Timer
- Inherits:
 - 
      Object
      
        
- Object
 - OpenHAB::Core::Timer
 
 
- Defined in:
 - lib/openhab/core/timer.rb
 
Overview
Timer allows you to administer the block of code that has been scheduled to run later with after.
Instance Attribute Summary collapse
- 
  
    
      #execution_time  ⇒ ZonedDateTime? 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
The scheduled execution time, or
nilif the timer was cancelled. - #id ⇒ Object?
 
Instance Method Summary collapse
- 
  
    
      #active?  ⇒ true, false 
    
    
  
  
  
  
  
  
  
  
  
    
Check if the timer will execute in the future.
 - 
  
    
      #cancel  ⇒ true, false 
    
    
  
  
  
  
  
  
  
  
  
    
Cancel timer.
 - 
  
    
      #cancelled?  ⇒ true, false 
    
    
  
  
  
  
  
  
  
  
  
    
Check if the timer has been cancelled.
 - #inspect ⇒ String (also: #to_s)
 - 
  
    
      #managed?  ⇒ true, false 
    
    
  
  
  
  
  
  
  
  
  
    
True if the timer is managed by TimerManager, false otherwise.
 - 
  
    
      #reschedule(time = nil)  ⇒ self 
    
    
  
  
  
  
  
  
  
  
  
    
Reschedule timer.
 - 
  
    
      #running?  ⇒ true, false 
    
    
  
  
  
  
  
  
  
  
  
    
Check if the timer code is currently running.
 - 
  
    
      #terminated?  ⇒ true, false 
    
    
  
  
  
  
  
  
  
  
  
    
Check if the timer has terminated.
 - 
  
    
      #unmanage  ⇒ org.openhab.core.automation.module.script.action.Timer 
    
    
  
  
  
  
  
  
  
  
  
    
Removes the timer from the TimerManager.
 
Instance Attribute Details
#execution_time ⇒ ZonedDateTime? (readonly)
Returns the scheduled execution time, or nil if the timer was cancelled.
| 
       | 
    
      # File 'lib/openhab/core/timer.rb', line 71
     | 
  
#id ⇒ Object?
      34 35 36  | 
    
      # File 'lib/openhab/core/timer.rb', line 34 def id @id end  | 
  
Instance Method Details
#active? ⇒ true, false
Check if the timer will execute in the future.
| 
       | 
    
      # File 'lib/openhab/core/timer.rb', line 14
     | 
  
#cancel ⇒ true, false
Cancel timer
      109 110 111 112  | 
    
      # File 'lib/openhab/core/timer.rb', line 109 def cancel DSL.timers.delete(self) cancel! end  | 
  
#cancelled? ⇒ true, false
Check if the timer has been cancelled.
| 
       | 
    
      # File 'lib/openhab/core/timer.rb', line 18
     | 
  
#inspect ⇒ String Also known as: to_s
      59 60 61 62 63 64 65 66 67 68  | 
    
      # File 'lib/openhab/core/timer.rb', line 59 def inspect r = "#<#{self.class.name} #{"#{id.inspect} " if id}#{block.source_location.join(":")}" if cancelled? r += " (cancelled)" else r += " @ #{execution_time}" r += " (executed)" if terminated? end "#{r}>" end  | 
  
#managed? ⇒ true, false
Returns True if the timer is managed by TimerManager, false otherwise. A timer is managed by default, and becomes un-managed when #unmanage is called.
      195 196 197  | 
    
      # File 'lib/openhab/core/timer.rb', line 195 def managed? @managed end  | 
  
#reschedule(time = nil) ⇒ self
Reschedule timer.
If the timer had been cancelled or executed, restart the timer.
      84 85 86 87 88 89 90 91 92 93  | 
    
      # File 'lib/openhab/core/timer.rb', line 84 def reschedule(time = nil) return reschedule!(time) unless id # re-add ourself to the TimerManager's @timers_by_id DSL.timers.schedule(id) do |old_timer| old_timer&.cancel unless old_timer.eql?(self) self.id = nil reschedule!(time) end end  | 
  
#running? ⇒ true, false
Check if the timer code is currently running.
| 
       | 
    
      # File 'lib/openhab/core/timer.rb', line 22
     | 
  
#terminated? ⇒ true, false
Check if the timer has terminated.
      30  | 
    
      # File 'lib/openhab/core/timer.rb', line 30 def_delegator :@timer, :has_terminated, :terminated?  | 
  
#unmanage ⇒ org.openhab.core.automation.module.script.action.Timer
Removes the timer from the TimerManager
The effects of calling this method are:
- The timer will no longer be automatically cancelled when the script unloads. It will still execute as scheduled even if the script is unloaded/removed.
 - It can no longer be referenced by its 
id. - Subsequent calls to after with the same 
idwill create a separate new timer. - Normal timer operations such as #reschedule, #cancel, etc. will still work.
 
      186 187 188 189 190 191  | 
    
      # File 'lib/openhab/core/timer.rb', line 186 def unmanage @managed = false DSL.timers.delete(self) @id = nil @timer end  |