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.
Files changed (106) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/tests.yml +41 -0
  3. data/.gitignore +2 -2
  4. data/.rubocop.yml +2 -9
  5. data/.standard.yml +3 -0
  6. data/CHANGELOG.md +18 -0
  7. data/Gemfile +2 -2
  8. data/README.md +40 -77
  9. data/Rakefile +4 -4
  10. data/examples/air_purifier.rb +66 -0
  11. data/examples/air_quality_sensor.rb +119 -0
  12. data/examples/battery_service.rb +58 -0
  13. data/examples/carbon_dioxide_sensor.rb +78 -0
  14. data/examples/carbon_monoxide_sensor.rb +78 -0
  15. data/examples/contact_sensor.rb +66 -0
  16. data/examples/door.rb +48 -0
  17. data/examples/fan.rb +30 -0
  18. data/examples/fan_v2.rb +68 -0
  19. data/examples/garage_door_opener.rb +71 -0
  20. data/examples/heater_cooler.rb +92 -0
  21. data/examples/humidifier_dehumidifier.rb +88 -0
  22. data/examples/humidity_sensor.rb +62 -0
  23. data/examples/leak_sensor.rb +66 -0
  24. data/examples/light_sensor.rb +64 -0
  25. data/examples/lightbulb.rb +31 -0
  26. data/examples/lock_mechanism.rb +34 -0
  27. data/examples/motion_sensor.rb +66 -0
  28. data/examples/occupancy_sensor.rb +66 -0
  29. data/examples/outlet.rb +29 -0
  30. data/examples/security_system.rb +53 -0
  31. data/examples/smoke_sensor.rb +66 -0
  32. data/examples/switch.rb +16 -0
  33. data/examples/television.rb +73 -0
  34. data/examples/temperature_sensor.rb +62 -0
  35. data/examples/thermostat.rb +113 -0
  36. data/examples/window.rb +48 -0
  37. data/examples/window_covering.rb +72 -0
  38. data/lib/ruby_home.rb +21 -22
  39. data/lib/ruby_home/accessory.rb +1 -1
  40. data/lib/ruby_home/accessory_collection.rb +6 -6
  41. data/lib/ruby_home/accessory_info.rb +18 -18
  42. data/lib/ruby_home/characteristic.rb +13 -7
  43. data/lib/ruby_home/characteristic_collection.rb +13 -13
  44. data/lib/ruby_home/config/categories.yml +39 -0
  45. data/lib/ruby_home/config/characteristics.yml +190 -319
  46. data/lib/ruby_home/config/manual_characteristics.yml +278 -0
  47. data/lib/ruby_home/config/manual_services.yml +45 -0
  48. data/lib/ruby_home/config/services.yml +338 -304
  49. data/lib/ruby_home/configuration.rb +21 -2
  50. data/lib/ruby_home/device_id.rb +3 -3
  51. data/lib/ruby_home/dns/service.rb +4 -6
  52. data/lib/ruby_home/dns/text_record.rb +10 -10
  53. data/lib/ruby_home/errors.rb +1 -0
  54. data/lib/ruby_home/factories/characteristic_factory.rb +38 -37
  55. data/lib/ruby_home/factories/service_factory.rb +72 -72
  56. data/lib/ruby_home/factories/templates/characteristic_template.rb +6 -6
  57. data/lib/ruby_home/factories/templates/service_template.rb +12 -11
  58. data/lib/ruby_home/hap/crypto/chacha20poly1305.rb +2 -2
  59. data/lib/ruby_home/hap/crypto/hkdf.rb +4 -4
  60. data/lib/ruby_home/hap/crypto/session_key.rb +7 -7
  61. data/lib/ruby_home/hap/decrypter.rb +8 -8
  62. data/lib/ruby_home/hap/encrypter.rb +5 -6
  63. data/lib/ruby_home/hap/ev_response.rb +17 -17
  64. data/lib/ruby_home/hap/hap_request.rb +1 -1
  65. data/lib/ruby_home/hap/server.rb +4 -4
  66. data/lib/ruby_home/hap/server_handler.rb +8 -10
  67. data/lib/ruby_home/hap/session.rb +22 -22
  68. data/lib/ruby_home/hap/values/base_value.rb +3 -3
  69. data/lib/ruby_home/hap/values/bool_value.rb +4 -4
  70. data/lib/ruby_home/hap/values/float_value.rb +4 -4
  71. data/lib/ruby_home/hap/values/identify_value.rb +1 -1
  72. data/lib/ruby_home/hap/values/int32_value.rb +4 -4
  73. data/lib/ruby_home/hap/values/null_value.rb +1 -1
  74. data/lib/ruby_home/hap/values/string_value.rb +11 -11
  75. data/lib/ruby_home/hap/values/uint32_value.rb +5 -5
  76. data/lib/ruby_home/hap/values/uint8_value.rb +14 -14
  77. data/lib/ruby_home/hex_helper.rb +3 -3
  78. data/lib/ruby_home/http/application.rb +7 -7
  79. data/lib/ruby_home/http/controllers/accessories_controller.rb +3 -3
  80. data/lib/ruby_home/http/controllers/application_controller.rb +6 -6
  81. data/lib/ruby_home/http/controllers/characteristics_controller.rb +29 -29
  82. data/lib/ruby_home/http/controllers/identify_controller.rb +10 -10
  83. data/lib/ruby_home/http/controllers/pair_setups_controller.rb +19 -19
  84. data/lib/ruby_home/http/controllers/pair_verifies_controller.rb +9 -9
  85. data/lib/ruby_home/http/controllers/pairings_controller.rb +6 -6
  86. data/lib/ruby_home/http/serializers/accessory_serializer.rb +5 -5
  87. data/lib/ruby_home/http/serializers/characteristic_serializer.rb +27 -19
  88. data/lib/ruby_home/http/serializers/characteristic_value_serializer.rb +5 -5
  89. data/lib/ruby_home/http/serializers/object_serializer.rb +1 -1
  90. data/lib/ruby_home/http/serializers/service_serializer.rb +19 -9
  91. data/lib/ruby_home/http/serializers/uuid_helper.rb +2 -2
  92. data/lib/ruby_home/http/services/session_notifier.rb +8 -8
  93. data/lib/ruby_home/http/services/start_srp_service.rb +3 -3
  94. data/lib/ruby_home/http/services/verify_finish_service.rb +22 -22
  95. data/lib/ruby_home/http/services/verify_srp_service.rb +22 -22
  96. data/lib/ruby_home/identifier_cache.rb +4 -5
  97. data/lib/ruby_home/password.rb +14 -14
  98. data/lib/ruby_home/persistable.rb +19 -12
  99. data/lib/ruby_home/service.rb +5 -2
  100. data/lib/ruby_home/service_collection.rb +1 -1
  101. data/lib/ruby_home/version.rb +1 -1
  102. data/rubyhome.gemspec +31 -31
  103. data/sbin/characteristic_generator.rb +22 -24
  104. data/sbin/service_generator.rb +38 -19
  105. metadata +85 -44
  106. data/.travis.yml +0 -31
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cace8911ec7e8999b154e2bbcf7794ff7e9ca890b1b53fb8167091c316565bc6
4
- data.tar.gz: 9f623241d8dd6bbca8e504919af18bd2084a722f5c9ee33a701714cbd82f73c1
3
+ metadata.gz: 01126dd521e4351b6b7b801bfbb2e4bfd9ab6e19d47ce1715dc9c964ea5dfeca
4
+ data.tar.gz: be5d09f37ec55495c374778c4e2c0baea87edd16ea791ff2f9ca65a90a0666ad
5
5
  SHA512:
