Class: OpenHAB::Core::Events::AbstractEvent

Inherits:
Object
  • Object
show all
Defined in:
lib/openhab/core/events/abstract_event.rb

Overview

Add attachments event data.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#attachmentObject

Returns:

  • (Object)


11
12
13
# File 'lib/openhab/core/events/abstract_event.rb', line 11

def attachment
  @attachment
end

#inputsHash

Returns:

  • (Hash)


14
15
16
# File 'lib/openhab/core/events/abstract_event.rb', line 14

def inputs
  @inputs
end

#sourceSource? (readonly)

Returns The component(s) that sent the event.

Returns:

  • (Source, nil)

    The component(s) that sent the event.



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/openhab/core/events/abstract_event.rb', line 38

def source
  unless instance_variable_defined?(:@source)
    begin
      # Disable "instance vars on non-persistent Java type"
      original_verbose = $VERBOSE
      $VERBOSE = nil
      @source = get_source && Source.new(get_source)
    ensure
      $VERBOSE = original_verbose
    end
  end
  @source
end

Instance Method Details

#inspectString

Returns:

  • (String)


71
72
73
74
75
# File 'lib/openhab/core/events/abstract_event.rb', line 71

def inspect
  s = "#<OpenHAB::Core::Events::#{self.class.simple_name} topic=#{topic} payload=#{payload.inspect}"
  s += " source=#{source.inspect}" if source
  "#{s}>"
end

#payloadHash, ...

Returns the event payload as a Hash.

Returns:

  • (Hash, String, nil)

    The payload object parsed by JSON. The keys are symbolized. nil when the payload is empty.



58
59
60
61
62
63
64
65
66
67
68
# File 'lib/openhab/core/events/abstract_event.rb', line 58

def payload
  require "json"
  # Disable "instance vars on non-persistent Java type"
  original_verbose = $VERBOSE
  $VERBOSE = nil
  @payload ||= JSON.parse(get_payload, symbolize_names: true) unless get_payload.empty?
rescue JSON::ParserError
  get_payload
ensure
  $VERBOSE = original_verbose
end