ruby_home 0.2.5 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (103) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/tests.yml +4 -4
  3. data/.gitignore +2 -2
  4. data/.rubocop.yml +2 -9
  5. data/.standard.yml +3 -0
  6. data/CHANGELOG.md +6 -1
  7. data/Gemfile +2 -2
  8. data/Rakefile +4 -4
  9. data/examples/air_purifier.rb +7 -8
  10. data/examples/air_quality_sensor.rb +8 -9
  11. data/examples/battery_service.rb +2 -3
  12. data/examples/carbon_dioxide_sensor.rb +2 -3
  13. data/examples/carbon_monoxide_sensor.rb +3 -4
  14. data/examples/contact_sensor.rb +2 -3
  15. data/examples/door.rb +5 -6
  16. data/examples/fan.rb +2 -3
  17. data/examples/fan_v2.rb +2 -3
  18. data/examples/garage_door_opener.rb +9 -10
  19. data/examples/heater_cooler.rb +9 -10
  20. data/examples/humidifier_dehumidifier.rb +9 -10
  21. data/examples/humidity_sensor.rb +2 -3
  22. data/examples/leak_sensor.rb +2 -3
  23. data/examples/light_sensor.rb +2 -3
  24. data/examples/lightbulb.rb +2 -3
  25. data/examples/lock_mechanism.rb +6 -7
  26. data/examples/motion_sensor.rb +2 -3
  27. data/examples/occupancy_sensor.rb +2 -3
  28. data/examples/outlet.rb +2 -3
  29. data/examples/security_system.rb +12 -13
  30. data/examples/smoke_sensor.rb +2 -3
  31. data/examples/switch.rb +2 -3
  32. data/examples/television.rb +8 -13
  33. data/examples/temperature_sensor.rb +2 -3
  34. data/examples/thermostat.rb +10 -11
  35. data/examples/window.rb +5 -6
  36. data/examples/window_covering.rb +5 -6
  37. data/lib/ruby_home.rb +21 -21
  38. data/lib/ruby_home/accessory.rb +1 -1
  39. data/lib/ruby_home/accessory_collection.rb +6 -6
  40. data/lib/ruby_home/accessory_info.rb +18 -18
  41. data/lib/ruby_home/characteristic.rb +8 -8
  42. data/lib/ruby_home/characteristic_collection.rb +13 -13
  43. data/lib/ruby_home/config/characteristics.yml +30 -635
  44. data/lib/ruby_home/config/manual_characteristics.yml +278 -0
  45. data/lib/ruby_home/config/manual_services.yml +45 -0
  46. data/lib/ruby_home/config/services.yml +329 -370
  47. data/lib/ruby_home/configuration.rb +4 -4
  48. data/lib/ruby_home/device_id.rb +3 -3
  49. data/lib/ruby_home/dns/service.rb +4 -6
  50. data/lib/ruby_home/dns/text_record.rb +9 -9
  51. data/lib/ruby_home/errors.rb +1 -0
  52. data/lib/ruby_home/factories/characteristic_factory.rb +37 -37
  53. data/lib/ruby_home/factories/service_factory.rb +72 -72
  54. data/lib/ruby_home/factories/templates/characteristic_template.rb +5 -5
  55. data/lib/ruby_home/factories/templates/service_template.rb +11 -10
  56. data/lib/ruby_home/hap/crypto/chacha20poly1305.rb +2 -2
  57. data/lib/ruby_home/hap/crypto/hkdf.rb +4 -4
  58. data/lib/ruby_home/hap/crypto/session_key.rb +7 -7
  59. data/lib/ruby_home/hap/decrypter.rb +8 -8
  60. data/lib/ruby_home/hap/encrypter.rb +5 -6
  61. data/lib/ruby_home/hap/ev_response.rb +17 -17
  62. data/lib/ruby_home/hap/hap_request.rb +1 -1
  63. data/lib/ruby_home/hap/server.rb +4 -4
  64. data/lib/ruby_home/hap/server_handler.rb +8 -10
  65. data/lib/ruby_home/hap/session.rb +22 -22
  66. data/lib/ruby_home/hap/values/base_value.rb +3 -3
  67. data/lib/ruby_home/hap/values/bool_value.rb +4 -4
  68. data/lib/ruby_home/hap/values/float_value.rb +4 -4
  69. data/lib/ruby_home/hap/values/identify_value.rb +1 -1
  70. data/lib/ruby_home/hap/values/int32_value.rb +4 -4
  71. data/lib/ruby_home/hap/values/null_value.rb +1 -1
  72. data/lib/ruby_home/hap/values/string_value.rb +11 -11
  73. data/lib/ruby_home/hap/values/uint32_value.rb +5 -5
  74. data/lib/ruby_home/hap/values/uint8_value.rb +14 -14
  75. data/lib/ruby_home/hex_helper.rb +3 -3
  76. data/lib/ruby_home/http/application.rb +7 -7
  77. data/lib/ruby_home/http/controllers/accessories_controller.rb +3 -3
  78. data/lib/ruby_home/http/controllers/application_controller.rb +6 -6
  79. data/lib/ruby_home/http/controllers/characteristics_controller.rb +29 -29
  80. data/lib/ruby_home/http/controllers/identify_controller.rb +10 -10
  81. data/lib/ruby_home/http/controllers/pair_setups_controller.rb +18 -18
  82. data/lib/ruby_home/http/controllers/pair_verifies_controller.rb +9 -9
  83. data/lib/ruby_home/http/controllers/pairings_controller.rb +5 -5
  84. data/lib/ruby_home/http/serializers/accessory_serializer.rb +5 -5
  85. data/lib/ruby_home/http/serializers/characteristic_serializer.rb +24 -24
  86. data/lib/ruby_home/http/serializers/characteristic_value_serializer.rb +5 -5
  87. data/lib/ruby_home/http/serializers/object_serializer.rb +1 -1
  88. data/lib/ruby_home/http/serializers/service_serializer.rb +9 -9
  89. data/lib/ruby_home/http/serializers/uuid_helper.rb +2 -2
  90. data/lib/ruby_home/http/services/session_notifier.rb +8 -8
  91. data/lib/ruby_home/http/services/start_srp_service.rb +3 -3
  92. data/lib/ruby_home/http/services/verify_finish_service.rb +22 -22
  93. data/lib/ruby_home/http/services/verify_srp_service.rb +22 -22
  94. data/lib/ruby_home/identifier_cache.rb +4 -5
  95. data/lib/ruby_home/password.rb +14 -14
  96. data/lib/ruby_home/persistable.rb +22 -7
  97. data/lib/ruby_home/service.rb +3 -3
  98. data/lib/ruby_home/service_collection.rb +1 -1
  99. data/lib/ruby_home/version.rb +1 -1
  100. data/rubyhome.gemspec +31 -31
  101. data/sbin/characteristic_generator.rb +22 -24
  102. data/sbin/service_generator.rb +36 -27
  103. metadata +25 -8
