ruby_home 0.1.21 → 0.1.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: c60d5366dfa8a7f6b485c54212fb6559f2542b7a
4
- data.tar.gz: f5a297ad7566a3a516be681bba3a16bbc94d204b
2
+ SHA256:
3
+ metadata.gz: f5c2472175346b490fafbd175e114227a9796e4304c472d5c3e5f4eb8734c76a
4
+ data.tar.gz: 6930dac62338255403695f5369397daa26fd0c7853d9ab2784a7de084f092655
5
5
  SHA512:
6
- metadata.gz: 66b2f8f148791dcacf5d2207ee69cafcf17a3b5fff85f69c1e682f403c6a7f14a6a4f729a57831595e01efb65865b74b91ad7f837c67417edd8fe42200b04606
7
- data.tar.gz: 5c5b99686275cea3696558be5034bc0f2f692323a500c63644ede9c990e7a56784006a3fe2d07155c4946d412a1c796e7f0bf2a059b16de9b14622dfda6952ea
6
+ metadata.gz: 18ebd83f029b7a1545d2f28331ca38be78ffe5a392026e598b93732b936dc5712b43e7b7b1c24088864709cc4fa45d6189bf3c9793220303d02b1fb86c336079
7
+ data.tar.gz: cd1227d1e26ef5dd91c6fc91c1ce526cc8b8e257916161a8cc72814e68f5be522b33bdd8f4db3d46a5511ce98534261917c640dfe75e6cc9e23df2cc19efe391
data/.gitignore CHANGED
@@ -11,3 +11,4 @@
11
11
  Gemfile.lock
12
12
  accessory_info.yml
13
13
  identifier_cache.yml
14
+ .ruby-version
@@ -12,7 +12,7 @@ install:
12
12
  - 'bundle --version'
13
13
  - bundle
14
14
  rvm:
15
- - 2.4
15
+ - 2.4.1
16
16
  - 2.5
17
17
  - 2.6
18
18
  - ruby-head
data/README.md CHANGED
@@ -58,6 +58,26 @@ end
58
58
  RubyHome.run
59
59
  ```
60
60
 
61
+ ## Configuration
62
+
63
+ The configuration options can be set by using the `configure` helper
64
+
65
+ ```ruby
66
+ RubyHome.configure do |c|
67
+ c.discovery_name = 'My Home'
68
+ end
69
+ ```
70
+
71
+ The following is the full list of available configuration options:
72
+
73
+ | Method | Description | Default | Example | Type |
74
+ |---|---|---|---|---|
75
+ | `discovery_name` | The user-visible name of the accessory | `"RubyHome"` | `"My Home"` | String |
76
+ | `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 |
78
+ | `host` | The hostname or IP address of the interface to listen on | `"0.0.0.0"` | `"192.168.0.2"` | String |
79
+ | `port` | The port that should be used when starting the built-in web server | `4567` | `8080` | Integer |
80
+
61
81
  ## Customization
62
82
 
63
83
  RubyHome tries to provide sane defaults for all services. Customization of any of the options is possible.
@@ -18,6 +18,16 @@ module RubyHome
18
18
  Dir[File.dirname(__FILE__) + '/ruby_home/**/*.rb'].each { |file| require file }
19
19
 
20
20
  class << self
21
+ def configuration
22
+ @_configuration ||= Configuration.new
23
+ end
24
+
25
+ alias_method :config, :configuration
26
+
27
+ def configure
28
+ yield configuration
29
+ end
30
+
21
31
  def run
22
32
  trap 'INT' do shutdown end
23
33
  trap 'TERM' do shutdown end
@@ -43,11 +53,11 @@ module RubyHome
43
53
  end
44
54
 
45
55
  def dns_service
46
- @_dns_service ||= DNS::Service.new(hap_server.port)
56
+ @_dns_service ||= DNS::Service.new(configuration: configuration)
47
57
  end
48
58
 
49
59
  def hap_server
50
- @_hap_server ||= HAP::Server.new('0.0.0.0', 4567)
60
+ @_hap_server ||= HAP::Server.new(configuration.host, configuration.port)
51
61
  end
52
62
 
53
63
  def greet
@@ -31,6 +31,11 @@ module RubyHome
31
31
  @password ||= Password.generate
32
32
  end
33
33
 
34
+ def password=(new_password)
35
+ @password = new_password
36
+ save
37
+ end
38
+
34
39
  def device_id
35
40
  @device_id ||= DeviceID.generate
36
41
  end
