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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cace8911ec7e8999b154e2bbcf7794ff7e9ca890b1b53fb8167091c316565bc6
4
- data.tar.gz: 9f623241d8dd6bbca8e504919af18bd2084a722f5c9ee33a701714cbd82f73c1
3
+ metadata.gz: 295a2fbbf4c858d6a72b0fded4bd051d2820a9892d1bd66145a2184fd2464720
4
+ data.tar.gz: cc9fd121510cefaebd8b01112017ae353edd0e12adb5160b7523257eb80881c6
5
5
  SHA512:
6
- metadata.gz: a4787d16e0be2c98a35d8428ef90ef83cd8462f2fa9189f6243367ef8eca006812a86c26d4c29afa5c3d09827401fb61909f5320b7e1d5ac2d4c5ab0d3e95f78
7
- data.tar.gz: 138ef40f9cf8e9c0fa8820c2611d1bf70dd4398578e40139165359d93558fe7df8205676fa660426debc49c9852d7f42d770f9a4b99cb9bf4d224bec21821384
6
+ metadata.gz: 55cd692b8e8d0ea893a43e8e9b98084a34f0fa4fe16b884b949f9d16ad9a67b92375f282a0e325f7a8a1c1a78ddea665b34df822ac859d11eae81fa3a0beabda
7
+ data.tar.gz: e0280695c0bdb55b71663550a9bc85c0e9566a1724812e7c3ca563e0ad18cf7df2e20e0d8e7e4dcc0f6e1f9dd52744b29e05a3185c276284d844e09aae0ee038
@@ -6,6 +6,8 @@ before_install:
6
6
  - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo LC_ALL=C.UTF-8 add-apt-repository -y ppa:ondrej/php; fi
7
7
  - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo apt-get update; fi
8
8
  - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo apt-get install -y libsodium-dev; fi
9
+ - if [ "$TRAVIS_OS_NAME" = "osx" ]; then brew update; fi
10
+ - if [ "$TRAVIS_OS_NAME" = "osx" ]; then brew install libsodium; fi
9
11
  install:
10
12
  - 'gem update --system'
11
13
  - 'gem --version'
@@ -24,8 +26,5 @@ addons:
24
26
  apt:
25
27
  packages:
26
28
  - libavahi-compat-libdnssd-dev
27
- homebrew:
28
- packages:
29
- - libsodium
30
29
  notifications:
31
30
  email: false
data/README.md CHANGED
@@ -58,6 +58,42 @@ end
58
58
  RubyHome.run
