Class: OpenHAB::RSpec::Mocks::ThingHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/openhab/rspec/mocks/thing_handler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(thing = nil) ⇒ ThingHandler

Returns a new instance of ThingHandler.



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/openhab/rspec/mocks/thing_handler.rb', line 15

def initialize(thing = nil)
  # have to handle the interface method
  if thing.nil?
    status_info = org.openhab.core.thing.binding.builder.ThingStatusInfoBuilder
                     .create(org.openhab.core.thing.ThingStatus::ONLINE).build
    @callback.status_updated(self.thing, status_info)
    return
  end

  # ruby initializer here
  @thing = thing
end

Instance Attribute Details

#callbackObject (readonly)

Returns the value of attribute callback.



13
14
15
# File 'lib/openhab/rspec/mocks/thing_handler.rb', line 13

def callback
  @callback
end

#thingObject (readonly)

Returns the value of attribute thing.



13
14
15
# File 'lib/openhab/rspec/mocks/thing_handler.rb', line 13

def thing
  @thing
end

Instance Method Details

#channel_linked(_channel_uid) ⇒ Object



51
# File 'lib/openhab/rspec/mocks/thing_handler.rb', line 51

def channel_linked(_channel_uid); end

#channel_unlinked(_channel_uid) ⇒ Object



52
# File 'lib/openhab/rspec/mocks/thing_handler.rb', line 52

def channel_unlinked(_channel_uid); end

#child_handler_disposed(child_handler, child_thing) ⇒ Object



49
# File 'lib/openhab/rspec/mocks/thing_handler.rb', line 49

def child_handler_disposed(child_handler, child_thing); end

#child_handler_initialized(child_handler, child_thing) ⇒ Object



48
# File 'lib/openhab/rspec/mocks/thing_handler.rb', line 48

def child_handler_initialized(child_handler, child_thing); end

#disposeObject



54
# File 'lib/openhab/rspec/mocks/thing_handler.rb', line 54

def dispose; end

#handle_command(channel_uid, command) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/openhab/rspec/mocks/thing_handler.rb', line 32

def handle_command(channel_uid, command)
  channel = thing.get_channel(channel_uid)
  return unless channel
  return if channel.auto_update_policy == org.openhab.core.thing.type.AutoUpdatePolicy::VETO

  callback&.state_updated(channel_uid, command) if command.is_a?(Core::Types::State)
end

#send_time_series(channel_uid, time_series) ⇒ Object



40
41
42
# File 'lib/openhab/rspec/mocks/thing_handler.rb', line 40

def send_time_series(channel_uid, time_series)
  @callback&.send_time_series(channel_uid, time_series)
end

#set_callback(callback) ⇒ Object



44
45
46
# File 'lib/openhab/rspec/mocks/thing_handler.rb', line 44

def set_callback(callback)
  @callback = callback
end

#thing_updated(thing) ⇒ Object



28
29
30
# File 'lib/openhab/rspec/mocks/thing_handler.rb', line 28

def thing_updated(thing)
  @thing = thing
end