Class: MiOS::Action

Inherits:
Object
  • Object
show all
Defined in:
lib/mios/action.rb

Instance Method Summary collapse

Constructor Details

#initialize(interface, service_id, action, parameters = {}) ⇒ Action

Returns a new instance of Action.



3
4
5
6
7
8
# File 'lib/mios/action.rb', line 3

def initialize(interface, service_id, action, parameters = {})
  @interface = interface
  @service_id = service_id
  @action = action
  @parameters = parameters
end

Instance Method Details

#take(async = false, &block) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/mios/action.rb', line 10

def take(async = false, &block)
  response = @interface.action(@action, @service_id, @parameters)
  # Is there ever more than one job from a device action?

  # Device actions return a response with a job ID.  Scene actions
  # do not.  This is an attempt to abstract that knowledge away
  # from the caller.
  if has_job?(response)
    Job.new(@interface, response.values.first['JobID'], async, &block)
  else
    yield if block_given?
  end
  response
end