-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathall.rb
87 lines (64 loc) · 2.23 KB
/
all.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# frozen_string_literal: true
module Milight
module V6
# Commands for lamps in all zones.
class All
def initialize(command)
@command = command
end
# Switch the lights on.
def on
@command.execute(0, [0x31, 0x00, 0x00, 0x08, 0x04, 0x01, 0x00, 0x00, 0x00])
self
end
# Switch the lights off.
def off
@command.execute(0, [0x31, 0x00, 0x00, 0x08, 0x04, 0x02, 0x00, 0x00, 0x00])
self
end
# Enable night light mode.
def night_light
@command.execute(0, [0x31, 0x00, 0x00, 0x08, 0x04, 0x05, 0x00, 0x00, 0x00])
self
end
# Set brightness, value: 0% to 100%.
def brightness(value)
raise ArgumentError, "Please supply a brightness value between 0-100." if value.negative? || value > 100
@command.execute(0, [0x31, 0x00, 0x00, 0x08, 0x03, value, 0x00, 0x00, 0x00])
self
end
# Set color temperature, value: 0 = 2700K, 100 = 6500K.
def temperature(value)
raise ArgumentError, "Please supply a temperature value between 0-100 (2700K to 6500K)." if value.negative? || value > 100
@command.execute(0, [0x31, 0x00, 0x00, 0x08, 0x05, value, 0x00, 0x00, 0x00])
self
end
# Set color temperature to warm light (2700K).
def warm_light
temperature(0)
end
# Set color temperature to white (cool) light (6500K).
def white_light
temperature(100)
end
# Set the hue, value: 0 to 255 (red).
# See Milight::V6::Color for predefined colors.
def hue(value)
raise ArgumentError, "Please supply a hue value between 0-255." if value.negative? || value > 255
@command.execute(0, [0x31, 0x00, 0x00, 0x08, 0x01, value, value, value, value])
self
end
# Set the saturation, value: 0% to 100%.
def saturation(value)
raise ArgumentError, "Please supply a saturation value between 0-100." if value.negative? || value > 100
@command.execute(0, [0x31, 0x00, 0x00, 0x08, 0x02, value, 0x00, 0x00, 0x00])
self
end
# Wait before continuing to next command.
def wait(seconds)
sleep(seconds)
self
end
end
end
end