@@ -1,10 +1,10 @@
1
- require_relative 'service_collection'
1
+ require_relative "service_collection"
2
2
 
3
3
  module RubyHome
4
4
  class DuplicateServiceError < StandardError; end
5
5
 
6
6
  class Service
7
- def initialize(accessory: , primary: false, hidden: false, name:, description:, uuid:)
7
+ def initialize(accessory:, name:, description:, uuid:, primary: false, hidden: false)
8
8
  @accessory = accessory
9
9
  @primary = primary
10
10
  @hidden = hidden
@@ -25,7 +25,7 @@ module RubyHome
25
25
  :uuid,
26
26
  :instance_id
27
27
  )
28
-
28
+
29
29
  attr_accessor :linked
30
30
 
31
31
  def instance_id=(new_id)
@@ -20,6 +20,6 @@ module RubyHome
20
20
 
21
21
  private
22
22
 
23
- attr_reader :services
23
+ attr_reader :services
24
24
  end
25
25
  end
@@ -1,3 +1,3 @@
1
1
  module RubyHome
2
- VERSION = '0.2.5'
2
+ VERSION = "0.2.6"
3
3
  end
data/rubyhome.gemspec CHANGED
@@ -1,45 +1,45 @@
1
-
2
- lib = File.expand_path('../lib', __FILE__)
1
+ lib = File.expand_path("../lib", __FILE__)
3
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'ruby_home/version'
3
+ require "ruby_home/version"
5
4
 
6
5
  Gem::Specification.new do |spec|
7
- spec.name = 'ruby_home'
8
- spec.version = RubyHome::VERSION
9
- spec.authors = ['Karl Entwistle']
10
- spec.email = ['karl@entwistle.com']
11
- spec.summary = 'Ruby HomeKit support'
12
- spec.description = <<~DESCRIPTION
6
+ spec.name = "ruby_home"
7
+ spec.version = RubyHome::VERSION
8
+ spec.authors = ["Karl Entwistle"]
9
+ spec.email = ["karl@entwistle.com"]
10
+ spec.summary = "Ruby HomeKit support"
11
+ spec.description = <<~DESCRIPTION
13
12
  RubyHome is a lightweight service you can run on your home network that
14
13
  emulates the iOS HomeKit API. It supports community contributed plugins, which
