Class: Milight::Bulb
- Inherits:
-
Object
- Object
- Milight::Bulb
- Defined in:
- lib/milight/bulb.rb
Instance Method Summary collapse
- #bright(persent) ⇒ Object
- #color_value=(val) ⇒ Object
- #dark ⇒ Object
- #debug(msg) ⇒ Object
-
#debugger=(type) ⇒ Object
TODO: move to anywhere…
- #disco(attr = nil) ⇒ Object
- #full_bright ⇒ Object
-
#initialize(group: :all, ip: nil, port: 8899) ⇒ Bulb
constructor
A new instance of Bulb.
-
#night ⇒ Object
night-command 100ms followed by ‘off-command’.
- #off ⇒ Object
- #on ⇒ Object
-
#white ⇒ Object
white-command 100ms followed by ‘on-command’.
Constructor Details
#initialize(group: :all, ip: nil, port: 8899) ⇒ Bulb
Returns a new instance of Bulb.
6 7 8 9 10 11 12 |
# File 'lib/milight/bulb.rb', line 6 def initialize(group: :all, ip: nil, port: 8899) self.group = group self.ip = ip @port = port @debugger = lambda {|_| } end |
Instance Method Details
#bright(persent) ⇒ Object
83 84 85 86 87 88 89 90 |
# File 'lib/milight/bulb.rb', line 83 def bright(persent) if val = brightness(persent.to_i) self.on command Command::BRIGHTENESS, val else debug "invalid persent value '#{persent}'" end end |
#color_value=(val) ⇒ Object
74 75 76 77 78 79 80 81 |
# File 'lib/milight/bulb.rb', line 74 def color_value=(val) if code = color_code(val) self.on command Command::SET_COLOR, code else debug "invalid color value '#{val}'" end end |
#dark ⇒ Object
96 97 98 |
# File 'lib/milight/bulb.rb', line 96 def dark self.bright 0 end |
#debug(msg) ⇒ Object
27 28 29 |
# File 'lib/milight/bulb.rb', line 27 def debug(msg) @debugger.call msg end |
#debugger=(type) ⇒ Object
TODO: move to anywhere…
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/milight/bulb.rb', line 15 def debugger=(type) @debugger = case type when :puts lambda {|msg| puts " - debug :: #{msg}" } else lambda {|_| } end debug "set debug - #{type}" end |
#disco(attr = nil) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/milight/bulb.rb', line 35 def disco(attr = nil) case attr && attr.to_sym when nil command Command::DISCO_MODE when :faster, :fast command Command::DISCO_SPEED_FASTER when :slower, :slow command Command::DISCO_SPEED_SLOWER else debug "invalid disco attribute: '#{attr}'" end end |
#full_bright ⇒ Object
92 93 94 |
# File 'lib/milight/bulb.rb', line 92 def full_bright self.bright 50 end |
#night ⇒ Object
night-command 100ms followed by ‘off-command’
59 60 61 62 |
# File 'lib/milight/bulb.rb', line 59 def night self.off command Command::NIGHT[@group] end |
#off ⇒ Object
48 49 50 |
# File 'lib/milight/bulb.rb', line 48 def off command Command::LED_OFF[@group] end |