59
59
  ```
60
60
 
61
+ ## Examples
62
+
63
+ The following example services are available:
64
+
65
+ ### Sensors
66
+ - [Air quality sensor](https://github.com/karlentwistle/ruby_home/blob/master/examples/air_quality_sensor.rb)
67
+ - [Carbon dioxide sensor](https://github.com/karlentwistle/ruby_home/blob/master/examples/carbon_dioxide_sensor.rb)
68
+ - [Carbon monoxide sensor](https://github.com/karlentwistle/ruby_home/blob/master/examples/carbon_monoxide_sensor.rb)
69
+ - [Contact sensor](https://github.com/karlentwistle/ruby_home/blob/master/examples/contact_sensor.rb)
70
+ - [Humidity sensor](https://github.com/karlentwistle/ruby_home/blob/master/examples/humidity_sensor.rb)
71
+ - [Leak sensor](https://github.com/karlentwistle/ruby_home/blob/master/examples/leak_sensor.rb)
72
+ - [Light sensor](https://github.com/karlentwistle/ruby_home/blob/master/examples/light_sensor.rb)
73
+ - [Motion sensor](https://github.com/karlentwistle/ruby_home/blob/master/examples/motion_sensor.rb)
74
+ - [Occupancy sensor](https://github.com/karlentwistle/ruby_home/blob/master/examples/occupancy_sensor.rb)
75
+ - [Smoke sensor](https://github.com/karlentwistle/ruby_home/blob/master/examples/smoke_sensor.rb)
76
+ - [Temperature sensor](https://github.com/karlentwistle/ruby_home/blob/master/examples/temperature_sensor.rb)
77
+
78
+ ### Controlables
79
+ - [Air purifier](https://github.com/karlentwistle/ruby_home/blob/master/examples/air_purifier.rb)
80
+ - [Battery service](https://github.com/karlentwistle/ruby_home/blob/master/examples/battery_service.rb)
81
+ - [Door](https://github.com/karlentwistle/ruby_home/blob/master/examples/door.rb)
82
+ - [Fan](https://github.com/karlentwistle/ruby_home/blob/master/examples/fan.rb)
83
+ - [Fan V2](https://github.com/karlentwistle/ruby_home/blob/master/examples/fan_v2.rb)
84
+ - [Garage door opener](https://github.com/karlentwistle/ruby_home/blob/master/examples/garage_door_opener.rb)
85
+ - [Heater cooler](https://github.com/karlentwistle/ruby_home/blob/master/examples/heater_cooler.rb)
86
+ - [Humidifier dehumidifier](https://github.com/karlentwistle/ruby_home/blob/master/examples/humidifier_dehumidifier.rb)
87
+ - [Lightbulb](https://github.com/karlentwistle/ruby_home/blob/master/examples/lightbulb.rb)
88
+ - [Lock mechanism](https://github.com/karlentwistle/ruby_home/blob/master/examples/lock_mechanism.rb)
89
+ - [Outlet](https://github.com/karlentwistle/ruby_home/blob/master/examples/outlet.rb)
90
+ - [Security system](https://github.com/karlentwistle/ruby_home/blob/master/examples/security_system.rb)
91
+ - [Switch](https://github.com/karlentwistle/ruby_home/blob/master/examples/switch.rb)
92
+ - [Thermostat](https://github.com/karlentwistle/ruby_home/blob/master/examples/thermostat.rb)
93
+ - [Window](https://github.com/karlentwistle/ruby_home/blob/master/examples/window.rb)
94
+ - [Window covering](https://github.com/karlentwistle/ruby_home/blob/master/examples/window_covering.rb)
95
+
96
+
61
97
  ## Configuration
62
98
 
63
99
  The configuration options can be set by using the `configure` helper:
@@ -148,81 +184,6 @@ end
148
184
  RubyHome.run
149
185
  ```
150
186
 
151
- ## More examples
152
-
153
- ### Create a garage door opener
154
-
155
- ```ruby
156
- require 'ruby_home'
157
-
158
- accessory_information = RubyHome::ServiceFactory.create(:accessory_information)
159
- door = RubyHome::ServiceFactory.create(:garage_door_opener)
160
-
161
- door.target_door_state.after_update do |updated_value|
162
- if updated_value == 0 # open
163
- sleep 1
164
- door.current_door_state = 0
165
- elsif updated_value == 1 #closed
166
- sleep 1
167
- door.current_door_state = 1
168
- end
169
- end
170
-
171
- RubyHome.run
172
- ```
173
-
174
- ### Create a thermostat
175
-
176
- ```ruby
177
- require 'ruby_home'
178
-
179
- accessory_information = RubyHome::ServiceFactory.create(:accessory_information)
180
- thermostat = RubyHome::ServiceFactory.create(:thermostat,
181
- current_heating_cooling_state: 0, # off
182
- target_heating_cooling_state: 0, # off
183
- current_temperature: 18,
184
- target_temperature: 18,
185
- temperature_display_units: 0
186
- )
187
-
188
- thermostat.target_temperature.after_update do |updated_value|
189
- if thermostat.current_temperature < updated_value
190
- thermostat.target_heating_cooling_state = 1 # heat
191
- elsif thermostat.current_temperature > updated_value
192
- thermostat.target_heating_cooling_state = 2 # cool
193
- end
194
- end
195
-
196
- thermostat.target_heating_cooling_state.after_update do |updated_value|
197
- if updated_value == 1
198
- thermostat.current_heating_cooling_state = 1 # heat
199
- elsif updated_value == 2
200
- thermostat.current_heating_cooling_state = 2 # cool
201
- else
202
- thermostat.current_heating_cooling_state = 0 # off
203
- end
204
- end
205
-
206
- Thread.new do
207
- loop do
208
- sleep 5 # seconds
209
-
210
- puts "current_temperature: #{thermostat.current_temperature.value.to_i}"
211
- puts "target_temperature: #{thermostat.target_temperature.value.to_i}"
212
-
213
- if thermostat.target_temperature.to_i > thermostat.current_temperature.to_i
214
- thermostat.current_temperature += 1
215
- elsif thermostat.target_temperature.to_i < thermostat.current_temperature.to_i
216
- thermostat.current_temperature -= 1
217
- else
218
- thermostat.target_heating_cooling_state = 3 # auto
219
- end
220
- end
221
- end
222
-
223
- RubyHome.run
224
- ```
225
-
226
187
  ## Development