15
14
  are modules that provide a bridge from HomeKit to various 3rd-party APIs
16
15
  provided by manufacturers of smart home devices.
17
16
  DESCRIPTION
18
- spec.homepage = 'https://github.com/karlentwistle/ruby_home'
19
- spec.license = 'MIT'
17
+ spec.homepage = "https://github.com/karlentwistle/ruby_home"
18
+ spec.license = "MIT"
20
19
 
21
- spec.files = `git ls-files -z`.split("\x0").reject do |f|
20
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
22
21
  f.match(%r{^(test|spec|features)/})
23
22
  end
24
- spec.bindir = 'bin'
25
- spec.executables = ['ruby_home']
26
- spec.require_paths = ['lib']
27
- spec.required_ruby_version = '>= 2.5.0'
23
+ spec.bindir = "bin"
24
+ spec.executables = ["ruby_home"]
25
+ spec.require_paths = ["lib"]
26
+ spec.required_ruby_version = ">= 2.5.0"
28
27
 
29
- spec.add_dependency 'dnssd', '~> 3.0'
30
- spec.add_dependency 'facets', '~> 3.1'
31
- spec.add_dependency 'hkdf', '~> 0.3.0'
32
- spec.add_dependency 'oj', '~> 3.10'
33
- spec.add_dependency 'rbnacl', '~> 7.0'
34
- spec.add_dependency 'ruby_home-srp', '~> 1.3'
35
- spec.add_dependency 'ruby_home-tlv', '~> 0.1'
36
- spec.add_dependency 'sinatra', '~> 2.0'
37
- spec.add_dependency 'webrick', '~> 1.7'
38
- spec.add_dependency 'wisper', '~> 2.0'
28
+ spec.add_dependency "dnssd", "~> 3.0"
29
+ spec.add_dependency "facets", "~> 3.1"
30
+ spec.add_dependency "hkdf", "~> 1.0.0"
31
+ spec.add_dependency "oj", "~> 3.10"
32
+ spec.add_dependency "rbnacl", "~> 7.0"
33
+ spec.add_dependency "ruby_home-srp", "~> 1.3"
34
+ spec.add_dependency "ruby_home-tlv", "~> 0.1"
35
+ spec.add_dependency "sinatra", "~> 2.0"
36
+ spec.add_dependency "webrick", "~> 1.7"
37
+ spec.add_dependency "wisper", "~> 2.0"
39
38
 
40
- spec.add_development_dependency 'byebug', '~> 11.0'
41
- spec.add_development_dependency 'plist', '~> 3.4'
42
- spec.add_development_dependency 'rack-test', '~> 1.1.0'
43
- spec.add_development_dependency 'rake', '~> 13.0'
44
- spec.add_development_dependency 'rspec', '~> 3.0'
39
+ spec.add_development_dependency "byebug", "~> 11.0"
40
+ spec.add_development_dependency "plist", "~> 3.4"
41
+ spec.add_development_dependency "rack-test", "~> 1.1.0"
42
+ spec.add_development_dependency "rake", "~> 13.0"
43
+ spec.add_development_dependency "rspec", "~> 3.0"
44
+ spec.add_development_dependency "standard", "~> 1.0"
45
45
  end
@@ -1,39 +1,39 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'byebug'
4
- require 'plist'
5
- require 'yaml'
3
+ require "byebug"
4
+ require "plist"
5
+ require "yaml"
6
6
 
7
7
  module RubyHome
8
8
  class CharacteristicGenerator
9
9
  class << self
10
10
  def run
11
11
  convert_binary_plist
12
- File.open(file_path, 'w') do |file|
12
+ File.open(file_path, "w") do |file|
13
13
  file.write generate_characteristics.to_yaml
14
14
  end
15
15
  end
16
16
 
17
17
  def generate_characteristics
18
- parsed_xml['Characteristics'].map do |characteristics_xml|
18
+ parsed_xml["Characteristics"].map do |characteristics_xml|
19
19
  new(characteristics_xml).generate_characteristic_hash
20
20
  end
21
21
  end
22
22
 
23
23
  def convert_binary_plist
24
24
  system([
25
- 'plutil -convert xml1 -o',
26
- '/tmp/Accessory.xml',
25
+ "plutil -convert xml1 -o",
26
+ "/tmp/Accessory.xml",
27
27
  "\'/Applications/Utilities/HomeKit\ Accessory\ Simulator.app/Contents/Frameworks/HAPAccessoryKit.framework/Versions/A/Resources/default.metadata.plist\'"
28
- ].join(' '))
28
+ ].join(" "))
29
29
  end
