-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathwindow.rb
48 lines (39 loc) · 1.21 KB
/
window.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
require "ruby_home"
accessory_information = RubyHome::ServiceFactory.create(:accessory_information)
window = RubyHome::ServiceFactory.create(:window,
target_position: 0, # required
position_state: 1, # required
current_position: 0, # required
name: "window", # optional
obstruction_detected: false) # optional
window.target_position.after_update do |target_position|
puts "window target position #{target_position}"
if target_position < window.current_position
window.position_state = 0
elsif target_position > window.current_position
window.position_state = 1
end
sleep 1
window.current_position = target_position
window.position_state = 2
end
position_state_values = {
0 => "Decreasing",
1 => "Increasing",
2 => "Stopped"
}
window.position_state.after_update do |position_state|
state = position_state_values[position_state]
puts "window position state #{state}"
end
window.current_position.after_update do |current_position|
puts "window current position #{current_position}"
end
window.obstruction_detected.after_update do |obstruction_detected|
if obstruction_detected
puts "window obstruction detected"
else
puts "window no obstruction detected"
end
end
RubyHome.run