227
188
 
228
189
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -0,0 +1,67 @@
1
+ require 'ruby_home'
2
+
3
+ accessory_information = RubyHome::ServiceFactory.create(:accessory_information)
4
+ air_purifier = RubyHome::ServiceFactory.create(:air_purifier,
5
+ target_air_purifier_state: 0, # required
6
+ current_air_purifier_state: 0, # required
7
+ active: 0, # required
8
+ name: "air purifier", # optional
9
+ rotation_speed: 0, # optional
10
+ swing_mode: 1, # optional
11
+ lock_physical_controls: 0, # optional
12
+ )
13
+
14
+ target_air_purifier_state_values = {
15
+ 0 => 'Manual',
16
+ 1 => 'Auto',
17
+ }
18
+ air_purifier.target_air_purifier_state.after_update do |target_air_purifier_state|
19
+ state = target_air_purifier_state_values[target_air_purifier_state]
20
+ puts "air purifier target air purifier state #{state}"
21
+ end
22
+
23
+ current_air_purifier_state_values = {
24
+ 0 => 'Inactive',
25
+ 1 => 'Idle',
26
+ 2 => 'Purifying Air',
27
+ }
28
+ air_purifier.current_air_purifier_state.after_update do |current_air_purifier_state|
29
+ state = current_air_purifier_state_values[current_air_purifier_state]
30
+ puts "air purifier current air purifier state is #{state}"
31
+ end
32
+
33
+ air_purifier.active.after_update do |active|
34
+ if active == 0
35
+ puts "air purifier is inactive"
36
+ air_purifier.target_air_purifier_state = 0
37
+ sleep 1
38
+ air_purifier.current_air_purifier_state = 0
39
+ elsif active == 1
40
+ puts "air purifier is active"
41
+ air_purifier.target_air_purifier_state = 1
42
+ sleep 1
43
+ air_purifier.current_air_purifier_state = 2
44
+ end
45
+ end
46
+
47
+ air_purifier.swing_mode.after_update do |swing_mode|
48
+ if swing_mode == 0
49
+ puts "air purifier swing is disabled"
50
+ elsif swing_mode == 1
51
+ puts "air purifier swing is enabled"
52
+ end
53
+ end
54
+
55
+ air_purifier.rotation_speed.after_update do |rotation_speed|
56
+ puts "air_purifier is spinning at #{rotation_speed} speed"
57
+ end
58
+
59
+ air_purifier.lock_physical_controls.after_update do |lock_physical_controls|
60
+ if lock_physical_controls == 0
61
+ puts "air purifier control lock disabled"
62
+ elsif lock_physical_controls == 1
63
+ puts "air purifier control lock enabled"
64
+ end
65
+ end
66
+
67
+ RubyHome.run
@@ -0,0 +1,120 @@
1
+ require 'ruby_home'
2
+
3
+ accessory_information = RubyHome::ServiceFactory.create(:accessory_information)
4
+ air_quality_sensor = RubyHome::ServiceFactory.create(:air_quality_sensor,
5
+ air_quality: 0, # required
6
+ name: "air quality sensor", # optional
7
+ carbon_dioxide_level: 0, # optional
8
+ carbon_monoxide_level: 0, # optional
9
+ voc_density: 0, # optional
10
+ pm10_density: 0, # optional
11
+ pm2_5_density: 0, # optional
12
+ sulphur_dioxide_density: 0, # optional
13
+ nitrogen_dioxide_density: 0, # optional
14
+ ozone_density: 0, # optional
15
+ status_low_battery: 0, # optional
16
+ status_tampered: 0, # optional
17
+ status_fault: 0, # optional
18
+ status_active: true # optional
19
+ )
20
+
21
+ air_quality_values = {
22
+ 0 => 'Unknown',
23
+ 1 => 'Excellent',
24
+ 2 => 'Good',
25
+ 3 => 'Fair',
26
+ 4 => 'Inferior',
27
+ 5 => 'Poor'
28
+ }
29
+ air_quality_sensor.air_quality.after_update do |air_quality|
30
+ state = air_quality_values[air_quality]
31
+ puts "air quality sensor air quality is #{state}"
32
+ end
33
+
34
+ air_quality_sensor.carbon_dioxide_level.after_update do |carbon_dioxide_level|
35
+ puts "air quality sensor carbon_dioxide_level #{carbon_dioxide_level}"
36
+ end
37
+
38
+ air_quality_sensor.carbon_monoxide_level.after_update do |carbon_monoxide_level|
39
+ puts "air quality sensor carbon_monoxide_level #{carbon_monoxide_level}"
40
+ end
41
+
42
+ air_quality_sensor.voc_density.after_update do |voc_density|
43
+ puts "air quality sensor voc_density #{voc_density}"
44
+ end
45
+
46
+ air_quality_sensor.pm10_density.after_update do |pm10_density|
47
+ puts "air quality sensor pm10_density #{pm10_density}"
48
+ end
49
+
50
+ air_quality_sensor.pm2_5_density.after_update do |pm2_5_density|
51
+ puts "air quality sensor pm2_5_density #{pm2_5_density}"
52
+ end
53
+
54
+ air_quality_sensor.sulphur_dioxide_density.after_update do |sulphur_dioxide_density|
55
+ puts "air quality sensor sulphur_dioxide_density #{sulphur_dioxide_density}"
56
+ end
57
+
58
+ air_quality_sensor.nitrogen_dioxide_density.after_update do |nitrogen_dioxide_density|
59
+ puts "air quality sensor nitrogen_dioxide_density #{nitrogen_dioxide_density}"
60
+ end
61
+
62
+ air_quality_sensor.ozone_density.after_update do |ozone_density|
63
+ puts "air quality sensor ozone_density #{ozone_density}"
64
+ end
65
+
66
+ air_quality_sensor.status_low_battery.after_update do |status_low_battery|
67
+ if status_low_battery == 0
68
+ puts "air quality sensor battery level normal"
69
+ elsif status_low_battery == 1
70
+ puts "air quality sensor battery level lormal"
71
+ end
72
+ end
73
+
74
+ air_quality_sensor.status_tampered.after_update do |status_tampered|
75
+ if status_tampered == 0
76
+ puts "air quality sensor status_tampered not tampered"
77
+ elsif status_tampered == 1
78
+ puts "air quality sensor status_tampered tampered"
79
+ end
80
+ end
81
+
82
+ air_quality_sensor.status_fault.after_update do |status_fault|
83
+ if status_fault == 0
84
+ puts "air quality sensor status_fault no fault"
85
+ elsif status_fault == 1
86
+ puts "air quality sensor status_fault general fault"
87
+ end
88
+ end
89
+
90
+ air_quality_sensor.status_active.after_update do |active|
91
+ if active
92
+ puts "air quality sensor is active"
93
+ else
94
+ puts "air quality sensor is inactive"
95
+ end
96
+ end
97
+
98
+ Thread.new do
99
+ sleep 30
100
+
101
+ loop do
102
+ air_quality_sensor.air_quality = air_quality_values.keys.sample
103
+ air_quality_sensor.carbon_dioxide_level = (0..100000).to_a.sample
104
+ air_quality_sensor.carbon_monoxide_level = (0..100).to_a.sample
105
+ air_quality_sensor.voc_density = (0..1000).to_a.sample
106
+ air_quality_sensor.pm10_density = (0..1000).to_a.sample
107
+ air_quality_sensor.pm2_5_density = (0..1000).to_a.sample
108
+ air_quality_sensor.sulphur_dioxide_density = (0..1000).to_a.sample
109
+ air_quality_sensor.nitrogen_dioxide_density = (0..1000).to_a.sample
110
+ air_quality_sensor.ozone_density = (0..1000).to_a.sample
111
+ air_quality_sensor.status_low_battery = (0..1).to_a.sample
112
+ air_quality_sensor.status_tampered = (0..1).to_a.sample
113
+ air_quality_sensor.status_fault = (0..1).to_a.sample
114
+ air_quality_sensor.status_active = [true, false].to_a.sample
115
+
116
+ sleep 10
117
+ end
118
+ end
119
+
120
+ RubyHome.run
@@ -0,0 +1,59 @@
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
+
11
+ battery_service.status_low_battery.after_update do |status_low_battery|
12
+ if status_low_battery == 0
13
+ puts "battery service status low battery is battery level normal"
14
+ elsif status_low_battery == 1
15
+ puts "battery service status low battery is battery level low"
16
+ end
17
+ end
18
+
19
+ battery_service.charging_state.after_update do |charging_state|
20
+ if charging_state == 0
21
+ puts "battery service charging state is not charging"
22
+ elsif charging_state == 1
23
+ puts "battery service charging state is charging"
24
+ elsif charging_state == 2
25
+ puts "battery service charging state is not chargeable"
26
+ end
27
+ end
28
+
29
+ battery_service.battery_level.after_update do |battery_level|
30
+ puts "battery service battery level #{battery_level}"
31
+
32
+ if battery_level < 10 && battery_service.status_low_battery != 1
33
+ battery_service.status_low_battery = 1
34
+ end
35
+
36
+ if battery_level > 11 && battery_service.status_low_battery != 0
37
+ battery_service.status_low_battery = 0
38
+ end
39
+ end
40
+
41
+ Thread.new do
42
+ sleep 30
43
+
44
+ loop do
45
+ battery_service.charging_state = 0
46
+ while battery_service.battery_level > 0
47
+ battery_service.battery_level -= 1
48
+ sleep 1
49
+ end
50
+
51
+ battery_service.charging_state = 1
52
+ while battery_service.battery_level < 101
53
+ battery_service.battery_level += 1
54
+ sleep 1
55
+ end
56
+ end
57
+ end
58
+
59
+ RubyHome.run
@@ -0,0 +1,79 @@
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
+
15
+ carbon_dioxide_sensor.carbon_dioxide_detected.after_update do |carbon_dioxide_detected|
16
+ if carbon_dioxide_detected == 0
17
+ puts "carbon dioxide sensor carbon dioxide detected CO2 levels normal"
18
+ elsif carbon_dioxide_detected == 1
19
+ puts "carbon dioxide sensor carbon dioxide detected CO2 levels abnormal"
20
+ end
21
+ end
22
+
23
+ carbon_dioxide_sensor.carbon_dioxide_peak_level.after_update do |carbon_dioxide_peak_level|
24
+ puts "carbon dioxide sensor carbon_dioxide_peak_level #{carbon_dioxide_peak_level}"
25
+ end
26
+
27
+ carbon_dioxide_sensor.carbon_dioxide_level.after_update do |carbon_dioxide_level|
28
+ puts "carbon dioxide sensor carbon_dioxide_level #{carbon_dioxide_level}"
29
+ end
30
+
31
+ carbon_dioxide_sensor.status_tampered.after_update do |status_tampered|
32
+ if status_tampered == 0
33
+ puts "carbon dioxide sensor status_tampered not tampered"
34
+ elsif status_tampered == 1
35
+ puts "carbon dioxide sensor status_tampered tampered"
36
+ end
37
+ end
38
+
39
+ carbon_dioxide_sensor.status_low_battery.after_update do |status_low_battery|
40
+ if status_low_battery == 0
41
+ puts "carbon dioxide sensor low battery is battery level normal"
42
+ elsif status_low_battery == 1
43
+ puts "carbon dioxide sensor low battery is battery level low"
44
+ end
45
+ end
46
+
47
+ carbon_dioxide_sensor.status_fault.after_update do |status_fault|
48
+ if status_fault == 0
49
+ puts "carbon dioxide sensor status_fault no fault"
50
+ elsif status_fault == 1
51
+ puts "carbon dioxide sensor status_fault general fault"
52
+ end
53
+ end
54
+
55
+ carbon_dioxide_sensor.status_active.after_update do |active|
56
+ if active
57
+ puts "carbon dioxide sensor is active"
58
+ else
59
+ puts "carbon dioxide sensor is inactive"
60
+ end
61
+ end
62
+
63
+ Thread.new do
64
+ sleep 30
65
+
66
+ loop do
67
+ carbon_dioxide_sensor.carbon_dioxide_detected = (0..1).to_a.sample
68
+ carbon_dioxide_sensor.carbon_dioxide_peak_level = (0..100000).to_a.sample
69
+ carbon_dioxide_sensor.carbon_dioxide_level = (0..100000).to_a.sample
70
+ carbon_dioxide_sensor.status_tampered = (0..1).to_a.sample
71
+ carbon_dioxide_sensor.status_low_battery = (0..1).to_a.sample
72
+ carbon_dioxide_sensor.status_fault = (0..1).to_a.sample
73
+ carbon_dioxide_sensor.status_active = [true, false].to_a.sample
74
+
75
+ sleep 10
76
+ end
77
+ end
78
+
79
+ RubyHome.run