6
- metadata.gz: a4787d16e0be2c98a35d8428ef90ef83cd8462f2fa9189f6243367ef8eca006812a86c26d4c29afa5c3d09827401fb61909f5320b7e1d5ac2d4c5ab0d3e95f78
7
- data.tar.gz: 138ef40f9cf8e9c0fa8820c2611d1bf70dd4398578e40139165359d93558fe7df8205676fa660426debc49c9852d7f42d770f9a4b99cb9bf4d224bec21821384
6
+ metadata.gz: 96fb624e38e24b0b6fc709f6df2f7dd048b2514210f1cd4b43e91a36c2de1bc0f8de22848bb106b44ab7e17f3efbfcab7a3ad839275a819391c745e890e299ea
7
+ data.tar.gz: bbbc772b8da1669307f63753f23ad07f1ada6e9f675e0a02e174f9653a94f67245cd13564c9d7e57f163fa2ebc1cb4526071df2ef5dc7763466146f446bfb852
@@ -0,0 +1,41 @@
1
+ name: Tests
2
+
3
+ on:
4
+ push:
5
+ branches: [ main ]
6
+ pull_request:
7
+ branches: [ main ]
8
+
9
+ jobs:
10
+ ubuntu:
11
+ runs-on: ubuntu-latest
12
+ strategy:
13
+ matrix:
14
+ ruby-version: [3.0, 2.7, 2.6]
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]
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/.gitignore CHANGED
@@ -1,14 +1,14 @@
1
1
  .byebug_history
2
2
  .rspec_status
3
+ .ruby-version
3
4
  /.bundle/
5
+ /.rubocop-*
4
6
  /.yardoc
5
7
  /_yardoc/
6
8
  /coverage/
