Class: OpenHAB::Core::Events::TimerEvent

Inherits:
AbstractEvent show all
Defined in:
lib/openhab/core/events/timer_event.rb

Overview

Adds methods to core openHAB TimerEvent to make it more natural in Ruby

This event can be triggered by a DateTimeTrigger, cron, or TimeOfDay trigger.

Since:

  • openHAB 4.0

Instance Attribute Summary collapse

Attributes inherited from AbstractEvent

#attachment, #inputs, #source

Method Summary

Methods inherited from AbstractEvent

#inspect, #payload

Instance Attribute Details

#cron_expressionString? (readonly)

Returns The cron expression that triggered this event. nil when this event wasn't triggered by a cron trigger.

Returns:

  • (String, nil)

    The cron expression that triggered this event. nil when this event wasn't triggered by a cron trigger.

Since:

  • openHAB 4.0



24
25
26
# File 'lib/openhab/core/events/timer_event.rb', line 24

def cron_expression
  payload&.[](:cronExpression)
end

#itemItem? (readonly)

Returns The DateTime item that triggered this event. nil when this event wasn't triggered by a DateTimeItem trigger.

Returns:

  • (Item, nil)

    The DateTime item that triggered this event. nil when this event wasn't triggered by a DateTimeItem trigger.

Since:

  • openHAB 4.0



33
34
35
# File 'lib/openhab/core/events/timer_event.rb', line 33

def item
  payload&.[](:itemName)&.then { |item_name| EntityLookup.lookup_item(item_name) }
end

#offsetDuration? (readonly)

Returns The offset from the configured time for this DateTime trigger event. nil when this event wasn't triggered by a DateTime trigger.

Returns:

  • (Duration, nil)

    The offset from the configured time for this DateTime trigger event. nil when this event wasn't triggered by a DateTime trigger.

Since:

  • openHAB 4.3



56
57
58
# File 'lib/openhab/core/events/timer_event.rb', line 56

def offset
  payload&.[](:offset)&.seconds
end

#timeLocalTime? (readonly)

Returns The configured time for this TimeOfDay trigger event. nil when this event wasn't triggered by a TimeOfDay trigger.

Returns:

  • (LocalTime, nil)

    The configured time for this TimeOfDay trigger event. nil when this event wasn't triggered by a TimeOfDay trigger.

Since:

  • openHAB 4.0



65
66
67
# File 'lib/openhab/core/events/timer_event.rb', line 65

def time
  payload&.[](:time)&.then { |time| LocalTime.parse(time) }
end

#time_only?Boolean (readonly)

Returns true when this event was triggered by a DateTimeItem with timeOnly set. false when this event wasn't triggered by a DateTimeItem or the timeOnly flag is not set.

Returns:

  • (Boolean)

    true when this event was triggered by a DateTimeItem with timeOnly set. false when this event wasn't triggered by a DateTimeItem or the timeOnly flag is not set.

See Also:

  • #every trigger
  • #at trigger

Since:

  • openHAB 4.3



46
47
48
# File 'lib/openhab/core/events/timer_event.rb', line 46

def time_only?
  !!payload&.[](:timeOnly)
end