Class: Wizrb::Shared::Group

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/wizrb/shared/group.rb

Direct Known Subclasses

Lighting::Group, Power::Group

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(devices:) ⇒ Group

Returns a new instance of Group.



16
17
18
# File 'lib/wizrb/shared/group.rb', line 16

def initialize(devices:)
  @devices = devices
end

Instance Attribute Details

#devicesObject (readonly)

Returns the value of attribute devices.



14
15
16
# File 'lib/wizrb/shared/group.rb', line 14

def devices
  @devices
end

Instance Method Details

#dispatch_event(event) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/wizrb/shared/group.rb', line 40

def dispatch_event(event)
  unless event.is_a?(Wizrb::Shared::Events::Base)
    raise ArgumentError, "Not an instance of Wizrb::Shared::Events::Base"
  end

  dispatch(event)
end

#dispatch_events(*events) ⇒ Object



48
49
50
51
52
53
54
55
56
57
# File 'lib/wizrb/shared/group.rb', line 48

def dispatch_events(*events)
  events.each do |event|
    unless event.is_a?(Wizrb::Shared::Events::Base)
      raise ArgumentError, "Not an instance of Wizrb::Shared::Events::Base"
    end
  end

  params = events.reduce({}) { |h, e| h.merge(e.params) }
  dispatch_event(Wizrb::Shared::Events::Base.new(method: "setState", params: params))
end

#eachObject



20
21
22
# File 'lib/wizrb/shared/group.rb', line 20

def each(&)
  @devices.each(&)
end

#power_offObject



28
29
30
# File 'lib/wizrb/shared/group.rb', line 28

def power_off
  dispatch_event(Wizrb::Shared::Events::PowerEvent.new(false))
end

#power_onObject



24
25
26
# File 'lib/wizrb/shared/group.rb', line 24

def power_on
  dispatch_event(Wizrb::Shared::Events::PowerEvent.new(true))
end

#rebootObject



32
33
34
# File 'lib/wizrb/shared/group.rb', line 32

def reboot
  dispatch_event(Wizrb::Shared::Events::RebootEvent.new)
end

#resetObject



36
37
38
# File 'lib/wizrb/shared/group.rb', line 36

def reset
  dispatch_event(Wizrb::Shared::Events::ResetEvent.new)
end