7
9
  /doc/
8
10
  /pkg/
9
11
  /spec/reports/
10
- /tmp/
11
12
  Gemfile.lock
12
13
  accessory_info.yml
13
14
  identifier_cache.yml
14
- .ruby-version
data/.rubocop.yml CHANGED
@@ -1,9 +1,2 @@
1
- Style:
2
- TrailingCommaInLiteral:
3
- Enabled: false
4
- Documentation:
5
- Enabled: false
6
- FrozenStringLiteralComment:
7
- Enabled: false
8
- IndentationConsistency:
9
- AllowProtectedAndPrivateMethodsBeIndented: true
1
+ inherit_from:
2
+ - https://raw.githubusercontent.com/testdouble/standard/master/config/base.yml
data/.standard.yml ADDED
@@ -0,0 +1,3 @@
1
+ ignore:
2
+ - 'examples/*':
3
+ - Lint/UselessAssignment
data/CHANGELOG.md ADDED
@@ -0,0 +1,18 @@
1
+ # ruby_home Changelog
2
+
3
+ ## [v0.2.6](https://github.com/karlentwistle/ruby_home/releases/tag/v0.2.6) (2021-05-25)
4
+
5
+ ### Features
6
+
7
+ * Introduce in memory cache for identifier_cache and accessory_info to improve read performance
8
+
9
+ ## [v0.2.5](https://github.com/karlentwistle/ruby_home/releases/tag/v0.2.5) (2021-01-22)
10
+
11
+ ### Features
12
+
13
+ * Added support for television service and characteristics (#100, @johndbritton, @getowic)
14
+ * category_identifier can now be configured (#100, @getowic)
15
+
16
+ ### Fixes
17
+
18
+ * Fix Ruby 3.0 LoadError (#102, @karlentwistle)
data/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
- source 'https://rubygems.org'
1
+ source "https://rubygems.org"
2
2
 
3
- git_source(:github) {|repo_name| 'https://github.com/#{repo_name}' }
3
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
4
 
5
5
  # Specify your gem's dependencies in ruby_home.gemspec
6
6
  gemspec
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
 
@@ -58,6 +57,43 @@ 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
99
  The configuration options can be set by using the `configure` helper:
@@ -77,6 +113,7 @@ The following is the full list of available configuration options:
77
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,
@@ -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.
data/Rakefile CHANGED
@@ -1,7 +1,7 @@
1
- require 'bundler/gem_tasks'
2
- require 'rspec/core/rake_task'
3
- require_relative 'lib/ruby_home'
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+ require_relative "lib/ruby_home"
4
4
 
5
5
  RSpec::Core::RakeTask.new(:spec)
6
6
 
7
- task :default => :spec
7
+ task default: :spec
@@ -0,0 +1,66 @@
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
+ target_air_purifier_state_values = {
14
+ 0 => "Manual",
15
+ 1 => "Auto"
16
+ }
17
+ air_purifier.target_air_purifier_state.after_update do |target_air_purifier_state|
18
+ state = target_air_purifier_state_values[target_air_purifier_state]
19
+ puts "air purifier target air purifier state #{state}"
20
+ end
21
+
22
+ current_air_purifier_state_values = {
23
+ 0 => "Inactive",
24
+ 1 => "Idle",
25
+ 2 => "Purifying Air"
26
+ }
27
+ air_purifier.current_air_purifier_state.after_update do |current_air_purifier_state|
28
+ state = current_air_purifier_state_values[current_air_purifier_state]
29
+ puts "air purifier current air purifier state is #{state}"
30
+ end
31
+
32
+ air_purifier.active.after_update do |active|
33
+ if active == 0
34
+ puts "air purifier is inactive"
35
+ air_purifier.target_air_purifier_state = 0
36
+ sleep 1
37
+ air_purifier.current_air_purifier_state = 0
38
+ elsif active == 1
39
+ puts "air purifier is active"
40
+ air_purifier.target_air_purifier_state = 1
41
+ sleep 1
42
+ air_purifier.current_air_purifier_state = 2
43
+ end
44
+ end
45
+
46
+ air_purifier.swing_mode.after_update do |swing_mode|
47
+ if swing_mode == 0
48
+ puts "air purifier swing is disabled"
49
+ elsif swing_mode == 1
50
+ puts "air purifier swing is enabled"
51
+ end
52
+ end
53
+
54
+ air_purifier.rotation_speed.after_update do |rotation_speed|
55
+ puts "air_purifier is spinning at #{rotation_speed} speed"
56
+ end
57
+
58
+ air_purifier.lock_physical_controls.after_update do |lock_physical_controls|
59
+ if lock_physical_controls == 0
60
+ puts "air purifier control lock disabled"
61
+ elsif lock_physical_controls == 1
62
+ puts "air purifier control lock enabled"
63
+ end
64
+ end
65
+
66
+ RubyHome.run
@@ -0,0 +1,119 @@
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
+ air_quality_values = {
21
+ 0 => "Unknown",
22
+ 1 => "Excellent",
23
+ 2 => "Good",
24
+ 3 => "Fair",
25
+ 4 => "Inferior",
26
+ 5 => "Poor"
27
+ }
28
+ air_quality_sensor.air_quality.after_update do |air_quality|
29
+ state = air_quality_values[air_quality]
30
+ puts "air quality sensor air quality is #{state}"
31
+ end
32
+
33
+ air_quality_sensor.carbon_dioxide_level.after_update do |carbon_dioxide_level|
34
+ puts "air quality sensor carbon_dioxide_level #{carbon_dioxide_level}"
35
+ end
36
+
37
+ air_quality_sensor.carbon_monoxide_level.after_update do |carbon_monoxide_level|
38
+ puts "air quality sensor carbon_monoxide_level #{carbon_monoxide_level}"
39
+ end
40
+
41
+ air_quality_sensor.voc_density.after_update do |voc_density|
42
+ puts "air quality sensor voc_density #{voc_density}"
43
+ end
44
+
45
+ air_quality_sensor.pm10_density.after_update do |pm10_density|
46
+ puts "air quality sensor pm10_density #{pm10_density}"
47
+ end
48
+
49
+ air_quality_sensor.pm2_5_density.after_update do |pm2_5_density|
50
+ puts "air quality sensor pm2_5_density #{pm2_5_density}"
51
+ end
52
+
53
+ air_quality_sensor.sulphur_dioxide_density.after_update do |sulphur_dioxide_density|
54
+ puts "air quality sensor sulphur_dioxide_density #{sulphur_dioxide_density}"
55
+ end
56
+
57
+ air_quality_sensor.nitrogen_dioxide_density.after_update do |nitrogen_dioxide_density|
58
+ puts "air quality sensor nitrogen_dioxide_density #{nitrogen_dioxide_density}"
59
+ end
60
+
61
+ air_quality_sensor.ozone_density.after_update do |ozone_density|
62
+ puts "air quality sensor ozone_density #{ozone_density}"
63
+ end
64
+
65
+ air_quality_sensor.status_low_battery.after_update do |status_low_battery|
66
+ if status_low_battery == 0
67
+ puts "air quality sensor battery level normal"
68
+ elsif status_low_battery == 1
69
+ puts "air quality sensor battery level lormal"
70
+ end
71
+ end
72
+
73
+ air_quality_sensor.status_tampered.after_update do |status_tampered|
74
+ if status_tampered == 0
75
+ puts "air quality sensor status_tampered not tampered"
76
+ elsif status_tampered == 1
77
+ puts "air quality sensor status_tampered tampered"
78
+ end
79
+ end
80
+
81
+ air_quality_sensor.status_fault.after_update do |status_fault|
82
+ if status_fault == 0
83
+ puts "air quality sensor status_fault no fault"
84
+ elsif status_fault == 1
85
+ puts "air quality sensor status_fault general fault"
86
+ end
87
+ end
88
+
89
+ air_quality_sensor.status_active.after_update do |active|
90
+ if active
91
+ puts "air quality sensor is active"
92
+ else
93
+ puts "air quality sensor is inactive"
94
+ end
95
+ end
96
+
97
+ Thread.new do
98
+ sleep 30
99
+
100
+ loop do
101
+ air_quality_sensor.air_quality = air_quality_values.keys.sample
102
+ air_quality_sensor.carbon_dioxide_level = (0..100000).to_a.sample
103
+ air_quality_sensor.carbon_monoxide_level = (0..100).to_a.sample
104
+ air_quality_sensor.voc_density = (0..1000).to_a.sample
105
+ air_quality_sensor.pm10_density = (0..1000).to_a.sample
106
+ air_quality_sensor.pm2_5_density = (0..1000).to_a.sample
107
+ air_quality_sensor.sulphur_dioxide_density = (0..1000).to_a.sample
108
+ air_quality_sensor.nitrogen_dioxide_density = (0..1000).to_a.sample
109
+ air_quality_sensor.ozone_density = (0..1000).to_a.sample
110
+ air_quality_sensor.status_low_battery = (0..1).to_a.sample
111
+ air_quality_sensor.status_tampered = (0..1).to_a.sample
112
+ air_quality_sensor.status_fault = (0..1).to_a.sample
113
+ air_quality_sensor.status_active = [true, false].to_a.sample
114
+
115
+ sleep 10
116
+ end
117
+ end
118
+
119
+ RubyHome.run