ruby_home 0.1.12 → 0.1.13

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: 164e411f03ec5168e551384eac1a24c7c95040aaa3e9c1c50fae85d2a357c0a6
4
- data.tar.gz: 485d5bb8c361d732fb916f81e164d50a88cdfb44ce6088ec6c67f73d35e19f33
3
+ metadata.gz: cbb486ea0b95baaee4388d69f2875024e941d7a79b2385f327f6cfb4639cc270
4
+ data.tar.gz: d451c724e41292c3899461951bcd337095404abd0c730744cd3bf863a58e9859
5
5
  SHA512:
6
- metadata.gz: 12340d7997f5c78bb160f5f7258595b73a81700c40a3a7de79acb2790290366443c5a03f899f4687487e82b6e7ed45a9c2400342c545d39588c0de14910bd052
7
- data.tar.gz: 3c86acf49f8348c1d56f4189faabd222d19141bbfed8f073d69fd701a5bce40f6e65356f4f4ce95e6867da98ce3a18d4e4b279e62413ac65d1fb879952abda7a
6
+ metadata.gz: 569b75436eaa94dd62ce2395cedf0af12b4a9d498168d80a12534e6ee2320a870e6f7967676fae986243b2f4bf6e98a456e17089183ee9c5e2768539fcb131b1
7
+ data.tar.gz: 0e43c491540462de28126a06cbe84f93b15ede9ef13133998f9c1e855b7c48ba8f4a3570d4d1fa8c485f6accc2fd1e1cb2864e92ff7dca0b04f7e728363dc818
data/README.md CHANGED
@@ -48,7 +48,7 @@ accessory_information = RubyHome::ServiceFactory.create(:accessory_information)
48
48
  fan = RubyHome::ServiceFactory.create(:fan)
49
49
 
50
50
  fan.characteristic(:on).after_update do |characteristic|
51
- if characteristic.value == 1
51
+ if characteristic.value == true
52
52
  puts "Fan switched on"
53
53
  else
54
54
  puts "Fan switched off"
@@ -106,7 +106,7 @@ fan = RubyHome::ServiceFactory.create(:fan,
106
106
  )
107
107
 
108
108
  fan.characteristic(:on).after_update do |characteristic|
109
- if characteristic.value == 1
109
+ if characteristic.value == true
110
110
  puts "Fan switched on"
111
111
  else
112
112
  puts "Fan switched off"
data/bin/ruby_home CHANGED
@@ -6,7 +6,7 @@ accessory_information = RubyHome::ServiceFactory.create(:accessory_information)
6
6
  fan = RubyHome::ServiceFactory.create(:fan)
7
7
 
8
8
  fan.characteristic(:on).after_update do |characteristic|
9
- if characteristic.value == 1
9
+ if characteristic.value == true
10
10
  puts "Fan switched on"
11
11
  else
12
12
  puts "Fan switched off"
@@ -43,10 +43,10 @@ module RubyHome
43
43
  @characteristic_name = characteristic_name.to_sym
44
44
  @service = service
45
45
  @subtype = subtype
46
- @value = value || default_value
46
+ @requested_value = value
47
47
  end
48
48
 
49
- attr_reader :service, :characteristic_name, :value, :subtype
49
+ attr_reader :service, :characteristic_name, :subtype
50
50
 
51
51
  delegate :accessory, to: :service
52
52
 
@@ -54,17 +54,12 @@ module RubyHome
54
54
  @template ||= CharacteristicTemplate.find_by(name: characteristic_name)
55
55
  end
56
56
 
57
- def default_value
58
- DEFAULT_VALUES.fetch(characteristic_name.to_sym) do
59
- klass = "RubyHome::#{template.format.classify}DefaultValue".safe_constantize || NullDefaultValue
60
- default_value = klass.new(template).default
57
+ def value
58
+ value_object.new(template, @requested_value)
59
+ end
61
60
 
62
- if default_value.nil?
63
- raise "No default value available for characteristic: #{characteristic_name} of type: #{template.format}"
64
- else
65
- default_value
66
- end
67
- end
61
+ def value_object
62
+ BaseValue.value_for_template(template)
68
63
  end
69
64
 
70
65
  def persisted_characteristic
@@ -36,7 +36,6 @@ module RubyHome
36
36
 
