ruby_home 0.2.1 → 0.2.6
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.
- checksums.yaml +4 -4
- data/.github/workflows/tests.yml +41 -0
- data/.gitignore +2 -2
- data/.rubocop.yml +2 -9
- data/.standard.yml +3 -0
- data/CHANGELOG.md +18 -0
- data/Gemfile +2 -2
- data/README.md +40 -77
- data/Rakefile +4 -4
- data/examples/air_purifier.rb +66 -0
- data/examples/air_quality_sensor.rb +119 -0
- data/examples/battery_service.rb +58 -0
- data/examples/carbon_dioxide_sensor.rb +78 -0
- data/examples/carbon_monoxide_sensor.rb +78 -0
- data/examples/contact_sensor.rb +66 -0
- data/examples/door.rb +48 -0
- data/examples/fan.rb +30 -0
- data/examples/fan_v2.rb +68 -0
- data/examples/garage_door_opener.rb +71 -0
- data/examples/heater_cooler.rb +92 -0
- data/examples/humidifier_dehumidifier.rb +88 -0
- data/examples/humidity_sensor.rb +62 -0
- data/examples/leak_sensor.rb +66 -0
- data/examples/light_sensor.rb +64 -0
- data/examples/lightbulb.rb +31 -0
- data/examples/lock_mechanism.rb +34 -0
- data/examples/motion_sensor.rb +66 -0
- data/examples/occupancy_sensor.rb +66 -0
- data/examples/outlet.rb +29 -0
- data/examples/security_system.rb +53 -0
- data/examples/smoke_sensor.rb +66 -0
- data/examples/switch.rb +16 -0
- data/examples/television.rb +73 -0
- data/examples/temperature_sensor.rb +62 -0
- data/examples/thermostat.rb +113 -0
- data/examples/window.rb +48 -0
- data/examples/window_covering.rb +72 -0
- data/lib/ruby_home.rb +21 -22
- data/lib/ruby_home/accessory.rb +1 -1
- data/lib/ruby_home/accessory_collection.rb +6 -6
- data/lib/ruby_home/accessory_info.rb +18 -18
- data/lib/ruby_home/characteristic.rb +13 -7
- data/lib/ruby_home/characteristic_collection.rb +13 -13
- data/lib/ruby_home/config/categories.yml +39 -0
- data/lib/ruby_home/config/characteristics.yml +190 -319
- data/lib/ruby_home/config/manual_characteristics.yml +278 -0
- data/lib/ruby_home/config/manual_services.yml +45 -0
- data/lib/ruby_home/config/services.yml +338 -304
- data/lib/ruby_home/configuration.rb +21 -2
- data/lib/ruby_home/device_id.rb +3 -3
- data/lib/ruby_home/dns/service.rb +4 -6
- data/lib/ruby_home/dns/text_record.rb +10 -10
- data/lib/ruby_home/errors.rb +1 -0
- data/lib/ruby_home/factories/characteristic_factory.rb +38 -37
- data/lib/ruby_home/factories/service_factory.rb +72 -72
- data/lib/ruby_home/factories/templates/characteristic_template.rb +6 -6
- data/lib/ruby_home/factories/templates/service_template.rb +12 -11
- data/lib/ruby_home/hap/crypto/chacha20poly1305.rb +2 -2
- data/lib/ruby_home/hap/crypto/hkdf.rb +4 -4
- data/lib/ruby_home/hap/crypto/session_key.rb +7 -7
- data/lib/ruby_home/hap/decrypter.rb +8 -8
- data/lib/ruby_home/hap/encrypter.rb +5 -6
- data/lib/ruby_home/hap/ev_response.rb +17 -17
- data/lib/ruby_home/hap/hap_request.rb +1 -1
- data/lib/ruby_home/hap/server.rb +4 -4
- data/lib/ruby_home/hap/server_handler.rb +8 -10
- data/lib/ruby_home/hap/session.rb +22 -22
- data/lib/ruby_home/hap/values/base_value.rb +3 -3
- data/lib/ruby_home/hap/values/bool_value.rb +4 -4
- data/lib/ruby_home/hap/values/float_value.rb +4 -4
- data/lib/ruby_home/hap/values/identify_value.rb +1 -1
- data/lib/ruby_home/hap/values/int32_value.rb +4 -4
- data/lib/ruby_home/hap/values/null_value.rb +1 -1
- data/lib/ruby_home/hap/values/string_value.rb +11 -11
- data/lib/ruby_home/hap/values/uint32_value.rb +5 -5
- data/lib/ruby_home/hap/values/uint8_value.rb +14 -14
- data/lib/ruby_home/hex_helper.rb +3 -3
- data/lib/ruby_home/http/application.rb +7 -7
- data/lib/ruby_home/http/controllers/accessories_controller.rb +3 -3
- data/lib/ruby_home/http/controllers/application_controller.rb +6 -6
- data/lib/ruby_home/http/controllers/characteristics_controller.rb +29 -29
- data/lib/ruby_home/http/controllers/identify_controller.rb +10 -10
- data/lib/ruby_home/http/controllers/pair_setups_controller.rb +19 -19
- data/lib/ruby_home/http/controllers/pair_verifies_controller.rb +9 -9
- data/lib/ruby_home/http/controllers/pairings_controller.rb +6 -6
- data/lib/ruby_home/http/serializers/accessory_serializer.rb +5 -5
- data/lib/ruby_home/http/serializers/characteristic_serializer.rb +27 -19
- data/lib/ruby_home/http/serializers/characteristic_value_serializer.rb +5 -5
- data/lib/ruby_home/http/serializers/object_serializer.rb +1 -1
- data/lib/ruby_home/http/serializers/service_serializer.rb +19 -9
- data/lib/ruby_home/http/serializers/uuid_helper.rb +2 -2
- data/lib/ruby_home/http/services/session_notifier.rb +8 -8
- data/lib/ruby_home/http/services/start_srp_service.rb +3 -3
- data/lib/ruby_home/http/services/verify_finish_service.rb +22 -22
- data/lib/ruby_home/http/services/verify_srp_service.rb +22 -22
- data/lib/ruby_home/identifier_cache.rb +4 -5
- data/lib/ruby_home/password.rb +14 -14
- data/lib/ruby_home/persistable.rb +19 -12
- data/lib/ruby_home/service.rb +5 -2
- data/lib/ruby_home/service_collection.rb +1 -1
- data/lib/ruby_home/version.rb +1 -1
- data/rubyhome.gemspec +31 -31
- data/sbin/characteristic_generator.rb +22 -24
- data/sbin/service_generator.rb +38 -19
- metadata +85 -44
- data/.travis.yml +0 -31
@@ -0,0 +1,92 @@
|
|
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
|
+
heater_cooler.current_temperature.after_update do |current_temperature|
|
18
|
+
puts "heater cooler current temperature in celsius #{current_temperature}"
|
19
|
+
end
|
20
|
+
|
21
|
+
target_heater_cooler_state_values = {
|
22
|
+
0 => "Auto",
|
23
|
+
1 => "Heat",
|
24
|
+
2 => "Cool"
|
25
|
+
}
|
26
|
+
heater_cooler.target_heater_cooler_state.after_update do |target_heater_cooler_state|
|
27
|
+
state = target_heater_cooler_state_values[target_heater_cooler_state]
|
28
|
+
puts "heater cooler target heater cooler state is #{state}"
|
29
|
+
end
|
30
|
+
|
31
|
+
current_heater_cooler_state_values = {
|
32
|
+
0 => "Inactive",
|
33
|
+
1 => "Idle",
|
34
|
+
2 => "Heating",
|
35
|
+
3 => "Cooling"
|
36
|
+
}
|
37
|
+
heater_cooler.current_heater_cooler_state.after_update do |current_heater_cooler_state|
|
38
|
+
state = current_heater_cooler_state_values[current_heater_cooler_state]
|
39
|
+
puts "heater cooler target heater cooler state is #{state}"
|
40
|
+
end
|
41
|
+
|
42
|
+
heater_cooler.active.after_update do |active|
|
43
|
+
if active == 0
|
44
|
+
puts "heater cooler is inactive"
|
45
|
+
elsif active == 1
|
46
|
+
puts "heater cooler is active"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
heater_cooler.rotation_speed.after_update do |rotation_speed|
|
51
|
+
puts "heater cooler is spinning at #{rotation_speed} speed"
|
52
|
+
end
|
53
|
+
|
54
|
+
heater_cooler.temperature_display_units.after_update do |temperature_display_unit|
|
55
|
+
if temperature_display_unit == 0
|
56
|
+
puts "heater cooler temperature display units Celsius"
|
57
|
+
elsif temperature_display_unit == 1
|
58
|
+
puts "heater cooler temperature display units Fahrenheit"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
heater_cooler.heating_threshold_temperature.after_update do |heating_threshold_temperature|
|
63
|
+
# maximum_value: 25
|
64
|
+
# minimum_value: 0
|
65
|
+
# step_value: 0.1
|
66
|
+
puts "heater cooler heating threshold temperature #{heating_threshold_temperature}"
|
67
|
+
end
|
68
|
+
|
69
|
+
heater_cooler.cooling_threshold_temperature.after_update do |cooling_threshold_temperature|
|
70
|
+
# maximum_value: 35
|
71
|
+
# minimum_value: 10
|
72
|
+
# step_value: 0.1
|
73
|
+
puts "heater cooler cooling threshold temperature temperature #{cooling_threshold_temperature}"
|
74
|
+
end
|
75
|
+
|
76
|
+
heater_cooler.swing_mode.after_update do |swing_mode|
|
77
|
+
if swing_mode == 0
|
78
|
+
puts "heater cooler swimg is disabled"
|
79
|
+
elsif swing_mode == 1
|
80
|
+
puts "heater cooler swimg is enabled"
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
heater_cooler.lock_physical_controls.after_update do |lock_physical_controls|
|
85
|
+
if lock_physical_controls == 0
|
86
|
+
puts "heater cooler control lock disabled"
|
87
|
+
elsif lock_physical_controls == 1
|
88
|
+
puts "heater cooler control lock enabled"
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
RubyHome.run
|
@@ -0,0 +1,88 @@
|
|
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
|
+
humidifier_dehumidifier.active.after_update do |active|
|
18
|
+
if active == 0
|
19
|
+
puts "humidifier dehumidifier is inactive"
|
20
|
+
elsif active == 1
|
21
|
+
puts "humidifier dehumidifier is active"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
target_humidifier_dehumidifier_state_values = {
|
26
|
+
0 => "Humidifier or Dehumidifier",
|
27
|
+
1 => "Humidifier",
|
28
|
+
2 => "Dehumidifier"
|
29
|
+
}
|
30
|
+
humidifier_dehumidifier.target_humidifier_dehumidifier_state.after_update do |target_humidifier_dehumidifier_state|
|
31
|
+
state = target_humidifier_dehumidifier_state_values[target_humidifier_dehumidifier_state]
|
32
|
+
puts "humidifier dehumidifier target humidifier dehumidifier state is #{state}"
|
33
|
+
end
|
34
|
+
|
35
|
+
current_humidifier_dehumidifier_state_values = {
|
36
|
+
0 => "Inactive",
|
37
|
+
1 => "Idle",
|
38
|
+
2 => "Humidifying",
|
39
|
+
3 => "Dehumidifying"
|
40
|
+
}
|
41
|
+
humidifier_dehumidifier.current_humidifier_dehumidifier_state.after_update do |current_humidifier_dehumidifier_state|
|
42
|
+
state = current_humidifier_dehumidifier_state_values[current_humidifier_dehumidifier_state]
|
43
|
+
puts "humidifier dehumidifier target humidifier dehumidifier state is #{state}"
|
44
|
+
end
|
45
|
+
|
46
|
+
humidifier_dehumidifier.current_relative_humidity.after_update do |current_relative_humidity|
|
47
|
+
puts "humidifier dehumidifier current relative humidity at #{current_relative_humidity}"
|
48
|
+
end
|
49
|
+
|
50
|
+
humidifier_dehumidifier.rotation_speed.after_update do |rotation_speed|
|
51
|
+
puts "humidifier dehumidifier is spinning at #{rotation_speed} speed"
|
52
|
+
end
|
53
|
+
|
54
|
+
humidifier_dehumidifier.relative_humidity_humidifier_threshold.after_update do |relative_humidity_humidifier_threshold|
|
55
|
+
# maximum_value: 100
|
56
|
+
# minimum_value: 0
|
57
|
+
# step_value: 1
|
58
|
+
puts "humidifier dehumidifier relative humidity humidifier threshold temperature #{relative_humidity_humidifier_threshold}"
|
59
|
+
end
|
60
|
+
|
61
|
+
humidifier_dehumidifier.relative_humidity_dehumidifier_threshold.after_update do |relative_humidity_dehumidifier_threshold|
|
62
|
+
# maximum_value: 100
|
63
|
+
# minimum_value: 0
|
64
|
+
# step_value: 1
|
65
|
+
puts "humidifier dehumidifier relative humidity humidifier threshold temperature #{relative_humidity_dehumidifier_threshold}"
|
66
|
+
end
|
67
|
+
|
68
|
+
humidifier_dehumidifier.water_level.after_update do |water_level|
|
69
|
+
puts "humidifier dehumidifier water level #{water_level}"
|
70
|
+
end
|
71
|
+
|
72
|
+
humidifier_dehumidifier.swing_mode.after_update do |swing_mode|
|
73
|
+
if swing_mode == 0
|
74
|
+
puts "humidifier dehumidifier swimg is disabled"
|
75
|
+
elsif swing_mode == 1
|
76
|
+
puts "humidifier dehumidifier swimg is enabled"
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
humidifier_dehumidifier.lock_physical_controls.after_update do |lock_physical_controls|
|
81
|
+
if lock_physical_controls == 0
|
82
|
+
puts "humidifier dehumidifier control lock disabled"
|
83
|
+
elsif lock_physical_controls == 1
|
84
|
+
puts "humidifier dehumidifier control lock enabled"
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
RubyHome.run
|
@@ -0,0 +1,62 @@
|
|
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
|
+
humidity_sensor.current_relative_humidity.after_update do |current_relative_humidity|
|
13
|
+
puts "humidity sensor current relative humidity #{current_relative_humidity}"
|
14
|
+
end
|
15
|
+
|
16
|
+
humidity_sensor.status_low_battery.after_update do |status_low_battery|
|
17
|
+
if status_low_battery == 0
|
18
|
+
puts "humidity sensor low battery is battery level normal"
|
19
|
+
elsif status_low_battery == 1
|
20
|
+
puts "humidity sensor low battery is battery level low"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
humidity_sensor.status_tampered.after_update do |status_tampered|
|
25
|
+
if status_tampered == 0
|
26
|
+
puts "humidity sensor status_tampered not tampered"
|
27
|
+
elsif status_tampered == 1
|
28
|
+
puts "humidity sensor status_tampered tampered"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
humidity_sensor.status_fault.after_update do |status_fault|
|
33
|
+
if status_fault == 0
|
34
|
+
puts "humidity sensor status_fault no fault"
|
35
|
+
elsif status_fault == 1
|
36
|
+
puts "humidity sensor status_fault general fault"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
humidity_sensor.status_active.after_update do |active|
|
41
|
+
if active
|
42
|
+
puts "humidity sensor is active"
|
43
|
+
else
|
44
|
+
puts "humidity sensor is inactive"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
Thread.new do
|
49
|
+
sleep 30
|
50
|
+
|
51
|
+
loop do
|
52
|
+
humidity_sensor.current_relative_humidity = (0..100).to_a.sample
|
53
|
+
humidity_sensor.status_low_battery = (0..1).to_a.sample
|
54
|
+
humidity_sensor.status_tampered = (0..1).to_a.sample
|
55
|
+
humidity_sensor.status_fault = (0..1).to_a.sample
|
56
|
+
humidity_sensor.status_active = [true, false].to_a.sample
|
57
|
+
|
58
|
+
sleep 10
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
RubyHome.run
|
@@ -0,0 +1,66 @@
|
|
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
|
+
leak_sensor.leak_detected.after_update do |leak_detected|
|
13
|
+
if leak_detected == 0
|
14
|
+
puts "leak sensor leak detected leak not detected"
|
15
|
+
elsif leak_detected == 1
|
16
|
+
puts "leak sensor leak detected leak detected"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
leak_sensor.status_low_battery.after_update do |status_low_battery|
|
21
|
+
if status_low_battery == 0
|
22
|
+
puts "leak sensor low battery is battery level normal"
|
23
|
+
elsif status_low_battery == 1
|
24
|
+
puts "leak sensor low battery is battery level low"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
leak_sensor.status_tampered.after_update do |status_tampered|
|
29
|
+
if status_tampered == 0
|
30
|
+
puts "leak sensor status_tampered not tampered"
|
31
|
+
elsif status_tampered == 1
|
32
|
+
puts "leak sensor status_tampered tampered"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
leak_sensor.status_fault.after_update do |status_fault|
|
37
|
+
if status_fault == 0
|
38
|
+
puts "leak sensor status_fault no fault"
|
39
|
+
elsif status_fault == 1
|
40
|
+
puts "leak sensor status_fault general fault"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
leak_sensor.status_active.after_update do |active|
|
45
|
+
if active
|
46
|
+
puts "leak sensor is active"
|
47
|
+
else
|
48
|
+
puts "leak sensor is inactive"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
Thread.new do
|
53
|
+
sleep 30
|
54
|
+
|
55
|
+
loop do
|
56
|
+
leak_sensor.leak_detected = (0..1).to_a.sample
|
57
|
+
leak_sensor.status_low_battery = (0..1).to_a.sample
|
58
|
+
leak_sensor.status_tampered = (0..1).to_a.sample
|
59
|
+
leak_sensor.status_fault = (0..1).to_a.sample
|
60
|
+
leak_sensor.status_active = [true, false].to_a.sample
|
61
|
+
|
62
|
+
sleep 10
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
RubyHome.run
|
@@ -0,0 +1,64 @@
|
|
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
|
+
light_sensor.current_ambient_light_level.after_update do |current_ambient_light_level|
|
13
|
+
# maximum_value: 100000
|
14
|
+
# minimum_value: 0.0001
|
15
|
+
puts "light sensor current ambient light level #{current_ambient_light_level}"
|
16
|
+
end
|
17
|
+
|
18
|
+
light_sensor.status_low_battery.after_update do |status_low_battery|
|
19
|
+
if status_low_battery == 0
|
20
|
+
puts "light sensor low battery is battery level normal"
|
21
|
+
elsif status_low_battery == 1
|
22
|
+
puts "light sensor low battery is battery level low"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
light_sensor.status_tampered.after_update do |status_tampered|
|
27
|
+
if status_tampered == 0
|
28
|
+
puts "light sensor status_tampered not tampered"
|
29
|
+
elsif status_tampered == 1
|
30
|
+
puts "light sensor status_tampered tampered"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
light_sensor.status_fault.after_update do |status_fault|
|
35
|
+
if status_fault == 0
|
36
|
+
puts "light sensor status_fault no fault"
|
37
|
+
elsif status_fault == 1
|
38
|
+
puts "light sensor status_fault general fault"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
light_sensor.status_active.after_update do |active|
|
43
|
+
if active
|
44
|
+
puts "light sensor is active"
|
45
|
+
else
|
46
|
+
puts "light sensor is inactive"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
Thread.new do
|
51
|
+
sleep 30
|
52
|
+
|
53
|
+
loop do
|
54
|
+
light_sensor.current_ambient_light_level = (1..100000).to_a.sample
|
55
|
+
light_sensor.status_low_battery = (0..1).to_a.sample
|
56
|
+
light_sensor.status_tampered = (0..1).to_a.sample
|
57
|
+
light_sensor.status_fault = (0..1).to_a.sample
|
58
|
+
light_sensor.status_active = [true, false].to_a.sample
|
59
|
+
|
60
|
+
sleep 10
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
RubyHome.run
|
@@ -0,0 +1,31 @@
|
|
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
|
+
lightbulb.on.after_update do |on|
|
12
|
+
if on
|
13
|
+
puts "lightbulb is on"
|
14
|
+
else
|
15
|
+
puts "lightbulb is off"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
lightbulb.brightness.after_update do |brightness|
|
20
|
+
puts "lightbulb is at #{brightness} brightness"
|
21
|
+
end
|
22
|
+
|
23
|
+
lightbulb.saturation.after_update do |saturation|
|
24
|
+
puts "lightbulb is at #{saturation} saturation"
|
25
|
+
end
|
26
|
+
|
27
|
+
lightbulb.hue.after_update do |hue|
|
28
|
+
puts "lightbulb is at #{hue} hue"
|
29
|
+
end
|
30
|
+
|
31
|
+
RubyHome.run
|
@@ -0,0 +1,34 @@
|
|
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
|
+
lock_mechanism.lock_target_state.after_update do |lock_target_state|
|
10
|
+
if lock_target_state == 0
|
11
|
+
puts "lock target state is unsecured"
|
12
|
+
|
13
|
+
sleep 1
|
14
|
+
lock_mechanism.lock_current_state = 0
|
15
|
+
elsif lock_target_state == 1
|
16
|
+
puts "lock target state is secured"
|
17
|
+
|
18
|
+
sleep 1
|
19
|
+
lock_mechanism.lock_current_state = 1
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
lock_current_state_values = {
|
24
|
+
0 => "Unsecured",
|
25
|
+
1 => "Secured",
|
26
|
+
2 => "Jammed",
|
27
|
+
3 => "Unknown"
|
28
|
+
}
|
29
|
+
lock_mechanism.lock_current_state.after_update do |lock_current_state|
|
30
|
+
state = lock_current_state_values[lock_current_state]
|
31
|
+
puts "lock current state #{state}"
|
32
|
+
end
|
33
|
+
|
34
|
+
RubyHome.run
|
@@ -0,0 +1,66 @@
|
|
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
|
+
motion_sensor.motion_detected.after_update do |motion_detected|
|
13
|
+
if motion_detected
|
14
|
+
puts "motion sensor detected motion"
|
15
|
+
else
|
16
|
+
puts "motion sensor no motion detected"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
motion_sensor.status_low_battery.after_update do |status_low_battery|
|
21
|
+
if status_low_battery == 0
|
22
|
+
puts "motion sensor battery level normal"
|
23
|
+
elsif status_low_battery == 1
|
24
|
+
puts "motion sensor battery level lormal"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
motion_sensor.status_tampered.after_update do |status_tampered|
|
29
|
+
if status_tampered == 0
|
30
|
+
puts "motion sensor status_tampered not tampered"
|
31
|
+
elsif status_tampered == 1
|
32
|
+
puts "motion sensor status_tampered tampered"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
motion_sensor.status_fault.after_update do |status_fault|
|
37
|
+
if status_fault == 0
|
38
|
+
puts "motion sensor status_fault no fault"
|
39
|
+
elsif status_fault == 1
|
40
|
+
puts "motion sensor status_fault general fault"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
motion_sensor.status_active.after_update do |active|
|
45
|
+
if active
|
46
|
+
puts "motion sensor is active"
|
47
|
+
else
|
48
|
+
puts "motion sensor is inactive"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
Thread.new do
|
53
|
+
sleep 30
|
54
|
+
|
55
|
+
loop do
|
56
|
+
motion_sensor.motion_detected = [true, false].to_a.sample
|
57
|
+
motion_sensor.status_low_battery = (0..1).to_a.sample
|
58
|
+
motion_sensor.status_tampered = (0..1).to_a.sample
|
59
|
+
motion_sensor.status_fault = (0..1).to_a.sample
|
60
|
+
motion_sensor.status_active = [true, false].to_a.sample
|
61
|
+
|
62
|
+
sleep 10
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
RubyHome.run
|