-
Notifications
You must be signed in to change notification settings - Fork 16
/
security_system.rb
53 lines (47 loc) · 1.68 KB
/
security_system.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
require "ruby_home"
accessory_information = RubyHome::ServiceFactory.create(:accessory_information)
security_system = RubyHome::ServiceFactory.create(:security_system,
security_system_target_state: 0, # required
security_system_current_state: 0, # required
name: "security system", # optional
security_system_alarm_type: 0, # optional
status_tampered: 0, # optional
status_fault: 0) # optional
security_system_target_state_values = {
0 => "Stay Arm",
1 => "Away Arm",
2 => "Night Arm",
3 => "Disarm"
}
security_system.security_system_target_state.after_update do |security_system_target_state|
state = security_system_target_state_values[security_system_target_state]
puts "security system security_system_target_state #{state}"
sleep 1
security_system.security_system_current_state = security_system_target_state
end
security_system_current_state_values = {
0 => "Stay Arm",
1 => "Away Arm",
2 => "Night Arm",
3 => "Disarmed",
4 => "Alarm Triggered"
}
security_system.security_system_current_state.after_update do |security_system_current_state|
state = security_system_current_state_values[security_system_current_state]
puts "security system security_system_current_state state #{state}"
end
security_system.status_tampered.after_update do |status_tampered|
if status_tampered == 0
puts "security system status_tampered not tampered"
elsif status_tampered == 1
puts "security system status_tampered tampered"
end
end
security_system.status_fault.after_update do |status_fault|
if status_fault == 0
puts "security system status_fault no fault"
elsif status_fault == 1
puts "security system status_fault general fault"
end
end
RubyHome.run