ruby_home 0.2.0 → 0.2.5
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/CHANGELOG.md +13 -0
- data/README.md +47 -84
- data/examples/air_purifier.rb +67 -0
- data/examples/air_quality_sensor.rb +120 -0
- data/examples/battery_service.rb +59 -0
- data/examples/carbon_dioxide_sensor.rb +79 -0
- data/examples/carbon_monoxide_sensor.rb +79 -0
- data/examples/contact_sensor.rb +67 -0
- data/examples/door.rb +49 -0
- data/examples/fan.rb +31 -0
- data/examples/fan_v2.rb +69 -0
- data/examples/garage_door_opener.rb +72 -0
- data/examples/heater_cooler.rb +93 -0
- data/examples/humidifier_dehumidifier.rb +89 -0
- data/examples/humidity_sensor.rb +63 -0
- data/examples/leak_sensor.rb +67 -0
- data/examples/light_sensor.rb +65 -0
- data/examples/lightbulb.rb +32 -0
- data/examples/lock_mechanism.rb +35 -0
- data/examples/motion_sensor.rb +67 -0
- data/examples/occupancy_sensor.rb +67 -0
- data/examples/outlet.rb +30 -0
- data/examples/security_system.rb +54 -0
- data/examples/smoke_sensor.rb +67 -0
- data/examples/switch.rb +17 -0
- data/examples/television.rb +78 -0
- data/examples/temperature_sensor.rb +63 -0
- data/examples/thermostat.rb +114 -0
- data/examples/window.rb +49 -0
- data/examples/window_covering.rb +73 -0
- data/lib/ruby_home.rb +0 -1
- data/lib/ruby_home/characteristic.rb +7 -1
- data/lib/ruby_home/config/categories.yml +39 -0
- data/lib/ruby_home/config/characteristics.yml +479 -3
- data/lib/ruby_home/config/services.yml +79 -4
- data/lib/ruby_home/configuration.rb +19 -0
- data/lib/ruby_home/dns/service.rb +2 -0
- data/lib/ruby_home/dns/text_record.rb +1 -1
- data/lib/ruby_home/errors.rb +4 -0
- data/lib/ruby_home/factories/characteristic_factory.rb +1 -0
- data/lib/ruby_home/factories/templates/characteristic_template.rb +1 -1
- data/lib/ruby_home/factories/templates/service_template.rb +1 -1
- data/lib/ruby_home/hap/server_handler.rb +4 -13
- data/lib/ruby_home/hap/values/uint8_value.rb +11 -1
- data/lib/ruby_home/http/controllers/application_controller.rb +10 -3
- data/lib/ruby_home/http/controllers/pair_setups_controller.rb +3 -3
- data/lib/ruby_home/http/controllers/pair_verifies_controller.rb +10 -12
- data/lib/ruby_home/http/controllers/pairings_controller.rb +1 -1
- data/lib/ruby_home/http/serializers/characteristic_serializer.rb +13 -5
- data/lib/ruby_home/http/serializers/service_serializer.rb +11 -1
- data/lib/ruby_home/http/services/verify_finish_service.rb +56 -0
- data/lib/ruby_home/http/services/verify_srp_service.rb +32 -41
- data/lib/ruby_home/persistable.rb +4 -12
- data/lib/ruby_home/service.rb +3 -0
- data/lib/ruby_home/version.rb +1 -1
- data/rubyhome.gemspec +7 -7
- data/sbin/service_generator.rb +12 -2
- metadata +65 -39
- data/.travis.yml +0 -31
@@ -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
|
data/examples/outlet.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'ruby_home'
|
2
|
+
|
3
|
+
accessory_information = RubyHome::ServiceFactory.create(:accessory_information)
|
4
|
+
outlet = RubyHome::ServiceFactory.create(:outlet,
|
5
|
+
outlet_in_use: false, # required
|
6
|
+
on: false, # required
|
7
|
+
name: "occupancy sensor", # optional
|
8
|
+
)
|
9
|
+
|
10
|
+
outlet.outlet_in_use.after_update do |outlet_in_use|
|
11
|
+
if outlet_in_use
|
12
|
+
puts "outlet in use"
|
13
|
+
else
|
14
|
+
puts "outlet not in use"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
outlet.on.after_update do |on|
|
19
|
+
if on
|
20
|
+
puts "outlet is on"
|
21
|
+
sleep 1
|
22
|
+
outlet.outlet_in_use = true
|
23
|
+
else
|
24
|
+
puts "outlet is off"
|
25
|
+
sleep 1
|
26
|
+
outlet.outlet_in_use = false
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
RubyHome.run
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'ruby_home'
|
2
|
+
|
3
|
+
accessory_information = RubyHome::ServiceFactory.create(:accessory_information)
|
4
|
+
security_system = RubyHome::ServiceFactory.create(:security_system,
|
5
|
+
security_system_target_state: 0, # required
|
6
|
+
security_system_current_state: 0, # required
|
7
|
+
name: 'security system', # optional
|
8
|
+
security_system_alarm_type: 0, # optional
|
9
|
+
status_tampered: 0, # optional
|
10
|
+
status_fault: 0 # optional
|
11
|
+
)
|
12
|
+
|
13
|
+
security_system_target_state_values = {
|
14
|
+
0 => 'Stay Arm',
|
15
|
+
1 => 'Away Arm',
|
16
|
+
2 => 'Night Arm',
|
17
|
+
3 => 'Disarm'
|
18
|
+
}
|
19
|
+
security_system.security_system_target_state.after_update do |security_system_target_state|
|
20
|
+
state = security_system_target_state_values[security_system_target_state]
|
21
|
+
puts "security system security_system_target_state #{state}"
|
22
|
+
sleep 1
|
23
|
+
security_system.security_system_current_state = security_system_target_state
|
24
|
+
end
|
25
|
+
|
26
|
+
security_system_current_state_values = {
|
27
|
+
0 => 'Stay Arm',
|
28
|
+
1 => 'Away Arm',
|
29
|
+
2 => 'Night Arm',
|
30
|
+
3 => 'Disarmed',
|
31
|
+
4 => 'Alarm Triggered'
|
32
|
+
}
|
33
|
+
security_system.security_system_current_state.after_update do |security_system_current_state|
|
34
|
+
state = security_system_current_state_values[security_system_current_state]
|
35
|
+
puts "security system security_system_current_state state #{state}"
|
36
|
+
end
|
37
|
+
|
38
|
+
security_system.status_tampered.after_update do |status_tampered|
|
39
|
+
if status_tampered == 0
|
40
|
+
puts "security system status_tampered not tampered"
|
41
|
+
elsif status_tampered == 1
|
42
|
+
puts "security system status_tampered tampered"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
security_system.status_fault.after_update do |status_fault|
|
47
|
+
if status_fault == 0
|
48
|
+
puts "security system status_fault no fault"
|
49
|
+
elsif status_fault == 1
|
50
|
+
puts "security system status_fault general fault"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
RubyHome.run
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'ruby_home'
|
2
|
+
|
3
|
+
accessory_information = RubyHome::ServiceFactory.create(:accessory_information)
|
4
|
+
smoke_sensor = RubyHome::ServiceFactory.create(:smoke_sensor,
|
5
|
+
smoke_detected: 0, # required
|
6
|
+
name: "smoke 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
|
+
smoke_sensor.smoke_detected.after_update do |smoke_detected|
|
14
|
+
if smoke_detected == 0
|
15
|
+
puts "smoke sensor smoke not detected"
|
16
|
+
elsif smoke_detected == 1
|
17
|
+
puts "smoke sensor smoke detected"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
smoke_sensor.status_low_battery.after_update do |status_low_battery|
|
22
|
+
if status_low_battery == 0
|
23
|
+
puts "smoke sensor battery level normal"
|
24
|
+
elsif status_low_battery == 1
|
25
|
+
puts "smoke sensor battery level lormal"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
smoke_sensor.status_tampered.after_update do |status_tampered|
|
30
|
+
if status_tampered == 0
|
31
|
+
puts "smoke sensor status_tampered not tampered"
|
32
|
+
elsif status_tampered == 1
|
33
|
+
puts "smoke sensor status_tampered tampered"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
smoke_sensor.status_fault.after_update do |status_fault|
|
38
|
+
if status_fault == 0
|
39
|
+
puts "smoke sensor status_fault no fault"
|
40
|
+
elsif status_fault == 1
|
41
|
+
puts "smoke sensor status_fault general fault"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
smoke_sensor.status_active.after_update do |active|
|
46
|
+
if active
|
47
|
+
puts "smoke sensor is active"
|
48
|
+
else
|
49
|
+
puts "smoke sensor is inactive"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
Thread.new do
|
54
|
+
sleep 30
|
55
|
+
|
56
|
+
loop do
|
57
|
+
smoke_sensor.smoke_detected = (0..1).to_a.sample
|
58
|
+
smoke_sensor.status_low_battery = (0..1).to_a.sample
|
59
|
+
smoke_sensor.status_tampered = (0..1).to_a.sample
|
60
|
+
smoke_sensor.status_fault = (0..1).to_a.sample
|
61
|
+
smoke_sensor.status_active = [true, false].to_a.sample
|
62
|
+
|
63
|
+
sleep 10
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
RubyHome.run
|
data/examples/switch.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'ruby_home'
|
2
|
+
|
3
|
+
accessory_information = RubyHome::ServiceFactory.create(:accessory_information)
|
4
|
+
switch = RubyHome::ServiceFactory.create(:switch,
|
5
|
+
on: false, # required
|
6
|
+
name: 'switch', # optional
|
7
|
+
)
|
8
|
+
|
9
|
+
switch.on.after_update do |on|
|
10
|
+
if on
|
11
|
+
puts "switch is on"
|
12
|
+
else
|
13
|
+
puts "switch is off"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
RubyHome.run
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'ruby_home'
|
2
|
+
|
3
|
+
RubyHome.configure do |c|
|
4
|
+
c.discovery_name = 'Television'
|
5
|
+
c.category_identifier = :television
|
6
|
+
end
|
7
|
+
|
8
|
+
accessory = RubyHome::Accessory.new
|
9
|
+
|
10
|
+
RubyHome::ServiceFactory.create(:accessory_information,
|
11
|
+
accessory: accessory, # required
|
12
|
+
)
|
13
|
+
|
14
|
+
television = RubyHome::ServiceFactory.create(:television,
|
15
|
+
accessory: accessory, # required
|
16
|
+
primary: true, # required
|
17
|
+
configured_name: 'Television', # required
|
18
|
+
active: 1, # required
|
19
|
+
active_identifier: 1, # required
|
20
|
+
sleep_discovery_mode: 1, # required
|
21
|
+
remote_key: nil, # required
|
22
|
+
name: 'Television', # optional
|
23
|
+
power_mode_selection: true, # optional
|
24
|
+
picture_mode: 4, # optional
|
25
|
+
target_media_state: 0, # optional
|
26
|
+
current_media_state: 0, # optional
|
27
|
+
brightness: 100 # optional
|
28
|
+
)
|
29
|
+
|
30
|
+
television.active.after_update do |active|
|
31
|
+
if active == 0
|
32
|
+
puts "television is inactive"
|
33
|
+
else
|
34
|
+
puts "television is active"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
television.active_identifier.after_update do |active_identifier|
|
39
|
+
puts "television active input source #{active_identifier}"
|
40
|
+
end
|
41
|
+
|
42
|
+
television.remote_key.after_update do |remote_key|
|
43
|
+
puts "television remote_key #{remote_key}"
|
44
|
+
end
|
45
|
+
|
46
|
+
speaker = RubyHome::ServiceFactory.create(:television_speaker,
|
47
|
+
accessory: accessory, # required
|
48
|
+
mute: false, # required
|
49
|
+
name: "Television Volume", # optional
|
50
|
+
active: 1, # optional
|
51
|
+
volume_control_type: 1, # optional
|
52
|
+
volume_selector: 0, # optional
|
53
|
+
)
|
54
|
+
speaker.volume_selector.after_update do |volume|
|
55
|
+
if volume == 0
|
56
|
+
puts "television volume up"
|
57
|
+
else
|
58
|
+
puts "television volume down"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
sources = (1..4).map do |index|
|
63
|
+
RubyHome::ServiceFactory.create(:input_source,
|
64
|
+
accessory: accessory, # required
|
65
|
+
subtype: "source#{index}", # required
|
66
|
+
name: "Source #{index}", # required
|
67
|
+
configured_name: "Source #{index}", # required
|
68
|
+
input_source_type: 3, # required
|
69
|
+
is_configured: 1, # required
|
70
|
+
current_visibility_state: 0, # required
|
71
|
+
identifier: index, # optional
|
72
|
+
input_device_type: 1 # optional
|
73
|
+
|
74
|
+
)
|
75
|
+
end
|
76
|
+
television.linked = [speaker] + sources
|
77
|
+
|
78
|
+
RubyHome.run
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'ruby_home'
|
2
|
+
|
3
|
+
accessory_information = RubyHome::ServiceFactory.create(:accessory_information)
|
4
|
+
temperature_sensor = RubyHome::ServiceFactory.create(:temperature_sensor,
|
5
|
+
current_temperature: 30, # required
|
6
|
+
name: "temperature 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
|
+
temperature_sensor.current_temperature.after_update do |current_temperature|
|
14
|
+
puts "temperature sensor current_temperature #{current_temperature}"
|
15
|
+
end
|
16
|
+
|
17
|
+
temperature_sensor.status_low_battery.after_update do |status_low_battery|
|
18
|
+
if status_low_battery == 0
|
19
|
+
puts "temperature sensor battery level normal"
|
20
|
+
elsif status_low_battery == 1
|
21
|
+
puts "temperature sensor battery level lormal"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
temperature_sensor.status_tampered.after_update do |status_tampered|
|
26
|
+
if status_tampered == 0
|
27
|
+
puts "temperature sensor status_tampered not tampered"
|
28
|
+
elsif status_tampered == 1
|
29
|
+
puts "temperature sensor status_tampered tampered"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
temperature_sensor.status_fault.after_update do |status_fault|
|
34
|
+
if status_fault == 0
|
35
|
+
puts "temperature sensor status_fault no fault"
|
36
|
+
elsif status_fault == 1
|
37
|
+
puts "temperature sensor status_fault general fault"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
temperature_sensor.status_active.after_update do |active|
|
42
|
+
if active
|
43
|
+
puts "temperature sensor is active"
|
44
|
+
else
|
45
|
+
puts "temperature sensor is inactive"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
Thread.new do
|
50
|
+
sleep 30
|
51
|
+
|
52
|
+
loop do
|
53
|
+
temperature_sensor.current_temperature = (0..100).to_a.sample
|
54
|
+
temperature_sensor.status_low_battery = (0..1).to_a.sample
|
55
|
+
temperature_sensor.status_tampered = (0..1).to_a.sample
|
56
|
+
temperature_sensor.status_fault = (0..1).to_a.sample
|
57
|
+
temperature_sensor.status_active = [true, false].to_a.sample
|
58
|
+
|
59
|
+
sleep 10
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
RubyHome.run
|