30
30
 
31
31
  def parsed_xml
32
- Plist.parse_xml('/tmp/Accessory.xml')
32
+ Plist.parse_xml("/tmp/Accessory.xml")
33
33
  end
34
34
 
35
35
  def file_path
36
- File.dirname(__FILE__) + '/../lib/ruby_home/config/characteristics.yml'
36
+ File.dirname(__FILE__) + "/../lib/ruby_home/config/characteristics.yml"
37
37
  end
38
38
  end
39
39
 
@@ -41,7 +41,6 @@ module RubyHome
41
41
  @constraints = xml["Constraints"]
42
42
  @format = xml["Format"]
43
43
  @name = xml["Name"]
44
- @permissions = xml["Permissions"]
45
44
  @properties = xml["Properties"]
46
45
  @uuid = xml["UUID"]
47
46
  @unit = xml["Unit"]
@@ -54,29 +53,28 @@ module RubyHome
54
53
  uuid: uuid,
55
54
  format: format,
56
55
  unit: sanitized_unit,
57
- permissions: permissions,
58
56
  properties: properties,
59
- constraints: constraints,
57
+ constraints: constraints
60
58
  }
61
59
  end
62
60
 
63
61
  private
64
62
 
65
- def sanitized_name
66
- name.downcase.gsub(' ', '_').gsub('.', '_')
67
- end
63
+ def sanitized_name
64
+ name.downcase.tr(" ", "_").tr(".", "_")
65
+ end
68
66
 
69
- def sanitized_unit
70
- if unit
71
- "\"#{unit}\""
72
- else
73
- "nil"
74
- end
67
+ def sanitized_unit
68
+ if unit
69
+ "\"#{unit}\""
70
+ else
71
+ "nil"
75
72
  end
73
+ end
76
74
 
77
- private
75
+ private
78
76
 
79
- attr_reader :constraints, :format, :name, :permissions, :properties, :uuid, :unit
77
+ attr_reader :constraints, :format, :name, :properties, :uuid, :unit
80
78
  end
81
79
  end
82
80
 
@@ -1,46 +1,47 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'byebug'
4
- require 'plist'
5
- require 'yaml'
3
+ require "byebug"
4
+ require "plist"
5
+ require "yaml"
6
+ require_relative "../lib/ruby_home"
6
7
 
7
8
  module RubyHome
8
9
  class ServiceGenerator
9
10
  class << self
10
11
  def run
11
12
  convert_binary_plist
12
- File.open(file_path, 'w') do |file|
13
+ File.open(file_path, "w") do |file|
13
14
  file.write generate_services.to_yaml
14
15
  end
15
16
  end
16
17
 
17
18
  def generate_services
18
- parsed_xml['Services'].map do |services_xml|
19
+ parsed_xml["Services"].map do |services_xml|
19
20
  new(services_xml).generate_service_hash
20
21
  end
21
22
  end
22
23
 
23
24
  def convert_binary_plist
24
25
  system([
25
- 'plutil -convert xml1 -o',
26
- '/tmp/Accessory.xml',
26
+ "plutil -convert xml1 -o",
27
+ "/tmp/Accessory.xml",
27
28
  "\'/Applications/Utilities/HomeKit\ Accessory\ Simulator.app/Contents/Frameworks/HAPAccessoryKit.framework/Versions/A/Resources/default.metadata.plist\'"
28
- ].join(' '))
29
+ ].join(" "))
29
30
  end
30
31
 
31
32
  def parsed_xml
32
- Plist.parse_xml('/tmp/Accessory.xml')
33
+ Plist.parse_xml("/tmp/Accessory.xml")
33
34
  end
34
35
 
35
36
  def file_path
36
- File.dirname(__FILE__) + '/../lib/ruby_home/config/services.yml'
37
+ File.dirname(__FILE__) + "/../lib/ruby_home/config/services.yml"
37
38
  end
38
39
  end
39
40
 
40
41
  def initialize(xml)
41
42
  @name = xml["Name"]
42
- @optional_characteristics = xml["OptionalCharacteristics"]
43
- @required_characteristics = xml["RequiredCharacteristics"]
43
+ @optional_characteristic_uuids = xml["OptionalCharacteristics"]
44
+ @required_characteristic_uuids = xml["RequiredCharacteristics"]
44
45
  @uuid = xml["UUID"]
45
46
  end
46
47
 
@@ -49,30 +50,38 @@ module RubyHome
49
50
  name: sanitized_name.to_sym,
50
51
  description: name,
51
52
  uuid: uuid,
