Class: OpenHAB::DSL::Imports::EventHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/openhab/dsl/imports.rb

Overview

reimplement to not use a thread

Instance Method Summary collapse

Constructor Details

#initialize(typed_event_subscribers, typed_event_factories) ⇒ EventHandler



147
148
149
150
# File 'lib/rspec/openhab/dsl/imports.rb', line 147

def initialize(typed_event_subscribers, typed_event_factories)
  @typed_event_subscribers = typed_event_subscribers
  @typed_event_factories = typed_event_factories
end

Instance Method Details

#handle_event(osgi_event) ⇒ Object



152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/rspec/openhab/dsl/imports.rb', line 152

def handle_event(osgi_event)
  type = osgi_event.get_property("type")
  payload = osgi_event.get_property("payload")
  topic = osgi_event.get_property("topic")
  source = osgi_event.get_property("source")

  if type.is_a?(String) && payload.is_a?(String) && topic.is_a?(String)
    handle_event_internal(type, payload, topic, source) unless type.empty? || payload.empty? || topic.empty?
  else
    logger.error("The handled OSGi event is invalid. " \
                 "Expect properties as string named 'type', 'payload', and 'topic'. " \
                 "Received event properties are: #{properties.keys.inspect}")
  end
end