@@ -0,0 +1,35 @@
1
+ module RubyHome
2
+ class Configuration
3
+ extend Forwardable
4
+
5
+ def initialize(accessory_info = AccessoryInfo.instance)
6
+ @accessory_info = accessory_info
7
+ end
8
+
9
+ DEFAULT_NAME = -'RubyHome'
10
+ DEFAULT_HOST = -'0.0.0.0'
11
+ DEFAULT_PORT = 4567
12
+ DEFAULT_MODEL_NAME = DEFAULT_NAME
13
+ DEFAULT_DISCOVERY_NAME = DEFAULT_NAME
14
+
15
+ def discovery_name
16
+ @discovery_name || DEFAULT_DISCOVERY_NAME
17
+ end
18
+
19
+ def model_name
20
+ @model_name || DEFAULT_MODEL_NAME
21
+ end
22
+
23
+ def port
24
+ @port || DEFAULT_PORT
25
+ end
26
+
27
+ def host
28
+ @host || DEFAULT_HOST
29
+ end
30
+
31
+ attr_writer :discovery_name, :model_name, :host, :port
32
+
33
+ def_delegators :@accessory_info, :password, :password=
34
+ end
35
+ end
@@ -1,8 +1,8 @@
1
1
  module RubyHome
2
2
  module DNS
3
3
  class Service
4
- def initialize(port)
5
- @port = port
4
+ def initialize(configuration: )
5
+ @configuration = configuration
6
6
  end
7
7
 
8
8
  def update
@@ -15,24 +15,38 @@ module RubyHome
15
15
 
16
16
  private
17
17
 
18
+ attr_reader :configuration
19
+
18
20
  def dnssd_service
19
21
  @_dnssd_service ||= begin
20
- DNSSD::Service.register(name, type, nil, port, nil, text_record)
22
+ DNSSD::Service.register(name, type, nil, port, host, text_record)
21
23
  end
22
24
  end
23
25
 
24
26
  def name
25
- 'RubyHome'
27
+ configuration.discovery_name
26
28
  end
27
29
 
28
30
  def type
29
- '_hap._tcp'
31
+ -'_hap._tcp'
32
+ end
33
+
34
+ def port
35
+ configuration.port
30
36
  end
31
37
 
32
- attr_reader :port
38
+ def host
39
+ return nil if configuration.host == Configuration::DEFAULT_HOST
40
+
41
+ configuration.host
42
+ end
33
43
 
34
44
  def text_record
35
- TextRecord.new(accessory_info: AccessoryInfo.instance)
45
+ TextRecord.new(accessory_info: accessory_info, configuration: configuration)
46
+ end
47
+
48
+ def accessory_info
49
+ AccessoryInfo.instance
36
50
  end
37
51
  end
38
52
  end
@@ -1,13 +1,14 @@
1
1
  module RubyHome
2
2
  class TextRecord < DNSSD::TextRecord
3
- def initialize(accessory_info:)
3
+ def initialize(accessory_info:, configuration:)
4
+ @configuration = configuration
4
5
  @accessory_info = accessory_info
5
6
  super(to_hash)
6
7
  end
7
8
 
8
9
  private
9
10
 
10
- attr_reader :accessory_info
11
+ attr_reader :accessory_info, :configuration
11
12
 
12
13
  def to_hash
13
14
  {
@@ -74,7 +75,7 @@ module RubyHome
74
75
  # Model name of the accessory (e.g. "Device1,1"). Required.
75
76
 
76
77
  def model_name
77
- 'RubyHome'
78
+ configuration.model_name
78
79
  end
79
80
 
80
81
  # Protocol version string <major>.<minor> (e.g. "1.0"). Required if value is
@@ -1,3 +1,3 @@
1
1
  module RubyHome
2
- VERSION = '0.1.21'
2
+ VERSION = '0.1.22'
3
3
  end
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.1.21
4
+ version: 0.1.22
5
5
  platform: ruby
6
6
  authors:
7
7
  - Karl Entwistle
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-02-21 00:00:00.000000000 Z
11
+ date: 2019-02-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bindata
@@ -248,7 +248,6 @@ files:
248
248
  - ".hound.yml"
249
249
  - ".rspec"
250
250
  - ".rubocop.yml"
251
- - ".ruby-version"
252
251
  - ".travis.yml"
253
252
  - Gemfile
254
253
  - LICENSE
@@ -265,6 +264,7 @@ files:
265
264
  - lib/ruby_home/characteristic_collection.rb
266
265
  - lib/ruby_home/config/characteristics.yml
267
266
  - lib/ruby_home/config/services.yml
267
+ - lib/ruby_home/configuration.rb
268
268
  - lib/ruby_home/device_id.rb
269
269
  - lib/ruby_home/dns/service.rb
270
270
  - lib/ruby_home/dns/text_record.rb
@@ -339,8 +339,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
339
339
  - !ruby/object:Gem::Version
340
340
  version: '0'
341
341
  requirements: []
342
- rubyforge_project:
343
- rubygems_version: 2.6.8
342
+ rubygems_version: 3.0.1
344
343
  signing_key:
345
344
  specification_version: 4
346
345
  summary: Ruby HomeKit support
@@ -1 +0,0 @@
1
- 2.4.0