Class: Wizrb::Lighting::State

Inherits:
Shared::State show all
Defined in:
lib/wizrb/lighting/state.rb

Constant Summary collapse

STATE_KEYS =
%i[state w c r g b temp dimming speed sceneId].freeze

Instance Method Summary collapse

Methods inherited from Shared::State

#initialize, #power, #to_json, #to_s

Constructor Details

This class inherits a constructor from Wizrb::Shared::State

Instance Method Details

#brightnessObject



32
33
34
# File 'lib/wizrb/lighting/state.rb', line 32

def brightness
  @state[:dimming]
end

#cold_whiteObject



20
21
22
# File 'lib/wizrb/lighting/state.rb', line 20

def cold_white
  @state[:c]
end

#color_tempObject



28
29
30
# File 'lib/wizrb/lighting/state.rb', line 28

def color_temp
  @state[:temp]
end

#parse!(response) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/wizrb/lighting/state.rb', line 8

def parse!(response)
  result = response&.dig("result")
  return unless result

  @state = result.transform_keys(&:to_sym).slice(*STATE_KEYS)
  @state.delete(:sceneId) if @state[:sceneId]&.zero?
end

#rgbObject



24
25
26
# File 'lib/wizrb/lighting/state.rb', line 24

def rgb
  {red: @state[:r], green: @state[:g], blue: @state[:b]}
end

#sceneObject



40
41
42
# File 'lib/wizrb/lighting/state.rb', line 40

def scene
  Wizrb::Lighting::SCENES.key(@state[:schdPsetId] || @state[:sceneId])
end

#speedObject



36
37
38
# File 'lib/wizrb/lighting/state.rb', line 36

def speed
  @state[:speed]
end

#warm_whiteObject



16
17
18
# File 'lib/wizrb/lighting/state.rb', line 16

def warm_white
  @state[:w]
end