ruby_home 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,89 @@
1
+ require 'ruby_home'
2
+
3
+ accessory_information = RubyHome::ServiceFactory.create(:accessory_information)
4
+ humidifier_dehumidifier = RubyHome::ServiceFactory.create(:humidifier_dehumidifier,
5
+ active: 1, # required
6
+ target_humidifier_dehumidifier_state: 0, # required
7
+ current_humidifier_dehumidifier_state: 1, # required
8
+ current_relative_humidity: 30, # required
9
+ name: "humidifier dehumidifier", # optional
10
+ rotation_speed: 0, # optional
11
+ relative_humidity_humidifier_threshold: 100, # optional
12
+ relative_humidity_dehumidifier_threshold: 0, # optional
13
+ water_level: 50, # optional
14
+ swing_mode: 1, # optional
15
+ lock_physical_controls: 0, # optional
16
+ )
17
+
18
+ humidifier_dehumidifier.active.after_update do |active|
19
+ if active == 0
20
+ puts "humidifier dehumidifier is inactive"
21
+ elsif active == 1
22
+ puts "humidifier dehumidifier is active"
23
+ end
24
+ end
25
+
26
+ target_humidifier_dehumidifier_state_values = {
27
+ 0 => 'Humidifier or Dehumidifier',
28
+ 1 => 'Humidifier',
29
+ 2 => 'Dehumidifier'
30
+ }
31
+ humidifier_dehumidifier.target_humidifier_dehumidifier_state.after_update do |target_humidifier_dehumidifier_state|
32
+ state = target_humidifier_dehumidifier_state_values[target_humidifier_dehumidifier_state]
33
+ puts "humidifier dehumidifier target humidifier dehumidifier state is #{state}"
34
+ end
35
+
36
+ current_humidifier_dehumidifier_state_values = {
37
+ 0 => 'Inactive',
38
+ 1 => 'Idle',
39
+ 2 => 'Humidifying',
40
+ 3 => 'Dehumidifying'
41
+ }
42
+ humidifier_dehumidifier.current_humidifier_dehumidifier_state.after_update do |current_humidifier_dehumidifier_state|
43
+ state = current_humidifier_dehumidifier_state_values[current_humidifier_dehumidifier_state]
44
+ puts "humidifier dehumidifier target humidifier dehumidifier state is #{state}"
45
+ end
46
+
47
+ humidifier_dehumidifier.current_relative_humidity.after_update do |current_relative_humidity|
48
+ puts "humidifier dehumidifier current relative humidity at #{current_relative_humidity}"
49
+ end
50
+
51
+ humidifier_dehumidifier.rotation_speed.after_update do |rotation_speed|
52
+ puts "humidifier dehumidifier is spinning at #{rotation_speed} speed"
53
+ end
54
+
55
+ humidifier_dehumidifier.relative_humidity_humidifier_threshold.after_update do |relative_humidity_humidifier_threshold|
56
+ # maximum_value: 100
57
+ # minimum_value: 0
58
+ # step_value: 1
59
+ puts "humidifier dehumidifier relative humidity humidifier threshold temperature #{relative_humidity_humidifier_threshold}"
60
+ end
61
+
62
+ humidifier_dehumidifier.relative_humidity_dehumidifier_threshold.after_update do |relative_humidity_dehumidifier_threshold|
63
+ # maximum_value: 100
64
+ # minimum_value: 0
65
+ # step_value: 1
66
+ puts "humidifier dehumidifier relative humidity humidifier threshold temperature #{relative_humidity_dehumidifier_threshold}"
67
+ end
68
+
69
+ humidifier_dehumidifier.water_level.after_update do |water_level|
70
+ puts "humidifier dehumidifier water level #{water_level}"
71
+ end
72
+
73
+ humidifier_dehumidifier.swing_mode.after_update do |swing_mode|
74
+ if swing_mode == 0
75
+ puts "humidifier dehumidifier swimg is disabled"
76
+ elsif swing_mode == 1
77
+ puts "humidifier dehumidifier swimg is enabled"
78
+ end
79
+ end
80
+
81
+ humidifier_dehumidifier.lock_physical_controls.after_update do |lock_physical_controls|
82
+ if lock_physical_controls == 0
83
+ puts "humidifier dehumidifier control lock disabled"
84
+ elsif lock_physical_controls == 1
85
+ puts "humidifier dehumidifier control lock enabled"
86
+ end
87
+ end
88
+
89
+ RubyHome.run
@@ -0,0 +1,63 @@
1
+ require 'ruby_home'
2
+
3
+ accessory_information = RubyHome::ServiceFactory.create(:accessory_information)
4
+ humidity_sensor = RubyHome::ServiceFactory.create(:humidity_sensor,
5
+ current_relative_humidity: 20, # required
6
+ name: "humidity sensor", # optional
7
+ status_low_battery: 0, # optional
8
+ status_tampered: 0, # optional
9
+ status_fault: 0, # optional
10
+ status_active: true # optional
11
+ )
12
+
13
+ humidity_sensor.current_relative_humidity.after_update do |current_relative_humidity|
14
+ puts "humidity sensor current relative humidity #{current_relative_humidity}"
15
+ end
16
+
17
+ humidity_sensor.status_low_battery.after_update do |status_low_battery|
18
+ if status_low_battery == 0
19
+ puts "humidity sensor low battery is battery level normal"
20
+ elsif status_low_battery == 1
21
+ puts "humidity sensor low battery is battery level low"
22
+ end
23
+ end
24
+
25
+ humidity_sensor.status_tampered.after_update do |status_tampered|
26
+ if status_tampered == 0
27
+ puts "humidity sensor status_tampered not tampered"
28
+ elsif status_tampered == 1
29
+ puts "humidity sensor status_tampered tampered"
30
+ end
31
+ end
32
+
33
+ humidity_sensor.status_fault.after_update do |status_fault|
34
+ if status_fault == 0
35
+ puts "humidity sensor status_fault no fault"
36
+ elsif status_fault == 1
37
+ puts "humidity sensor status_fault general fault"
38
+ end
39
+ end
40
+
41
+ humidity_sensor.status_active.after_update do |active|
42
+ if active
43
+ puts "humidity sensor is active"
44
+ else
45
+ puts "humidity sensor is inactive"
46
+ end
47
+ end
48
+
49
+ Thread.new do
50
+ sleep 30
51
+
52
+ loop do
53
+ humidity_sensor.current_relative_humidity = (0..100).to_a.sample
54
+ humidity_sensor.status_low_battery = (0..1).to_a.sample
55
+ humidity_sensor.status_tampered = (0..1).to_a.sample
56
+ humidity_sensor.status_fault = (0..1).to_a.sample
57
+ humidity_sensor.status_active = [true, false].to_a.sample
58
+
59
+ sleep 10
60
+ end
61
+ end
62
+
63
+ RubyHome.run
@@ -0,0 +1,67 @@
1
+ require 'ruby_home'
2
+
3
+ accessory_information = RubyHome::ServiceFactory.create(:accessory_information)
4
+ leak_sensor = RubyHome::ServiceFactory.create(:leak_sensor,
5
+ leak_detected: 0, # required
6
+ name: "leak sensor", # optional
7
+ status_low_battery: 0, # optional
8
+ status_tampered: 0, # optional
9
+ status_fault: 0, # optional
10
+ status_active: true # optional
11
+ )
12
+
13
+ leak_sensor.leak_detected.after_update do |leak_detected|
14
+ if leak_detected == 0
15
+ puts "leak sensor leak detected leak not detected"
16
+ elsif leak_detected == 1
17
+ puts "leak sensor leak detected leak detected"
18
+ end
19
+ end
20
+
21
+ leak_sensor.status_low_battery.after_update do |status_low_battery|
22
+ if status_low_battery == 0
23
+ puts "leak sensor low battery is battery level normal"
24
+ elsif status_low_battery == 1
25
+ puts "leak sensor low battery is battery level low"
26
+ end
27
+ end
28
+
29
+ leak_sensor.status_tampered.after_update do |status_tampered|
30
+ if status_tampered == 0
31
+ puts "leak sensor status_tampered not tampered"
32
+ elsif status_tampered == 1
33
+ puts "leak sensor status_tampered tampered"
34
+ end
35
+ end
36
+
37
+ leak_sensor.status_fault.after_update do |status_fault|
38
+ if status_fault == 0
39
+ puts "leak sensor status_fault no fault"
40
+ elsif status_fault == 1
41
+ puts "leak sensor status_fault general fault"
42
+ end
43
+ end
44
+
45
+ leak_sensor.status_active.after_update do |active|
46
+ if active
47
+ puts "leak sensor is active"
48
+ else
49
+ puts "leak sensor is inactive"
50
+ end
51
+ end
52
+
53
+ Thread.new do
54
+ sleep 30
55
+
56
+ loop do
57
+ leak_sensor.leak_detected = (0..1).to_a.sample
58
+ leak_sensor.status_low_battery = (0..1).to_a.sample
59
+ leak_sensor.status_tampered = (0..1).to_a.sample
60
+ leak_sensor.status_fault = (0..1).to_a.sample
61
+ leak_sensor.status_active = [true, false].to_a.sample
62
+
63
+ sleep 10
64
+ end
65
+ end
66
+
67
+ RubyHome.run
@@ -0,0 +1,65 @@
1
+ require 'ruby_home'
2
+
3
+ accessory_information = RubyHome::ServiceFactory.create(:accessory_information)
4
+ light_sensor = RubyHome::ServiceFactory.create(:light_sensor,
5
+ current_ambient_light_level: 50000, # required
6
+ name: "light sensor", # optional
7
+ status_low_battery: 0, # optional
8
+ status_tampered: 0, # optional
9
+ status_fault: 0, # optional
10
+ status_active: true # optional
11
+ )
12
+
13
+ light_sensor.current_ambient_light_level.after_update do |current_ambient_light_level|
14
+ # maximum_value: 100000
15
+ # minimum_value: 0.0001
16
+ puts "light sensor current ambient light level #{current_ambient_light_level}"
17
+ end
18
+
19
+ light_sensor.status_low_battery.after_update do |status_low_battery|
20
+ if status_low_battery == 0
21
+ puts "light sensor low battery is battery level normal"
22
+ elsif status_low_battery == 1
23
+ puts "light sensor low battery is battery level low"
24
+ end
25
+ end
26
+
27
+ light_sensor.status_tampered.after_update do |status_tampered|
28
+ if status_tampered == 0
29
+ puts "light sensor status_tampered not tampered"
30
+ elsif status_tampered == 1
31
+ puts "light sensor status_tampered tampered"
32
+ end
33
+ end
34
+
35
+ light_sensor.status_fault.after_update do |status_fault|
36
+ if status_fault == 0
37
+ puts "light sensor status_fault no fault"
38
+ elsif status_fault == 1
39
+ puts "light sensor status_fault general fault"
40
+ end
41
+ end
42
+
43
+ light_sensor.status_active.after_update do |active|
44
+ if active
45
+ puts "light sensor is active"
46
+ else
47
+ puts "light sensor is inactive"
48
+ end
49
+ end
50
+
51
+ Thread.new do
52
+ sleep 30
53
+
54
+ loop do
55
+ light_sensor.current_ambient_light_level = (1..100000).to_a.sample
56
+ light_sensor.status_low_battery = (0..1).to_a.sample
57
+ light_sensor.status_tampered = (0..1).to_a.sample
58
+ light_sensor.status_fault = (0..1).to_a.sample
59
+ light_sensor.status_active = [true, false].to_a.sample
60
+
61
+ sleep 10
62
+ end
63
+ end
64
+
65
+ RubyHome.run
@@ -0,0 +1,32 @@
1
+ require 'ruby_home'
2
+
3
+ accessory_information = RubyHome::ServiceFactory.create(:accessory_information)
4
+ lightbulb = RubyHome::ServiceFactory.create(:lightbulb,
5
+ on: true, # required
6
+ name: "lightbulb", # optional
7
+ brightness: 100, # optional
8
+ saturation: 100, # optional
9
+ hue: 360 # optional
10
+ )
11
+
12
+ lightbulb.on.after_update do |on|
13
+ if on
14
+ puts "lightbulb is on"
15
+ else
16
+ puts "lightbulb is off"
17
+ end
18
+ end
19
+
20
+ lightbulb.brightness.after_update do |brightness|
21
+ puts "lightbulb is at #{brightness} brightness"
22
+ end
23
+
24
+ lightbulb.saturation.after_update do |saturation|
25
+ puts "lightbulb is at #{saturation} saturation"
26
+ end
27
+
28
+ lightbulb.hue.after_update do |hue|
29
+ puts "lightbulb is at #{hue} hue"
30
+ end
31
+
32
+ RubyHome.run
@@ -0,0 +1,35 @@
1
+ require 'ruby_home'
2
+
3
+ accessory_information = RubyHome::ServiceFactory.create(:accessory_information)
4
+ lock_mechanism = RubyHome::ServiceFactory.create(:lock_mechanism,
5
+ lock_target_state: 1, # required
6
+ lock_current_state: 1, # required
7
+ name: "lock" # optional
8
+ )
9
+
10
+ lock_mechanism.lock_target_state.after_update do |lock_target_state|
11
+ if lock_target_state == 0
12
+ puts "lock target state is unsecured"
13
+
14
+ sleep 1
15
+ lock_mechanism.lock_current_state = 0
16
+ elsif lock_target_state == 1
17
+ puts "lock target state is secured"
18
+
19
+ sleep 1
20
+ lock_mechanism.lock_current_state = 1
21
+ end
22
+ end
23
+
24
+ lock_current_state_values = {
25
+ 0 => 'Unsecured',
26
+ 1 => 'Secured',
27
+ 2 => 'Jammed',
28
+ 3 => 'Unknown'
29
+ }
30
+ lock_mechanism.lock_current_state.after_update do |lock_current_state|
31
+ state = lock_current_state_values[lock_current_state]
32
+ puts "lock current state #{state}"
33
+ end
34
+
35
+ RubyHome.run
@@ -0,0 +1,67 @@
1
+ require 'ruby_home'
2
+
3
+ accessory_information = RubyHome::ServiceFactory.create(:accessory_information)
4
+ motion_sensor = RubyHome::ServiceFactory.create(:motion_sensor,
5
+ motion_detected: false, # required
6
+ name: "motion sensor", # optional
7
+ status_low_battery: 0, # optional
8
+ status_tampered: 0, # optional
9
+ status_fault: 0, # optional
10
+ status_active: true # optional
11
+ )
12
+
13
+ motion_sensor.motion_detected.after_update do |motion_detected|
14
+ if motion_detected
15
+ puts "motion sensor detected motion"
16
+ else
17
+ puts "motion sensor no motion detected"
18
+ end
19
+ end
20
+
21
+ motion_sensor.status_low_battery.after_update do |status_low_battery|
22
+ if status_low_battery == 0
23
+ puts "motion sensor battery level normal"
24
+ elsif status_low_battery == 1
25
+ puts "motion sensor battery level lormal"
26
+ end
27
+ end
28
+
29
+ motion_sensor.status_tampered.after_update do |status_tampered|
30
+ if status_tampered == 0
31
+ puts "motion sensor status_tampered not tampered"
32
+ elsif status_tampered == 1
33
+ puts "motion sensor status_tampered tampered"
34
+ end
35
+ end
36
+
37
+ motion_sensor.status_fault.after_update do |status_fault|
38
+ if status_fault == 0
39
+ puts "motion sensor status_fault no fault"
40
+ elsif status_fault == 1
41
+ puts "motion sensor status_fault general fault"
42
+ end
43
+ end
44
+
45
+ motion_sensor.status_active.after_update do |active|
46
+ if active
47
+ puts "motion sensor is active"
48
+ else
49
+ puts "motion sensor is inactive"
50
+ end
51
+ end
52
+
53
+ Thread.new do
54
+ sleep 30
55
+
56
+ loop do
57
+ motion_sensor.motion_detected = [true, false].to_a.sample
58
+ motion_sensor.status_low_battery = (0..1).to_a.sample
59
+ motion_sensor.status_tampered = (0..1).to_a.sample
60
+ motion_sensor.status_fault = (0..1).to_a.sample
61
+ motion_sensor.status_active = [true, false].to_a.sample
62
+
63
+ sleep 10
64
+ end
65
+ end
66
+
67
+ RubyHome.run
@@ -0,0 +1,67 @@
1
+ require 'ruby_home'
2
+
3
+ accessory_information = RubyHome::ServiceFactory.create(:accessory_information)
4
+ occupancy_sensor = RubyHome::ServiceFactory.create(:occupancy_sensor,
5
+ motion_detected: false, # required
6
+ name: "occupancy sensor", # optional
7
+ status_low_battery: 0, # optional
8
+ status_tampered: 0, # optional
9
+ status_fault: 0, # optional
10
+ status_active: true # optional
11
+ )
12
+
13
+ occupancy_sensor.occupancy_detected.after_update do |occupancy_detected|
14
+ if occupancy_detected == 0
15
+ puts "occupancy sensor occupancy not detected"
16
+ else
17
+ puts "occupancy sensor occupancy detected"
18
+ end
19
+ end
20
+
21
+ occupancy_sensor.status_low_battery.after_update do |status_low_battery|
22
+ if status_low_battery == 0
23
+ puts "occupancy sensor battery level normal"
24
+ elsif status_low_battery == 1
25
+ puts "occupancy sensor battery level lormal"
26
+ end
27
+ end
28
+
29
+ occupancy_sensor.status_tampered.after_update do |status_tampered|
30
+ if status_tampered == 0
31
+ puts "occupancy sensor status_tampered not tampered"
32
+ elsif status_tampered == 1
33
+ puts "occupancy sensor status_tampered tampered"
34
+ end
35
+ end
36
+
37
+ occupancy_sensor.status_fault.after_update do |status_fault|
38
+ if status_fault == 0
39
+ puts "occupancy sensor status_fault no fault"
40
+ elsif status_fault == 1
41
+ puts "occupancy sensor status_fault general fault"
42
+ end
43
+ end
44
+
45
+ occupancy_sensor.status_active.after_update do |active|
46
+ if active
47
+ puts "occupancy sensor is active"
48
+ else
49
+ puts "occupancy sensor is inactive"
50
+ end
51
+ end
52
+
53
+ Thread.new do
54
+ sleep 30
55
+
56
+ loop do
57
+ occupancy_sensor.occupancy_detected = (0..1).to_a.sample
58
+ occupancy_sensor.status_low_battery = (0..1).to_a.sample
59
+ occupancy_sensor.status_tampered = (0..1).to_a.sample
60
+ occupancy_sensor.status_fault = (0..1).to_a.sample
61
+ occupancy_sensor.status_active = [true, false].to_a.sample
62
+
63
+ sleep 10
64
+ end
65
+ end
66
+
67
+ RubyHome.run