ruby_home 0.1.15 → 0.1.16

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: 90d257a9cc88bba2f6323a89829fc89000e6e84842dbf7abadefb35168eb2848
4
- data.tar.gz: 94acb47192d8cb7b9a54f01f7621da8b5371c2218ebf9494d2324af2193a705d
3
+ metadata.gz: 78d53eedc8551fe938a91a59629393108dbab03836f237ee9c535769c97bc09e
4
+ data.tar.gz: '0388c9fee54bc40b072eefb0d330701c5460d9e99156c7b0df305caf2294a671'
5
5
  SHA512:
6
- metadata.gz: e229661aca3237368c77159703e01b10ad8a39d4c3ce35176ce73251668bba6077646285c2360fa783d79d5c77b658ae84299af6143ecd613b8abf97edd2213b
7
- data.tar.gz: 3e4aadce797eb3b8a8be1ae6f70af601866726c7d53f76e3a0c7246fda25affadc0c67220e98d1596b4befa1a6dc6299ff89f7863c232b45e1748529497d84c8
6
+ metadata.gz: f60165e3c45540053e7074e94dfb190d4290363189c6e730079d669b1d85e9b1ab4f2c0297ec5359acd6c680d30200c646b0d5c4e8be680d765d9f3097dda06a
7
+ data.tar.gz: 3da982336642c9a69d64b32a3c769bdc60f55c30cfaf6be51c3b3a6eb56fd629e65186ccd705b8bfaac54a87fe34dc28baa3a7b0fc3e3ac28a73a8924bd40748
@@ -1,9 +1,5 @@
1
1
  module RubyHome
2
2
  class CharacteristicFactory
3
- DEFAULT_VALUES = {
4
- identify: nil,
5
- }.freeze
6
-
7
3
  def self.create(characteristic_name, service: , subtype: 'default' , value: nil)
8
4
  new(
9
5
  characteristic_name: characteristic_name,
@@ -22,7 +18,7 @@ module RubyHome
22
18
  service: service,
23
19
  unit: template.unit,
24
20
  uuid: template.uuid,
25
- value: value
21
+ value_object: value_object
26
22
  )
27
23
 
28
24
  if persisted_characteristic
@@ -54,11 +50,11 @@ module RubyHome
54
50
  @template ||= CharacteristicTemplate.find_by(name: characteristic_name)
55
51
  end
56
52
 
57
- def value
58
- value_object.new(template, @requested_value)
53
+ def value_object
54
+ value_object_class.new(template, @requested_value)
59
55
  end
60
56
 
61
- def value_object
57
+ def value_object_class
62
58
  BaseValue.value_for_template(template)
63
59
  end
64
60
 
@@ -23,7 +23,7 @@ module RubyHome
23
23
  'write' => 'pw',
24
24
  }.freeze
25
25
 
26
- def initialize(uuid:, name:, description:, format:, unit:, properties:, service: , value: nil)
26
+ def initialize(uuid:, name:, description:, format:, unit:, properties:, service: , value_object: )
27
27
  @uuid = uuid
28
28
  @name = name
29
29
  @description = description
@@ -31,7 +31,7 @@ module RubyHome
31
31
  @unit = unit
32
32
  @properties = properties
33
33
  @service = service
34
- @value = value
34
+ @value_object = value_object
35
35
  end
36
36
 
37
37
  attr_reader(
@@ -42,7 +42,8 @@ module RubyHome
42
42
  :format,
43
43
  :unit,
44
44
  :properties,
45
- :instance_id
45
+ :instance_id,
46
+ :value_object,
46
47
  )
47
48
 
48
49
  def instance_id=(new_id)
@@ -59,11 +60,11 @@ module RubyHome
59
60
  end
60
61
 
61
62
  def value
62
- @value.value
63
+ value_object.value
63
64
  end
64
65
 
65
66
  def value=(new_value)
66
- @value.value = new_value
67
+ value_object.value = new_value
67
68
  broadcast(:after_update, self)
68
69
  end
69
70
  end
@@ -65,8 +65,8 @@ module RubyHome
65
65
 
66
66
  return close(socket) unless request.keep_alive?
67
67
  return close(socket) unless response.keep_alive?
68
- rescue Errno::ECONNRESET, Errno::ECONNABORTED,
69
- Errno::EPROTO, Errno::EINVAL, Errno::EHOSTUNREACH
68
+ rescue Errno::ECONNABORTED, Errno::ECONNRESET, Errno::EHOSTUNREACH,
69
+ Errno::EINVAL, Errno::EPROTO, Errno::ETIMEDOUT
70
70
  close(socket)