52
- optional_characteristics_uuids: optional_characteristics,
53
- required_characteristics_uuids: required_characteristics,
53
+ optional_characteristic_names: optional_characteristic_names.sort,
54
+ required_characteristic_names: required_characteristic_names.sort
54
55
  }
55
56
  end
56
57
 
57
58
  private
58
59
 
59
- def sanitized_name
60
- name.downcase.gsub(' ', '_')
61
- end
60
+ def sanitized_name
61
+ name.downcase.tr(" ", "_")
62
+ end
62
63
 
63
- COLOR_TEMPERATURE_UUID = -'000000CE-0000-1000-8000-0026BB765291'
64
+ def optional_characteristic_names
65
+ optional_characteristic_uuids.map do |uuid|
66
+ RubyHome::CharacteristicTemplate.find_by(uuid: uuid).name
67
+ end + additional_optional_characteristic_names
68
+ end
64
69
 
65
- def optional_characteristics
66
- if sanitized_name == 'lightbulb'
67
- # HomeKit Accessory Simulator doesnt include color temperature as a characteristic
68
- # HAP-Specification-Non-Commercial-Version lists it as a valid optional characteristic
69
- @optional_characteristics + [COLOR_TEMPERATURE_UUID]
70
- else
71
- @optional_characteristics
72
- end
70
+ ADDITIONAL_OPTIONAL_CHARACTERISTIC_NAMES = {
71
+ "lightbulb" => [:color_temperature]
72
+ }.freeze
73
+
74
+ def additional_optional_characteristic_names
75
+ ADDITIONAL_OPTIONAL_CHARACTERISTIC_NAMES.fetch(sanitized_name, [])
76
+ end
77
+
78
+ def required_characteristic_names
79
+ required_characteristic_uuids.map do |uuid|
80
+ RubyHome::CharacteristicTemplate.find_by(uuid: uuid).name
73
81
  end
82
+ end
74
83
 
75
- attr_reader :name, :required_characteristics, :uuid
84
+ attr_reader :name, :required_characteristic_uuids, :optional_characteristic_uuids, :uuid
76
85
  end
77
86
  end
78
87
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_home
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Karl Entwistle
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-01-22 00:00:00.000000000 Z
11
+ date: 2021-05-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dnssd
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 0.3.0
47
+ version: 1.0.0
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 0.3.0
54
+ version: 1.0.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: oj
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -220,6 +220,20 @@ dependencies:
220
220
  - - "~>"
221
221
  - !ruby/object:Gem::Version
222
222
  version: '3.0'
223
+ - !ruby/object:Gem::Dependency
224
+ name: standard
225
+ requirement: !ruby/object:Gem::Requirement
226
+ requirements:
227
+ - - "~>"
228
+ - !ruby/object:Gem::Version
229
+ version: '1.0'
230
+ type: :development
231
+ prerelease: false
232
+ version_requirements: !ruby/object:Gem::Requirement
233
+ requirements:
234
+ - - "~>"
235
+ - !ruby/object:Gem::Version
236
+ version: '1.0'
223
237
  description: |
224
238
  RubyHome is a lightweight service you can run on your home network that
225
239
  emulates the iOS HomeKit API. It supports community contributed plugins, which
@@ -237,6 +251,7 @@ files:
237
251
  - ".hound.yml"
238
252
  - ".rspec"
239
253
  - ".rubocop.yml"
254
+ - ".standard.yml"
240
255
  - CHANGELOG.md
241
256
  - Gemfile
242
257
  - LICENSE
@@ -281,6 +296,8 @@ files:
281
296
  - lib/ruby_home/characteristic_collection.rb
282
297
  - lib/ruby_home/config/categories.yml
283
298
  - lib/ruby_home/config/characteristics.yml
299
+ - lib/ruby_home/config/manual_characteristics.yml
300
+ - lib/ruby_home/config/manual_services.yml
284
301
  - lib/ruby_home/config/services.yml
285
302
  - lib/ruby_home/configuration.rb
286
303
  - lib/ruby_home/device_id.rb
@@ -344,7 +361,7 @@ homepage: https://github.com/karlentwistle/ruby_home
344
361
  licenses:
345
362
  - MIT
346
363
  metadata: {}
347
- post_install_message:
364
+ post_install_message:
348
365
  rdoc_options: []
349
366
  require_paths:
350
367
  - lib
@@ -359,8 +376,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
359
376
  - !ruby/object:Gem::Version
360
377
  version: '0'
361
378
  requirements: []
362
- rubygems_version: 3.1.4
363
- signing_key:
379
+ rubygems_version: 3.2.15
380
+ signing_key:
364
381
  specification_version: 4
365
382
  summary: Ruby HomeKit support
366
383
  test_files: []