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 +4 -4
- data/README.md +2 -2
- data/bin/ruby_home +1 -1
- data/lib/ruby_home/factories/characteristic_factory.rb +7 -12
- data/lib/ruby_home/hap/characteristic.rb +5 -3
- data/lib/ruby_home/hap/values/base_value.rb +28 -0
- data/lib/ruby_home/hap/values/bool_value.rb +20 -0
- data/lib/ruby_home/{factories/default_values → hap/values}/float_value.rb +1 -1
- data/lib/ruby_home/{factories/default_values → hap/values}/int32_value.rb +1 -1
- data/lib/ruby_home/hap/values/null_value.rb +17 -0
- data/lib/ruby_home/{factories/default_values → hap/values}/string_value.rb +1 -1
- data/lib/ruby_home/{factories/default_values → hap/values}/uint32_value.rb +1 -1
- data/lib/ruby_home/{factories/default_values → hap/values}/uint8_value.rb +1 -1
- data/lib/ruby_home/http/controllers/characteristics_controller.rb +2 -2
- data/lib/ruby_home/version.rb +1 -1
- metadata +10 -10
- data/lib/ruby_home/factories/default_values/base_value.rb +0 -15
- data/lib/ruby_home/factories/default_values/bool_value.rb +0 -9
- data/lib/ruby_home/factories/default_values/null_value.rb +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cbb486ea0b95baaee4388d69f2875024e941d7a79b2385f327f6cfb4639cc270
|
4
|
+
data.tar.gz: d451c724e41292c3899461951bcd337095404abd0c730744cd3bf863a58e9859
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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 ==
|
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 ==
|
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 ==
|
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
|
-
@
|
46
|
+
@requested_value = value
|
47
47
|
end
|
48
48
|
|
49
|
-
attr_reader :service, :characteristic_name, :
|
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
|
58
|
-
|
59
|
-
|
60
|
-
default_value = klass.new(template).default
|
57
|
+
def value
|
58
|
+
value_object.new(template, @requested_value)
|
59
|
+
end
|
61
60
|
|
62
|
-
|
63
|
-
|
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
|
-
|
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
|
@@ -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
|
17
|
+
if characteristic_params.key?("value")
|
18
18
|
update_characteristics(characteristic_params)
|
19
|
-
elsif characteristic_params
|
19
|
+
elsif characteristic_params.key?("ev")
|
20
20
|
subscribe_characteristics(characteristic_params)
|
21
21
|
end
|
22
22
|
end
|
data/lib/ruby_home/version.rb
CHANGED
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.
|
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-
|
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
|