ruby_home 0.2.1 → 0.2.6
Sign up to get free protection for your applications and to get access to all the features.
- 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,58 @@
|
|
1
|
+
require "ruby_home"
|
2
|
+
|
3
|
+
accessory_information = RubyHome::ServiceFactory.create(:accessory_information)
|
4
|
+
battery_service = RubyHome::ServiceFactory.create(:battery_service,
|
5
|
+
status_low_battery: 0, # required
|
6
|
+
charging_state: 0, # required
|
7
|
+
battery_level: 20, # required
|
8
|
+
name: "battery service") # optional
|
9
|
+
|
10
|
+
battery_service.status_low_battery.after_update do |status_low_battery|
|
11
|
+
if status_low_battery == 0
|
12
|
+
puts "battery service status low battery is battery level normal"
|
13
|
+
elsif status_low_battery == 1
|
14
|
+
puts "battery service status low battery is battery level low"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
battery_service.charging_state.after_update do |charging_state|
|
19
|
+
if charging_state == 0
|
20
|
+
puts "battery service charging state is not charging"
|
21
|
+
elsif charging_state == 1
|
22
|
+
puts "battery service charging state is charging"
|
23
|
+
elsif charging_state == 2
|
24
|
+
puts "battery service charging state is not chargeable"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
battery_service.battery_level.after_update do |battery_level|
|
29
|
+
puts "battery service battery level #{battery_level}"
|
30
|
+
|
31
|
+
if battery_level < 10 && battery_service.status_low_battery != 1
|
32
|
+
battery_service.status_low_battery = 1
|
33
|
+
end
|
34
|
+
|
35
|
+
if battery_level > 11 && battery_service.status_low_battery != 0
|
36
|
+
battery_service.status_low_battery = 0
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
Thread.new do
|
41
|
+
sleep 30
|
42
|
+
|
43
|
+
loop do
|
44
|
+
battery_service.charging_state = 0
|
45
|
+
while battery_service.battery_level > 0
|
46
|
+
battery_service.battery_level -= 1
|
47
|
+
sleep 1
|
48
|
+
end
|
49
|
+
|
50
|
+
battery_service.charging_state = 1
|
51
|
+
while battery_service.battery_level < 101
|
52
|
+
battery_service.battery_level += 1
|
53
|
+
sleep 1
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
RubyHome.run
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require "ruby_home"
|
2
|
+
|
3
|
+
accessory_information = RubyHome::ServiceFactory.create(:accessory_information)
|
4
|
+
carbon_dioxide_sensor = RubyHome::ServiceFactory.create(:carbon_dioxide_sensor,
|
5
|
+
carbon_dioxide_detected: 0, # required
|
6
|
+
name: "carbon dioxide sensor", # optional
|
7
|
+
carbon_dioxide_peak_level: 0, # optional
|
8
|
+
carbon_dioxide_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
|
+
carbon_dioxide_sensor.carbon_dioxide_detected.after_update do |carbon_dioxide_detected|
|
15
|
+
if carbon_dioxide_detected == 0
|
16
|
+
puts "carbon dioxide sensor carbon dioxide detected CO2 levels normal"
|
17
|
+
elsif carbon_dioxide_detected == 1
|
18
|
+
puts "carbon dioxide sensor carbon dioxide detected CO2 levels abnormal"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
carbon_dioxide_sensor.carbon_dioxide_peak_level.after_update do |carbon_dioxide_peak_level|
|
23
|
+
puts "carbon dioxide sensor carbon_dioxide_peak_level #{carbon_dioxide_peak_level}"
|
24
|
+
end
|
25
|
+
|
26
|
+
carbon_dioxide_sensor.carbon_dioxide_level.after_update do |carbon_dioxide_level|
|
27
|
+
puts "carbon dioxide sensor carbon_dioxide_level #{carbon_dioxide_level}"
|
28
|
+
end
|
29
|
+
|
30
|
+
carbon_dioxide_sensor.status_tampered.after_update do |status_tampered|
|
31
|
+
if status_tampered == 0
|
32
|
+
puts "carbon dioxide sensor status_tampered not tampered"
|
33
|
+
elsif status_tampered == 1
|
34
|
+
puts "carbon dioxide sensor status_tampered tampered"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
carbon_dioxide_sensor.status_low_battery.after_update do |status_low_battery|
|
39
|
+
if status_low_battery == 0
|
40
|
+
puts "carbon dioxide sensor low battery is battery level normal"
|
41
|
+
elsif status_low_battery == 1
|
42
|
+
puts "carbon dioxide sensor low battery is battery level low"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
carbon_dioxide_sensor.status_fault.after_update do |status_fault|
|
47
|
+
if status_fault == 0
|
48
|
+
puts "carbon dioxide sensor status_fault no fault"
|
49
|
+
elsif status_fault == 1
|
50
|
+
puts "carbon dioxide sensor status_fault general fault"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
carbon_dioxide_sensor.status_active.after_update do |active|
|
55
|
+
if active
|
56
|
+
puts "carbon dioxide sensor is active"
|
57
|
+
else
|
58
|
+
puts "carbon dioxide sensor is inactive"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
Thread.new do
|
63
|
+
sleep 30
|
64
|
+
|
65
|
+
loop do
|
66
|
+
carbon_dioxide_sensor.carbon_dioxide_detected = (0..1).to_a.sample
|
67
|
+
carbon_dioxide_sensor.carbon_dioxide_peak_level = (0..100000).to_a.sample
|
68
|
+
carbon_dioxide_sensor.carbon_dioxide_level = (0..100000).to_a.sample
|
69
|
+
carbon_dioxide_sensor.status_tampered = (0..1).to_a.sample
|
70
|
+
carbon_dioxide_sensor.status_low_battery = (0..1).to_a.sample
|
71
|
+
carbon_dioxide_sensor.status_fault = (0..1).to_a.sample
|
72
|
+
carbon_dioxide_sensor.status_active = [true, false].to_a.sample
|
73
|
+
|
74
|
+
sleep 10
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
RubyHome.run
|
@@ -0,0 +1,78 @@
|
|
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
|
+
carbon_monoxide_sensor.carbon_monoxide_detected.after_update do |carbon_monoxide_detected|
|
15
|
+
if carbon_monoxide_detected == 0
|
16
|
+
puts "carbon monoxide sensor carbon monoxide detected CO2 levels normal"
|
17
|
+
elsif carbon_monoxide_detected == 1
|
18
|
+
puts "carbon monoxide sensor carbon monoxide detected CO2 levels abnormal"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
carbon_monoxide_sensor.carbon_monoxide_peak_level.after_update do |carbon_monoxide_peak_level|
|
23
|
+
puts "carbon monoxide sensor carbon_monoxide_peak_level #{carbon_monoxide_peak_level}"
|
24
|
+
end
|
25
|
+
|
26
|
+
carbon_monoxide_sensor.carbon_monoxide_level.after_update do |carbon_monoxide_level|
|
27
|
+
puts "carbon monoxide sensor carbon_monoxide_level #{carbon_monoxide_level}"
|
28
|
+
end
|
29
|
+
|
30
|
+
carbon_monoxide_sensor.status_tampered.after_update do |status_tampered|
|
31
|
+
if status_tampered == 0
|
32
|
+
puts "carbon monoxide sensor status_tampered not tampered"
|
33
|
+
elsif status_tampered == 1
|
34
|
+
puts "carbon monoxide sensor status_tampered tampered"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
carbon_monoxide_sensor.status_low_battery.after_update do |status_low_battery|
|
39
|
+
if status_low_battery == 0
|
40
|
+
puts "carbon monoxide sensor low battery is battery level normal"
|
41
|
+
elsif status_low_battery == 1
|
42
|
+
puts "carbon monoxide sensor low battery is battery level low"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
carbon_monoxide_sensor.status_fault.after_update do |status_fault|
|
47
|
+
if status_fault == 0
|
48
|
+
puts "carbon monoxide sensor status_fault no fault"
|
49
|
+
elsif status_fault == 1
|
50
|
+
puts "carbon monoxide sensor status_fault general fault"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
carbon_monoxide_sensor.status_active.after_update do |active|
|
55
|
+
if active
|
56
|
+
puts "carbon monoxide sensor is active"
|
57
|
+
else
|
58
|
+
puts "carbon monoxide sensor is inactive"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
Thread.new do
|
63
|
+
sleep 30
|
64
|
+
|
65
|
+
loop do
|
66
|
+
carbon_monoxide_sensor.carbon_monoxide_detected = (0..1).to_a.sample
|
67
|
+
carbon_monoxide_sensor.carbon_monoxide_peak_level = (0..100).to_a.sample
|
68
|
+
carbon_monoxide_sensor.carbon_monoxide_level = (0..100).to_a.sample
|
69
|
+
carbon_monoxide_sensor.status_tampered = (0..1).to_a.sample
|
70
|
+
carbon_monoxide_sensor.status_low_battery = (0..1).to_a.sample
|
71
|
+
carbon_monoxide_sensor.status_fault = (0..1).to_a.sample
|
72
|
+
carbon_monoxide_sensor.status_active = [true, false].to_a.sample
|
73
|
+
|
74
|
+
sleep 10
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
RubyHome.run
|
@@ -0,0 +1,66 @@
|
|
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
|
+
contact_sensor.contact_sensor_state.after_update do |contact_sensor_state|
|
13
|
+
if contact_sensor_state == 0
|
14
|
+
puts "contact sensor contact sensor state contact detected"
|
15
|
+
elsif contact_sensor_state == 1
|
16
|
+
puts "contact sensor contact sensor state contact not detected"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
contact_sensor.status_low_battery.after_update do |status_low_battery|
|
21
|
+
if status_low_battery == 0
|
22
|
+
puts "contact sensor low battery is battery level normal"
|
23
|
+
elsif status_low_battery == 1
|
24
|
+
puts "contact sensor low battery is battery level low"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
contact_sensor.status_tampered.after_update do |status_tampered|
|
29
|
+
if status_tampered == 0
|
30
|
+
puts "contact sensor status_tampered not tampered"
|
31
|
+
elsif status_tampered == 1
|
32
|
+
puts "contact sensor status_tampered tampered"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
contact_sensor.status_fault.after_update do |status_fault|
|
37
|
+
if status_fault == 0
|
38
|
+
puts "contact sensor status_fault no fault"
|
39
|
+
elsif status_fault == 1
|
40
|
+
puts "contact sensor status_fault general fault"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
contact_sensor.status_active.after_update do |active|
|
45
|
+
if active
|
46
|
+
puts "contact sensor is active"
|
47
|
+
else
|
48
|
+
puts "contact sensor is inactive"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
Thread.new do
|
53
|
+
sleep 30
|
54
|
+
|
55
|
+
loop do
|
56
|
+
contact_sensor.contact_sensor_state = (0..1).to_a.sample
|
57
|
+
contact_sensor.status_low_battery = (0..1).to_a.sample
|
58
|
+
contact_sensor.status_tampered = (0..1).to_a.sample
|
59
|
+
contact_sensor.status_fault = (0..1).to_a.sample
|
60
|
+
contact_sensor.status_active = [true, false].to_a.sample
|
61
|
+
|
62
|
+
sleep 10
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
RubyHome.run
|
data/examples/door.rb
ADDED
@@ -0,0 +1,48 @@
|
|
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
|
+
door.target_position.after_update do |target_position|
|
12
|
+
puts "door target position #{target_position}"
|
13
|
+
|
14
|
+
if target_position < door.current_position
|
15
|
+
door.position_state = 0
|
16
|
+
elsif target_position > door.current_position
|
17
|
+
door.position_state = 1
|
18
|
+
end
|
19
|
+
|
20
|
+
sleep 1
|
21
|
+
|
22
|
+
door.current_position = target_position
|
23
|
+
door.position_state = 2
|
24
|
+
end
|
25
|
+
|
26
|
+
position_state_values = {
|
27
|
+
0 => "Decreasing",
|
28
|
+
1 => "Increasing",
|
29
|
+
2 => "Stopped"
|
30
|
+
}
|
31
|
+
door.position_state.after_update do |position_state|
|
32
|
+
state = position_state_values[position_state]
|
33
|
+
puts "door position state #{state}"
|
34
|
+
end
|
35
|
+
|
36
|
+
door.current_position.after_update do |current_position|
|
37
|
+
puts "door current position #{current_position}"
|
38
|
+
end
|
39
|
+
|
40
|
+
door.obstruction_detected.after_update do |obstruction_detected|
|
41
|
+
if obstruction_detected
|
42
|
+
puts "door obstruction detected"
|
43
|
+
else
|
44
|
+
puts "door no obstruction detected"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
RubyHome.run
|
data/examples/fan.rb
ADDED
@@ -0,0 +1,30 @@
|
|
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
|
+
fan.on.after_update do |on|
|
11
|
+
if on
|
12
|
+
puts "fan is on"
|
13
|
+
else
|
14
|
+
puts "fan is off"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
fan.rotation_speed.after_update do |rotation_speed|
|
19
|
+
puts "fan is spinning at #{rotation_speed} speed"
|
20
|
+
end
|
21
|
+
|
22
|
+
fan.rotation_direction.after_update do |rotation_direction|
|
23
|
+
if rotation_direction == 0
|
24
|
+
puts "fan rotating clockwise"
|
25
|
+
elsif rotation_direction == 1
|
26
|
+
puts "fan rotating counter clockwise"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
RubyHome.run
|
data/examples/fan_v2.rb
ADDED
@@ -0,0 +1,68 @@
|
|
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
|
+
fan.active.after_update do |active|
|
15
|
+
if active == 0
|
16
|
+
puts "fan is inactive"
|
17
|
+
elsif active == 1
|
18
|
+
puts "fan is active"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
fan.swing_mode.after_update do |swing_mode|
|
23
|
+
if swing_mode == 0
|
24
|
+
puts "fan swing is disabled"
|
25
|
+
elsif swing_mode == 1
|
26
|
+
puts "fan swing is enabled"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
fan.rotation_speed.after_update do |rotation_speed|
|
31
|
+
puts "fan is spinning at #{rotation_speed} speed"
|
32
|
+
end
|
33
|
+
|
34
|
+
fan.rotation_direction.after_update do |rotation_direction|
|
35
|
+
if rotation_direction == 0
|
36
|
+
puts "fan rotating clockwise"
|
37
|
+
elsif rotation_direction == 1
|
38
|
+
puts "fan rotating counter clockwise"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
fan.lock_physical_controls.after_update do |lock_physical_controls|
|
43
|
+
if lock_physical_controls == 0
|
44
|
+
puts "fan control lock disabled"
|
45
|
+
elsif lock_physical_controls == 1
|
46
|
+
puts "fan control lock enabled"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
fan.target_fan_state.after_update do |target_fan_state|
|
51
|
+
if target_fan_state == 0
|
52
|
+
puts "fan target fan state manual"
|
53
|
+
elsif target_fan_state == 1
|
54
|
+
puts "fan target fan state auto"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
fan.current_fan_state.after_update do |current_fan_state|
|
59
|
+
if current_fan_state == 0
|
60
|
+
puts "fan current fan state inactive"
|
61
|
+
elsif current_fan_state == 1
|
62
|
+
puts "fan current fan state idle"
|
63
|
+
elsif current_fan_state == 2
|
64
|
+
puts "fan current fan state blowing air"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
RubyHome.run
|
@@ -0,0 +1,71 @@
|
|
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
|
+
garage_door_opener.obstruction_detected.after_update do |obstruction_detected|
|
13
|
+
if obstruction_detected
|
14
|
+
puts "garage door opener obstruction detected"
|
15
|
+
else
|
16
|
+
puts "garage door opener no obstruction detected"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
target_door_state_values = {
|
21
|
+
0 => "Open",
|
22
|
+
1 => "Closed"
|
23
|
+
}
|
24
|
+
garage_door_opener.target_door_state.after_update do |target_door_state|
|
25
|
+
state = target_door_state_values[target_door_state]
|
26
|
+
puts "garage door opener target door state is #{state}"
|
27
|
+
|
28
|
+
if target_door_state == 0
|
29
|
+
garage_door_opener.current_door_state = 2
|
30
|
+
sleep 1
|
31
|
+
garage_door_opener.current_door_state = 0
|
32
|
+
elsif target_door_state == 1
|
33
|
+
garage_door_opener.current_door_state = 3
|
34
|
+
sleep 1
|
35
|
+
garage_door_opener.current_door_state = 1
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
current_door_state_values = {
|
40
|
+
0 => "Open",
|
41
|
+
1 => "Closed",
|
42
|
+
2 => "Opening",
|
43
|
+
3 => "Closing",
|
44
|
+
4 => "Stopped"
|
45
|
+
}
|
46
|
+
garage_door_opener.current_door_state.after_update do |current_door_state|
|
47
|
+
state = current_door_state_values[current_door_state]
|
48
|
+
puts "garage door opener current door state door state is #{state}"
|
49
|
+
end
|
50
|
+
|
51
|
+
garage_door_opener.lock_target_state.after_update do |lock_target_state|
|
52
|
+
if lock_target_state == 0
|
53
|
+
puts "garage door opener lock target state is unsecured"
|
54
|
+
elsif lock_target_state == 1
|
55
|
+
puts "garage door opener lock target state is secured"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
garage_door_opener.lock_current_state.after_update do |lock_current_state|
|
60
|
+
if lock_current_state == 0
|
61
|
+
puts "garage door opener lock current state is unsecured"
|
62
|
+
elsif lock_current_state == 1
|
63
|
+
puts "garage door opener lock current state is secured"
|
64
|
+
elsif lock_current_state == 2
|
65
|
+
puts "garage door opener lock current state is jammed"
|
66
|
+
elsif lock_current_state == 3
|
67
|
+
puts "garage door opener lock current state is unknown"
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
RubyHome.run
|