ruby_home 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,79 @@
1
+ require 'ruby_home'
2
+
3
+ accessory_information = RubyHome::ServiceFactory.create(:accessory_information)
4
+ carbon_monoxide_sensor = RubyHome::ServiceFactory.create(:carbon_monoxide_sensor,
5
+ carbon_monoxide_detected: 0, # required
6
+ name: "carbon monoxide sensor", # optional
7
+ carbon_monoxide_peak_level: 0, # optional
8
+ carbon_monoxide_level: 0, # optional
9
+ status_tampered: 0, # optional
10
+ status_low_battery: 0, # optional
11
+ status_fault: 0, # optional
12
+ status_active: true # optional
13
+ )
14
+
15
+ carbon_monoxide_sensor.carbon_monoxide_detected.after_update do |carbon_monoxide_detected|
16
+ if carbon_monoxide_detected == 0
17
+ puts "carbon monoxide sensor carbon monoxide detected CO2 levels normal"
18
+ elsif carbon_monoxide_detected == 1
19
+ puts "carbon monoxide sensor carbon monoxide detected CO2 levels abnormal"
20
+ end
21
+ end
22
+
23
+ carbon_monoxide_sensor.carbon_monoxide_peak_level.after_update do |carbon_monoxide_peak_level|
24
+ puts "carbon monoxide sensor carbon_monoxide_peak_level #{carbon_monoxide_peak_level}"
25
+ end
26
+
27
+ carbon_monoxide_sensor.carbon_monoxide_level.after_update do |carbon_monoxide_level|
28
+ puts "carbon monoxide sensor carbon_monoxide_level #{carbon_monoxide_level}"
29
+ end
30
+
31
+ carbon_monoxide_sensor.status_tampered.after_update do |status_tampered|
32
+ if status_tampered == 0
33
+ puts "carbon monoxide sensor status_tampered not tampered"
34
+ elsif status_tampered == 1
35
+ puts "carbon monoxide sensor status_tampered tampered"
36
+ end
37
+ end
38
+
39
+ carbon_monoxide_sensor.status_low_battery.after_update do |status_low_battery|
40
+ if status_low_battery == 0
41
+ puts "carbon monoxide sensor low battery is battery level normal"
42
+ elsif status_low_battery == 1
43
+ puts "carbon monoxide sensor low battery is battery level low"
44
+ end
45
+ end
46
+
47
+ carbon_monoxide_sensor.status_fault.after_update do |status_fault|
48
+ if status_fault == 0
49
+ puts "carbon monoxide sensor status_fault no fault"
50
+ elsif status_fault == 1
51
+ puts "carbon monoxide sensor status_fault general fault"
52
+ end
53
+ end
54
+
55
+ carbon_monoxide_sensor.status_active.after_update do |active|
56
+ if active
57
+ puts "carbon monoxide sensor is active"
58
+ else
59
+ puts "carbon monoxide sensor is inactive"
60
+ end
61
+ end
62
+
63
+ Thread.new do
64
+ sleep 30
65
+
66
+ loop do
67
+ carbon_monoxide_sensor.carbon_monoxide_detected = (0..1).to_a.sample
68
+ carbon_monoxide_sensor.carbon_monoxide_peak_level = (0..100).to_a.sample
69
+ carbon_monoxide_sensor.carbon_monoxide_level = (0..100).to_a.sample
70
+ carbon_monoxide_sensor.status_tampered = (0..1).to_a.sample
71
+ carbon_monoxide_sensor.status_low_battery = (0..1).to_a.sample
72
+ carbon_monoxide_sensor.status_fault = (0..1).to_a.sample
73
+ carbon_monoxide_sensor.status_active = [true, false].to_a.sample
74
+
75
+ sleep 10
76
+ end
77
+ end
78
+
79
+ RubyHome.run
@@ -0,0 +1,67 @@
1
+ require 'ruby_home'
2
+
3
+ accessory_information = RubyHome::ServiceFactory.create(:accessory_information)
4
+ contact_sensor = RubyHome::ServiceFactory.create(:contact_sensor,
5
+ contact_sensor_state: 0, # required
6
+ name: "contact 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
+ contact_sensor.contact_sensor_state.after_update do |contact_sensor_state|
14
+ if contact_sensor_state == 0
15
+ puts "contact sensor contact sensor state contact detected"
16
+ elsif contact_sensor_state == 1
17
+ puts "contact sensor contact sensor state contact not detected"
18
+ end
19
+ end
20
+
21
+ contact_sensor.status_low_battery.after_update do |status_low_battery|
22
+ if status_low_battery == 0
23
+ puts "contact sensor low battery is battery level normal"
24
+ elsif status_low_battery == 1
25
+ puts "contact sensor low battery is battery level low"
26
+ end
27
+ end
28
+
29
+ contact_sensor.status_tampered.after_update do |status_tampered|
30
+ if status_tampered == 0
31
+ puts "contact sensor status_tampered not tampered"
32
+ elsif status_tampered == 1
33
+ puts "contact sensor status_tampered tampered"
34
+ end
35
+ end
36
+
37
+ contact_sensor.status_fault.after_update do |status_fault|
38
+ if status_fault == 0
39
+ puts "contact sensor status_fault no fault"
40
+ elsif status_fault == 1
41
+ puts "contact sensor status_fault general fault"
42
+ end
43
+ end
44
+
45
+ contact_sensor.status_active.after_update do |active|
46
+ if active
47
+ puts "contact sensor is active"
48
+ else
49
+ puts "contact sensor is inactive"
50
+ end
51
+ end
52
+
53
+ Thread.new do
54
+ sleep 30
55
+
56
+ loop do
57
+ contact_sensor.contact_sensor_state = (0..1).to_a.sample
58
+ contact_sensor.status_low_battery = (0..1).to_a.sample
59
+ contact_sensor.status_tampered = (0..1).to_a.sample
60
+ contact_sensor.status_fault = (0..1).to_a.sample
61
+ contact_sensor.status_active = [true, false].to_a.sample
62
+
63
+ sleep 10
64
+ end
65
+ end
66
+
67
+ RubyHome.run
@@ -0,0 +1,49 @@
1
+ require 'ruby_home'
2
+
3
+ accessory_information = RubyHome::ServiceFactory.create(:accessory_information)
4
+ door = RubyHome::ServiceFactory.create(:door,
5
+ target_position: 0, # required
6
+ position_state: 1, # required
7
+ current_position: 0, # required
8
+ name: "door", # optional
9
+ obstruction_detected: false, # optional
10
+ )
11
+
12
+ door.target_position.after_update do |target_position|
13
+ puts "door target position #{target_position}"
14
+
15
+ if target_position < door.current_position
16
+ door.position_state = 0
17
+ elsif target_position > door.current_position
18
+ door.position_state = 1
19
+ end
20
+
21
+ sleep 1
22
+
23
+ door.current_position = target_position
24
+ door.position_state = 2
25
+ end
26
+
27
+ position_state_values = {
28
+ 0 => 'Decreasing',
29
+ 1 => 'Increasing',
30
+ 2 => 'Stopped'
31
+ }
32
+ door.position_state.after_update do |position_state|
33
+ state = position_state_values[position_state]
34
+ puts "door position state #{state}"
35
+ end
36
+
37
+ door.current_position.after_update do |current_position|
38
+ puts "door current position #{current_position}"
39
+ end
40
+
41
+ door.obstruction_detected.after_update do |obstruction_detected|
42
+ if obstruction_detected
43
+ puts "door obstruction detected"
44
+ else
45
+ puts "door no obstruction detected"
46
+ end
47
+ end
48
+
49
+ RubyHome.run
@@ -0,0 +1,31 @@
1
+ require 'ruby_home'
2
+
3
+ accessory_information = RubyHome::ServiceFactory.create(:accessory_information)
4
+ fan = RubyHome::ServiceFactory.create(:fan,
5
+ on: false, # required
6
+ name: "fan", # optional
7
+ rotation_speed: 50, # optional
8
+ rotation_direction: 0 # optional
9
+ )
10
+
11
+ fan.on.after_update do |on|
12
+ if on
13
+ puts "fan is on"
14
+ else
15
+ puts "fan is off"
16
+ end
17
+ end
18
+
19
+ fan.rotation_speed.after_update do |rotation_speed|
20
+ puts "fan is spinning at #{rotation_speed} speed"
21
+ end
22
+
23
+ fan.rotation_direction.after_update do |rotation_direction|
24
+ if rotation_direction == 0
25
+ puts "fan rotating clockwise"
26
+ elsif rotation_direction == 1
27
+ puts "fan rotating counter clockwise"
28
+ end
29
+ end
30
+
31
+ RubyHome.run
@@ -0,0 +1,69 @@
1
+ require 'ruby_home'
2
+
3
+ accessory_information = RubyHome::ServiceFactory.create(:accessory_information)
4
+ fan = RubyHome::ServiceFactory.create(:fan_v2,
5
+ active: 1, # required
6
+ name: "fan", # optional
7
+ swing_mode: 1, # optional
8
+ rotation_speed: 0, # optional
9
+ rotation_direction: 0, # optional
10
+ lock_physical_controls: 0, # optional
11
+ target_fan_state: 0, # optional
12
+ current_fan_state: 0 # optional
13
+ )
14
+
15
+ fan.active.after_update do |active|
16
+ if active == 0
17
+ puts "fan is inactive"
18
+ elsif active == 1
19
+ puts "fan is active"
20
+ end
21
+ end
22
+
23
+ fan.swing_mode.after_update do |swing_mode|
24
+ if swing_mode == 0
25
+ puts "fan swing is disabled"
26
+ elsif swing_mode == 1
27
+ puts "fan swing is enabled"
28
+ end
29
+ end
30
+
31
+ fan.rotation_speed.after_update do |rotation_speed|
32
+ puts "fan is spinning at #{rotation_speed} speed"
33
+ end
34
+
35
+ fan.rotation_direction.after_update do |rotation_direction|
36
+ if rotation_direction == 0
37
+ puts "fan rotating clockwise"
38
+ elsif rotation_direction == 1
39
+ puts "fan rotating counter clockwise"
40
+ end
41
+ end
42
+
43
+ fan.lock_physical_controls.after_update do |lock_physical_controls|
44
+ if lock_physical_controls == 0
45
+ puts "fan control lock disabled"
46
+ elsif lock_physical_controls == 1
47
+ puts "fan control lock enabled"
48
+ end
49
+ end
50
+
51
+ fan.target_fan_state.after_update do |target_fan_state|
52
+ if target_fan_state == 0
53
+ puts "fan target fan state manual"
54
+ elsif target_fan_state == 1
55
+ puts "fan target fan state auto"
56
+ end
57
+ end
58
+
59
+ fan.current_fan_state.after_update do |current_fan_state|
60
+ if current_fan_state == 0
61
+ puts "fan current fan state inactive"
62
+ elsif current_fan_state == 1
63
+ puts "fan current fan state idle"
64
+ elsif current_fan_state == 2
65
+ puts "fan current fan state blowing air"
66
+ end
67
+ end
68
+
69
+ RubyHome.run
@@ -0,0 +1,72 @@
1
+ require 'ruby_home'
2
+
3
+ accessory_information = RubyHome::ServiceFactory.create(:accessory_information)
4
+ garage_door_opener = RubyHome::ServiceFactory.create(:garage_door_opener,
5
+ obstruction_detected: false, # required
6
+ target_door_state: 1, # required
7
+ current_door_state: 1, # required
8
+ name: "garage door opener", # optional
9
+ lock_target_state: 1, # optional
10
+ lock_current_state: 1, # optional
11
+ )
12
+
13
+ garage_door_opener.obstruction_detected.after_update do |obstruction_detected|
14
+ if obstruction_detected
15
+ puts "garage door opener obstruction detected"
16
+ else
17
+ puts "garage door opener no obstruction detected"
18
+ end
19
+ end
20
+
21
+ target_door_state_values = {
22
+ 0 => 'Open',
23
+ 1 => 'Closed',
24
+ }
25
+ garage_door_opener.target_door_state.after_update do |target_door_state|
26
+ state = target_door_state_values[target_door_state]
27
+ puts "garage door opener target door state is #{state}"
28
+
29
+ if target_door_state == 0
30
+ garage_door_opener.current_door_state = 2
31
+ sleep 1
32
+ garage_door_opener.current_door_state = 0
33
+ elsif target_door_state == 1
34
+ garage_door_opener.current_door_state = 3
35
+ sleep 1
36
+ garage_door_opener.current_door_state = 1
37
+ end
38
+ end
39
+
40
+ current_door_state_values = {
41
+ 0 => 'Open',
42
+ 1 => 'Closed',
43
+ 2 => 'Opening',
44
+ 3 => 'Closing',
45
+ 4 => 'Stopped'
46
+ }
47
+ garage_door_opener.current_door_state.after_update do |current_door_state|
48
+ state = current_door_state_values[current_door_state]
49
+ puts "garage door opener current door state door state is #{state}"
50
+ end
51
+
52
+ garage_door_opener.lock_target_state.after_update do |lock_target_state|
53
+ if lock_target_state == 0
54
+ puts "garage door opener lock target state is unsecured"
55
+ elsif lock_target_state == 1
56
+ puts "garage door opener lock target state is secured"
57
+ end
58
+ end
59
+
60
+ garage_door_opener.lock_current_state.after_update do |lock_current_state|
61
+ if lock_current_state == 0
62
+ puts "garage door opener lock current state is unsecured"
63
+ elsif lock_current_state == 1
64
+ puts "garage door opener lock current state is secured"
65
+ elsif lock_current_state == 2
66
+ puts "garage door opener lock current state is jammed"
67
+ elsif lock_current_state == 3
68
+ puts "garage door opener lock current state is unknown"
69
+ end
70
+ end
71
+
72
+ RubyHome.run
@@ -0,0 +1,93 @@
1
+ require 'ruby_home'
2
+
3
+ accessory_information = RubyHome::ServiceFactory.create(:accessory_information)
4
+ heater_cooler = RubyHome::ServiceFactory.create(:heater_cooler,
5
+ current_temperature: 20, # required
6
+ target_heater_cooler_state: 1, # required
7
+ current_heater_cooler_state: 2, # required
8
+ active: 1, # required
9
+ name: "heater cooler", # optional
10
+ rotation_speed: 0, # optional
11
+ temperature_display_units: 0, # optional
12
+ heating_threshold_temperature: 20, # optional
13
+ cooling_threshold_temperature: 10, # optional
14
+ swing_mode: 1, # optional
15
+ lock_physical_controls: 0, # optional
16
+ )
17
+
18
+ heater_cooler.current_temperature.after_update do |current_temperature|
19
+ puts "heater cooler current temperature in celsius #{current_temperature}"
20
+ end
21
+
22
+ target_heater_cooler_state_values = {
23
+ 0 => 'Auto',
24
+ 1 => 'Heat',
25
+ 2 => 'Cool'
26
+ }
27
+ heater_cooler.target_heater_cooler_state.after_update do |target_heater_cooler_state|
28
+ state = target_heater_cooler_state_values[target_heater_cooler_state]
29
+ puts "heater cooler target heater cooler state is #{state}"
30
+ end
31
+
32
+ current_heater_cooler_state_values = {
33
+ 0 => 'Inactive',
34
+ 1 => 'Idle',
35
+ 2 => 'Heating',
36
+ 3 => 'Cooling'
37
+ }
38
+ heater_cooler.current_heater_cooler_state.after_update do |current_heater_cooler_state|
39
+ state = current_heater_cooler_state_values[current_heater_cooler_state]
40
+ puts "heater cooler target heater cooler state is #{state}"
41
+ end
42
+
43
+ heater_cooler.active.after_update do |active|
44
+ if active == 0
45
+ puts "heater cooler is inactive"
46
+ elsif active == 1
47
+ puts "heater cooler is active"
48
+ end
49
+ end
50
+
51
+ heater_cooler.rotation_speed.after_update do |rotation_speed|
52
+ puts "heater cooler is spinning at #{rotation_speed} speed"
53
+ end
54
+
55
+ heater_cooler.temperature_display_units.after_update do |temperature_display_unit|
56
+ if temperature_display_unit == 0
57
+ puts "heater cooler temperature display units Celsius"
58
+ elsif temperature_display_unit == 1
59
+ puts "heater cooler temperature display units Fahrenheit"
60
+ end
61
+ end
62
+
63
+ heater_cooler.heating_threshold_temperature.after_update do |heating_threshold_temperature|
64
+ # maximum_value: 25
65
+ # minimum_value: 0
66
+ # step_value: 0.1
67
+ puts "heater cooler heating threshold temperature #{heating_threshold_temperature}"
68
+ end
69
+
70
+ heater_cooler.cooling_threshold_temperature.after_update do |cooling_threshold_temperature|
71
+ # maximum_value: 35
72
+ # minimum_value: 10
73
+ # step_value: 0.1
74
+ puts "heater cooler cooling threshold temperature temperature #{cooling_threshold_temperature}"
75
+ end
76
+
77
+ heater_cooler.swing_mode.after_update do |swing_mode|
78
+ if swing_mode == 0
79
+ puts "heater cooler swimg is disabled"
80
+ elsif swing_mode == 1
81
+ puts "heater cooler swimg is enabled"
82
+ end
83
+ end
84
+
85
+ heater_cooler.lock_physical_controls.after_update do |lock_physical_controls|
86
+ if lock_physical_controls == 0
87
+ puts "heater cooler control lock disabled"
88
+ elsif lock_physical_controls == 1
89
+ puts "heater cooler control lock enabled"
90
+ end
91
+ end
92
+
93
+ RubyHome.run