37
37
  attr_reader(
38
38
  :service,
39
- :value,
40
39
  :uuid,
41
40
  :name,
42
41
  :description,
@@ -59,9 +58,12 @@ module RubyHome
59
58
  service.instance_id
60
59
  end
61
60
 
61
+ def value
62
+ @value.value
63
+ end
64
+
62
65
  def value=(new_value)
63
- return if name == :identify
64
- @value = new_value
66
+ @value.value = new_value
65
67
  broadcast(:after_update, self)
66
68
  end
67
69
  end
@@ -0,0 +1,28 @@
1
+ module RubyHome
2
+ class BaseValue
3
+ def self.value_for_template(template)
4
+ return NullValue if template.name == :identify
5
+
6
+ "::RubyHome::#{template.format.classify}Value".safe_constantize || NullValue
7
+ end
8
+
9
+ def initialize(characteristic_template=nil, initial_value=nil)
10
+ @template = characteristic_template
11
+ @value = initial_value
12
+ end
13
+
14
+ def value
15
+ @value || default
16
+ end
17
+
18
+ def default
19
+ raise NotImplementedError
20
+ end
21
+
22
+ attr_writer :value
23
+
24
+ private
25
+
26
+ attr_reader :template
27
+ end
28
+ end
@@ -0,0 +1,20 @@
1
+ require_relative 'base_value'
2
+
3
+ module RubyHome
4
+ class BoolValue < BaseValue
5
+ REMAPPED_VALUES = {
6
+ '0' => false,
7
+ 0 => false,
8
+ '1' => true,
9
+ 1 => true,
10
+ }.freeze
11
+
12
+ def default
13
+ false
14
+ end
15
+
16
+ def value=(new_value)
17
+ @value = REMAPPED_VALUES.fetch(new_value, new_value)
18
+ end
19
+ end
20
+ end
@@ -1,7 +1,7 @@
1
1
  require_relative 'base_value'
2
2
 
3
3
  module RubyHome
4
- class FloatDefaultValue < BaseValue
4
+ class FloatValue < BaseValue
5
5
  def default
6
6
  minimum_value.to_f
7
7
  end
@@ -1,7 +1,7 @@
1
1
  require_relative 'base_value'
2
2
 
3
3
  module RubyHome
4
- class Int32DefaultValue < BaseValue
4
+ class Int32Value < BaseValue
5
5
  def default
6
6
  minimum_value.to_i
7
7
  end
@@ -0,0 +1,17 @@
1
+ require_relative 'base_value'
2
+
3
+ module RubyHome
4
+ class NullValue < BaseValue
5
+ def value
6
+ nil
7
+ end
8
+
9
+ def value=(new_value)
10
+ nil
11
+ end
12
+
13
+ def default
14
+ nil
15
+ end
16
+ end
17
+ end
@@ -1,7 +1,7 @@
1
1
  require_relative 'base_value'
2
2
 
3
3
  module RubyHome
4
- class StringDefaultValue < BaseValue
4
+ class StringValue < BaseValue
5
5
  DEFAULT_VALUES = {
6
6
  firmware_revision: '1.0',
7
7
  hardware_revision: '1.0',
@@ -1,7 +1,7 @@
1
1
  require_relative 'base_value'
2
2
 
3
3
  module RubyHome
4
- class Uint32DefaultValue < BaseValue
4
+ class Uint32Value < BaseValue
5
5
  DEFAULT_VALUES = {
6
6
  color_temperature: 50,
7
7
  lock_management_auto_security_timeout: 0,
@@ -1,7 +1,7 @@
1
1
  require_relative 'base_value'
2
2
 
3
3
  module RubyHome
4
- class Uint8DefaultValue < BaseValue
4
+ class Uint8Value < BaseValue
5
5
  def default
6
6
  first_default_value.to_i
7
7
  end
@@ -14,9 +14,9 @@ module RubyHome
14
14
 
15
15
  put '/' do
16
16
  json_body.fetch('characteristics', []).each do |characteristic_params|
17
- if characteristic_params['value']
17
+ if characteristic_params.key?("value")
18
18
  update_characteristics(characteristic_params)
19
- elsif characteristic_params['ev']
19
+ elsif characteristic_params.key?("ev")
20
20
  subscribe_characteristics(characteristic_params)
21
21
  end
22
22
  end
@@ -1,3 +1,3 @@
1
1
  module RubyHome
2
- VERSION = '0.1.12'
2
+ VERSION = '0.1.13'
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.12
4
+ version: 0.1.13
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-14 00:00:00.000000000 Z
11
+ date: 2018-11-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -278,14 +278,6 @@ files:
278
278
  - lib/ruby_home/dns/service.rb
279
279
  - lib/ruby_home/dns/text_record.rb
280
280
  - lib/ruby_home/factories/characteristic_factory.rb
281
- - lib/ruby_home/factories/default_values/base_value.rb
282
- - lib/ruby_home/factories/default_values/bool_value.rb
283
- - lib/ruby_home/factories/default_values/float_value.rb
284
- - lib/ruby_home/factories/default_values/int32_value.rb
285
- - lib/ruby_home/factories/default_values/null_value.rb
286
- - lib/ruby_home/factories/default_values/string_value.rb
287
- - lib/ruby_home/factories/default_values/uint32_value.rb
288
- - lib/ruby_home/factories/default_values/uint8_value.rb
289
281
  - lib/ruby_home/factories/service_factory.rb
290
282
  - lib/ruby_home/factories/templates/characteristic_template.rb
291
283
  - lib/ruby_home/factories/templates/service_template.rb
@@ -304,6 +296,14 @@ files:
304
296
  - lib/ruby_home/hap/server.rb
305
297
  - lib/ruby_home/hap/service.rb
306
298
  - lib/ruby_home/hap/tlv.rb
299
+ - lib/ruby_home/hap/values/base_value.rb
300
+ - lib/ruby_home/hap/values/bool_value.rb
301
+ - lib/ruby_home/hap/values/float_value.rb
302
+ - lib/ruby_home/hap/values/int32_value.rb
303
+ - lib/ruby_home/hap/values/null_value.rb
304
+ - lib/ruby_home/hap/values/string_value.rb
305
+ - lib/ruby_home/hap/values/uint32_value.rb
306
+ - lib/ruby_home/hap/values/uint8_value.rb
307
307
  - lib/ruby_home/hex_helper.rb
308
308
  - lib/ruby_home/http/application.rb
309
309
  - lib/ruby_home/http/controllers/accessories_controller.rb
@@ -1,15 +0,0 @@
1
- module RubyHome
2
- class BaseValue
3
- def initialize(template)
4
- @template = template
5
- end
6
-
7
- def default
8
- raise NotImplementedError
9
- end
10
-
11
- private
12
-
13
- attr_reader :template
14
- end
15
- end
@@ -1,9 +0,0 @@
1
- require_relative 'base_value'
2
-
3
- module RubyHome
4
- class BoolDefaultValue < BaseValue
5
- def default
6
- false
7
- end
8
- end
9
- end
@@ -1,9 +0,0 @@
1
- require_relative 'base_value'
2
-
3
- module RubyHome
4
- class NullDefaultValue < BaseValue
5
- def default
6
- nil
7
- end
8
- end
9
- end