Class: LightMeUp::SettingsUpdate

Inherits:
Object
  • Object
show all
Defined in:
lib/light_me_up/settings_update.rb

Defined Under Namespace

Classes: InvalidOptions, ToggleIncompatible

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_client, options) ⇒ SettingsUpdate

Returns a new instance of SettingsUpdate.



10
11
12
13
# File 'lib/light_me_up/settings_update.rb', line 10

def initialize(api_client, options)
  @api_client = api_client
  @options = options
end

Instance Attribute Details

#api_clientObject (readonly)

Returns the value of attribute api_client.



5
6
7
# File 'lib/light_me_up/settings_update.rb', line 5

def api_client
  @api_client
end

#optionsObject (readonly)

Returns the value of attribute options.



5
6
7
# File 'lib/light_me_up/settings_update.rb', line 5

def options
  @options
end

Instance Method Details

#performObject



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/light_me_up/settings_update.rb', line 15

def perform
  settings_options = options.slice(:toggle, :on, :brightness, :temperature)
  if settings_options.delete(:toggle)
    raise ToggleIncompatible, "is not compatible with on or off" if settings_options.key?(:on)

    api_client.toggle(**settings_options)
  elsif settings_options.any?
    api_client.update(**settings_options)
  else
    raise InvalidOptions, "At least one option must be provided"
  end
end