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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: faee051d71617c37bbbaf0274d1469db94770d0623bc415a7f8448ff7ce4408b
|
4
|
+
data.tar.gz: c207e5bb1bec2c07d86183e912c21a3f8f4e8c3c4c27b639cd955a9a3d21b887
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 601d7ef1d41989e34ae7ba3a336dcf3b36c93a693a0bfb8d998afc2aae7e9bcf243c65406eab992269f03e627ef71f0b01be904969b37e063c2472f4b438a022
|
7
|
+
data.tar.gz: 7f5ee6ca44cabbdbf316e1a21c388ba09173e4a69853a8505d80249bd4602ee9f0cf609c8a6755fc6b6337c540d4a712573f1d4984b1435dd008ed04a77d8b49
|
@@ -0,0 +1,41 @@
|
|
1
|
+
name: Tests
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [ master ]
|
6
|
+
pull_request:
|
7
|
+
branches: [ master ]
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
ubuntu:
|
11
|
+
runs-on: ubuntu-latest
|
12
|
+
strategy:
|
13
|
+
matrix:
|
14
|
+
ruby-version: [3.0, 2.7, 2.6, 2.5]
|
15
|
+
steps:
|
16
|
+
- name: Install libdnssd
|
17
|
+
run: sudo apt-get install libavahi-compat-libdnssd-dev
|
18
|
+
- uses: actions/checkout@v2
|
19
|
+
- name: Set up Ruby ${{ matrix.ruby-version }}
|
20
|
+
uses: ruby/setup-ruby@v1
|
21
|
+
with:
|
22
|
+
ruby-version: ${{ matrix.ruby-version }}
|
23
|
+
- name: Install dependencies
|
24
|
+
run: bundle
|
25
|
+
- name: Run tests
|
26
|
+
run: bundle exec rake
|
27
|
+
mac:
|
28
|
+
runs-on: macos-latest
|
29
|
+
strategy:
|
30
|
+
matrix:
|
31
|
+
ruby-version: [3.0, 2.7, 2.6, 2.5]
|
32
|
+
steps:
|
33
|
+
- uses: actions/checkout@v2
|
34
|
+
- name: Set up Ruby ${{ matrix.ruby-version }}
|
35
|
+
uses: ruby/setup-ruby@v1
|
36
|
+
with:
|
37
|
+
ruby-version: ${{ matrix.ruby-version }}
|
38
|
+
- name: Install dependencies
|
39
|
+
run: bundle
|
40
|
+
- name: Run tests
|
41
|
+
run: bundle exec rake
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# ruby_home Changelog
|
2
|
+
|
3
|
+
## [v0.2.5](https://github.com/karlentwistle/ruby_home/releases/tag/v0.2.5) (2021-01-22)
|
4
|
+
|
5
|
+
### Features
|
6
|
+
|
7
|
+
* Added support for television service and characteristics (#100, @johndbritton, @getowic)
|
8
|
+
* category_identifier can now be configured (#100, @getowic)
|
9
|
+
|
10
|
+
|
11
|
+
### Fixes
|
12
|
+
|
13
|
+
* Fix Ruby 3.0 LoadError (#102, @karlentwistle)
|
data/README.md
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
[![Maintainability](https://api.codeclimate.com/v1/badges/c81f4cfdf5c13d716487/maintainability)](https://codeclimate.com/github/karlentwistle/ruby_home/maintainability)
|
2
|
-
[![Build Status](https://travis-ci.org/karlentwistle/ruby_home.svg?branch=master)](https://travis-ci.org/karlentwistle/ruby_home)
|
3
2
|
|
4
3
|
# ruby_home
|
5
4
|
|
@@ -17,7 +16,7 @@ For OS X users, libsodium is available via homebrew and can be installed with:
|
|
17
16
|
|
18
17
|
brew install libsodium
|
19
18
|
|
20
|
-
For Debian users, libsodium is available
|
19
|
+
For Debian users, libsodium is available via apt:
|
21
20
|
|
22
21
|
sudo apt-get install libsodium-dev
|
23
22
|
|
@@ -33,13 +32,13 @@ And then execute:
|
|
33
32
|
|
34
33
|
$ bundle
|
35
34
|
|
36
|
-
Or install it yourself
|
35
|
+
Or install it yourself with:
|
37
36
|
|
38
37
|
$ gem install ruby_home
|
39
38
|
|
40
39
|
## Basic usage
|
41
40
|
|
42
|
-
Create a fan with an on/off switch
|
41
|
+
Create a fan with an on/off switch:
|
43
42
|
|
44
43
|
```ruby
|
45
44
|
require 'ruby_home'
|
@@ -58,9 +57,46 @@ end
|
|
58
57
|
RubyHome.run
|
59
58
|
```
|
60
59
|
|
60
|
+
## Examples
|
61
|
+
|
62
|
+
The following example services are available:
|
63
|
+
|
64
|
+
### Sensors
|
65
|
+
- [Air quality sensor](https://github.com/karlentwistle/ruby_home/blob/master/examples/air_quality_sensor.rb)
|
66
|
+
- [Carbon dioxide sensor](https://github.com/karlentwistle/ruby_home/blob/master/examples/carbon_dioxide_sensor.rb)
|
67
|
+
- [Carbon monoxide sensor](https://github.com/karlentwistle/ruby_home/blob/master/examples/carbon_monoxide_sensor.rb)
|
68
|
+
- [Contact sensor](https://github.com/karlentwistle/ruby_home/blob/master/examples/contact_sensor.rb)
|
69
|
+
- [Humidity sensor](https://github.com/karlentwistle/ruby_home/blob/master/examples/humidity_sensor.rb)
|
70
|
+
- [Leak sensor](https://github.com/karlentwistle/ruby_home/blob/master/examples/leak_sensor.rb)
|
71
|
+
- [Light sensor](https://github.com/karlentwistle/ruby_home/blob/master/examples/light_sensor.rb)
|
72
|
+
- [Motion sensor](https://github.com/karlentwistle/ruby_home/blob/master/examples/motion_sensor.rb)
|
73
|
+
- [Occupancy sensor](https://github.com/karlentwistle/ruby_home/blob/master/examples/occupancy_sensor.rb)
|
74
|
+
- [Smoke sensor](https://github.com/karlentwistle/ruby_home/blob/master/examples/smoke_sensor.rb)
|
75
|
+
- [Temperature sensor](https://github.com/karlentwistle/ruby_home/blob/master/examples/temperature_sensor.rb)
|
76
|
+
|
77
|
+
### Controlables
|
78
|
+
- [Air purifier](https://github.com/karlentwistle/ruby_home/blob/master/examples/air_purifier.rb)
|
79
|
+
- [Battery service](https://github.com/karlentwistle/ruby_home/blob/master/examples/battery_service.rb)
|
80
|
+
- [Door](https://github.com/karlentwistle/ruby_home/blob/master/examples/door.rb)
|
81
|
+
- [Fan](https://github.com/karlentwistle/ruby_home/blob/master/examples/fan.rb)
|
82
|
+
- [Fan V2](https://github.com/karlentwistle/ruby_home/blob/master/examples/fan_v2.rb)
|
83
|
+
- [Garage door opener](https://github.com/karlentwistle/ruby_home/blob/master/examples/garage_door_opener.rb)
|
84
|
+
- [Heater cooler](https://github.com/karlentwistle/ruby_home/blob/master/examples/heater_cooler.rb)
|
85
|
+
- [Humidifier dehumidifier](https://github.com/karlentwistle/ruby_home/blob/master/examples/humidifier_dehumidifier.rb)
|
86
|
+
- [Lightbulb](https://github.com/karlentwistle/ruby_home/blob/master/examples/lightbulb.rb)
|
87
|
+
- [Lock mechanism](https://github.com/karlentwistle/ruby_home/blob/master/examples/lock_mechanism.rb)
|
88
|
+
- [Outlet](https://github.com/karlentwistle/ruby_home/blob/master/examples/outlet.rb)
|
89
|
+
- [Security system](https://github.com/karlentwistle/ruby_home/blob/master/examples/security_system.rb)
|
90
|
+
- [Switch](https://github.com/karlentwistle/ruby_home/blob/master/examples/switch.rb)
|
91
|
+
- [Television](https://github.com/karlentwistle/ruby_home/blob/master/examples/television.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
|
-
The configuration options can be set by using the `configure` helper
|
99
|
+
The configuration options can be set by using the `configure` helper:
|
64
100
|
|
65
101
|
```ruby
|
66
102
|
RubyHome.configure do |c|
|
@@ -74,9 +110,10 @@ The following is the full list of available configuration options:
|
|
74
110
|
|---|---|---|---|---|
|
75
111
|
| `discovery_name` | The user-visible name of the accessory | `"RubyHome"` | `"My Home"` | String |
|
76
112
|
| `model_name` | The model name of the accessory | `"RubyHome"` | `"Device1,1"` | String |
|
77
|
-
| `password` | Used for pairing must conform to the format XXX-XX-XXX where each X is a 0-9 digit and dashes are required | Randomly generated | `"101-48-005"` | String |
|
113
|
+
| `password` | Used for pairing, must conform to the format XXX-XX-XXX where each X is a 0-9 digit and dashes are required | Randomly generated | `"101-48-005"` | String |
|
78
114
|
| `host` | The hostname or IP address of the interface to listen on | `"0.0.0.0"` | `"192.168.0.2"` | String |
|
79
115
|
| `port` | The port that should be used when starting the built-in web server | `4567` | `8080` | Integer |
|
116
|
+
| `category_identifier` | Indicates the [category](https://github.com/karlentwistle/ruby_home/blob/master/lib/ruby_home/config/categories.yml) that best describes the primary function of the accessory. | `:bridge` | `:fan` | Symbol |
|
80
117
|
|
81
118
|
## Customization
|
82
119
|
|
@@ -90,7 +127,8 @@ accessory_information = RubyHome::ServiceFactory.create(:accessory_information,
|
|
90
127
|
manufacturer: 'Fake Company',
|
91
128
|
model: 'BSB001',
|
92
129
|
name: 'Kickass fan bridge',
|
93
|
-
serial_number: 'AB1-UK-A123456'
|
130
|
+
serial_number: 'AB1-UK-A123456',
|
131
|
+
category_identifier: :fan
|
94
132
|
)
|
95
133
|
|
96
134
|
fan = RubyHome::ServiceFactory.create(:fan,
|
@@ -117,9 +155,9 @@ RubyHome.run
|
|
117
155
|
|
118
156
|
## Updating a characteristics value
|
119
157
|
|
120
|
-
If you have a service with characteristics that can be changed outside of Ruby Home
|
158
|
+
If you have a service with characteristics that can be changed outside of Ruby Home, you'll want to keep Ruby Home in sync with these modifications. Otherwise, the characteristics current value won't correspond with reality. The simplest way to do this is a background job that periodically polls the devices current status and updates the corresponding characteristics value if it's changed.
|
121
159
|
|
122
|
-
Given a fan which can be switched on / off with a remote control
|
160
|
+
Given a fan which can be switched on / off with a remote control, which has a JSON API endpoint at http://example.org/fan_status.json that returns its current status `{ "on": true }` or `{ "on": false }`, we can spawn a thread that keeps polling the fans current status and if it's changed update our fan service "on" characteristic.
|
123
161
|
|
124
162
|
```ruby
|
125
163
|
require 'json'
|
@@ -148,81 +186,6 @@ end
|
|
148
186
|
RubyHome.run
|
149
187
|
```
|
150
188
|
|
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
189
|
## Development
|
227
190
|
|
228
191
|
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
|