71
71
  rescue EOFError
72
72
  close(socket)
@@ -79,4 +79,3 @@ module RubyHome
79
79
  end
80
80
  end
81
81
  end
82
-
@@ -1,7 +1,7 @@
1
1
  module RubyHome
2
2
  class BaseValue
3
3
  def self.value_for_template(template)
4
- return NullValue if template.name == :identify
4
+ return IdentifyValue if template.name == :identify
5
5
 
6
6
  "::RubyHome::#{template.format.classify}Value".safe_constantize || NullValue
7
7
  end
@@ -0,0 +1,9 @@
1
+ require_relative 'base_value'
2
+
3
+ module RubyHome
4
+ class IdentifyValue < BaseValue
5
+ def value
6
+ true
7
+ end
8
+ end
9
+ end
@@ -14,22 +14,26 @@ module RubyHome
14
14
  'perms' => perms(characteristic),
15
15
  'format' => characteristic.format,
16
16
  'description' => characteristic.description,
17
- }.merge(optional_hash(characteristic))
17
+ }.merge(value_hash(characteristic))
18
18
  end
19
19
 
20
- def perms(characteristic)
21
- characteristic.properties.map do |property|
22
- RubyHome::Characteristic::PROPERTIES[property]
23
- end.compact
24
- end
20
+ private
21
+
22
+ HIDDEN_VALUE_OBJECTS = [ IdentifyValue ].freeze
25
23
 
26
- def optional_hash(characteristic)
27
- Hash.new.tap do |optional_hash|
28
- if characteristic.value != nil
29
- optional_hash['value'] = characteristic.value
24
+ def perms(characteristic)
25
+ characteristic.properties.map do |property|
26
+ RubyHome::Characteristic::PROPERTIES[property]
27
+ end.compact
28
+ end
29
+
30
+ def value_hash(characteristic)
31
+ if HIDDEN_VALUE_OBJECTS.include?(characteristic.value_object.class)
32
+ {}
33
+ else
34
+ { 'value' => characteristic.value }.compact
30
35
  end
31
36
  end
32
- end
33
37
  end
34
38
  end
35
39
  end
@@ -1,3 +1,3 @@
1
1
  module RubyHome
2
- VERSION = '0.1.15'
2
+ VERSION = '0.1.16'
3
3
  end
data/rubyhome.gemspec CHANGED
@@ -30,7 +30,7 @@ Gem::Specification.new do |spec|
30
30
  spec.add_dependency 'dnssd', '~> 3.0'
31
31
  spec.add_dependency 'hkdf', '~> 0.3.0'
32
32
  spec.add_dependency 'nio4r', '~> 2.3', '>= 2.3.1'
33
- spec.add_dependency 'oj', '3.7.1'
33
+ spec.add_dependency 'oj', '3.7.4'
34
34
  spec.add_dependency 'rbnacl', '~> 6.0'
35
35
  spec.add_dependency 'ruby_home-srp', '~> 1.2'
36
36
  spec.add_dependency 'sinatra', '2.0.4'
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.15
4
+ version: 0.1.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Karl Entwistle
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-11-27 00:00:00.000000000 Z
11
+ date: 2018-12-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -98,14 +98,14 @@ dependencies:
98
98
  requirements:
99
99
  - - '='
100
100
  - !ruby/object:Gem::Version
101
- version: 3.7.1
101
+ version: 3.7.4
102
102
  type: :runtime
103
103
  prerelease: false
104
104
  version_requirements: !ruby/object:Gem::Requirement
105
105
  requirements:
106
106
  - - '='
107
107
  - !ruby/object:Gem::Version
108
- version: 3.7.1
108
+ version: 3.7.4
109
109
  - !ruby/object:Gem::Dependency
110
110
  name: rbnacl
111
111
  requirement: !ruby/object:Gem::Requirement
@@ -300,6 +300,7 @@ files:
300
300
  - lib/ruby_home/hap/values/base_value.rb
301
301
  - lib/ruby_home/hap/values/bool_value.rb
302
302
  - lib/ruby_home/hap/values/float_value.rb
303
+ - lib/ruby_home/hap/values/identify_value.rb
303
304
  - lib/ruby_home/hap/values/int32_value.rb
304
305
  - lib/ruby_home/hap/values/null_value.rb
305
306
  - lib/ruby_home/hap/values/string_value.rb