home_assistant-generator 0.1.0.pre.alpha.pre.8 → 0.1.0.pre.alpha.pre.10
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
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 56be305faa1ef040a0690afb8911bee8719066f9
|
4
|
+
data.tar.gz: b111391114c8bb8143f68a2edf41fc4181d366c3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 44d2df897c33d0ddbbba4c61f7434abb7c6d4f4eb8eb473e694a46b0ee3e016405f2abc5cd140bf15891d090c859b7f83ea489b2723f9037fa20aac7b14f6c2b
|
7
|
+
data.tar.gz: da98eca2a2f46f0631df65e981e357da2c60bf044762f6c89c558e1361c733fb05cdf6e4718e65fe21c5eb56345f4f34c78d6c88a234c1dea61c8d9933615ab2
|
data/example_config.rb
CHANGED
@@ -6,10 +6,10 @@ end
|
|
6
6
|
|
7
7
|
|
8
8
|
automation 'Activate movie playing scene' do
|
9
|
-
trigger.when('KoKodi').from(:paused).to(:playing)
|
9
|
+
#trigger.when('KoKodi').from(:paused).to(:playing)
|
10
10
|
|
11
11
|
# Other examples
|
12
|
-
|
12
|
+
trigger.when('KoKodi').playing
|
13
13
|
# equivalent to:
|
14
14
|
# trigger.when('KoKodi').to(:playing)
|
15
15
|
|
@@ -1,45 +1,53 @@
|
|
1
|
+
require_relative 'properties'
|
2
|
+
|
1
3
|
module HomeAssistant
|
2
4
|
module Generator
|
3
5
|
# describe an automation from home-assistant
|
4
6
|
class Automation
|
5
|
-
|
7
|
+
prepend Properties
|
6
8
|
|
7
9
|
def initialize(name, &block)
|
8
|
-
|
9
|
-
properties[:alias] = name
|
10
|
+
properties['alias'] = name
|
10
11
|
instance_eval(&block)
|
11
12
|
end
|
12
13
|
|
13
14
|
def trigger
|
14
|
-
properties[
|
15
|
-
properties[
|
15
|
+
properties['trigger'] ||= Trigger.new
|
16
|
+
properties['trigger']
|
16
17
|
end
|
17
18
|
|
18
19
|
class Trigger
|
19
|
-
|
20
|
+
prepend Properties
|
21
|
+
attr_reader :sub
|
20
22
|
def initialize
|
21
|
-
@
|
23
|
+
@sub = nil
|
22
24
|
end
|
23
25
|
|
24
26
|
def when(component_short_name)
|
25
27
|
# TODO: search for real entity_id
|
26
|
-
properties[
|
27
|
-
properties[
|
28
|
-
|
28
|
+
properties['entity_id'] = component_short_name
|
29
|
+
properties['platform'] = 'state'
|
30
|
+
@sub = State.new(properties)
|
31
|
+
@sub
|
29
32
|
end
|
30
33
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
properties[name] = args.first
|
35
|
-
when 0
|
36
|
-
properties[:to] = name
|
37
|
-
else
|
38
|
-
super
|
34
|
+
class State
|
35
|
+
def initialize(properties)
|
36
|
+
@properties = properties
|
39
37
|
end
|
40
|
-
self
|
41
|
-
end
|
42
38
|
|
39
|
+
def method_missing(name, *args)
|
40
|
+
case args.size
|
41
|
+
when 1
|
42
|
+
@properties[name.to_s] = args.first
|
43
|
+
when 0
|
44
|
+
@properties['to'] = name
|
45
|
+
else
|
46
|
+
super
|
47
|
+
end
|
48
|
+
self
|
49
|
+
end
|
50
|
+
end
|
43
51
|
end
|
44
52
|
end
|
45
53
|
end
|
@@ -1,13 +1,13 @@
|
|
1
|
-
|
1
|
+
require_relative 'properties'
|
2
2
|
|
3
3
|
module HomeAssistant
|
4
4
|
module Generator
|
5
5
|
# generic home-assistant component
|
6
6
|
class Component
|
7
|
-
|
7
|
+
prepend Properties
|
8
|
+
|
8
9
|
attr_accessor :component_class
|
9
10
|
def initialize(name)
|
10
|
-
@properties = Mash.new
|
11
11
|
send(name_property, name)
|
12
12
|
end
|
13
13
|
|
@@ -15,14 +15,10 @@ module HomeAssistant
|
|
15
15
|
:name
|
16
16
|
end
|
17
17
|
|
18
|
-
def to_h
|
19
|
-
properties.to_hash
|
20
|
-
end
|
21
|
-
|
22
18
|
def method_missing(name, *args)
|
23
19
|
super unless args.one?
|
24
20
|
|
25
|
-
properties[name.
|
21
|
+
properties[name.to_s] = case args.first
|
26
22
|
when Symbol
|
27
23
|
args.first.to_s
|
28
24
|
else
|
@@ -1,4 +1,3 @@
|
|
1
|
-
require 'mash'
|
2
1
|
require 'yaml'
|
3
2
|
|
4
3
|
require_relative 'component'
|
@@ -15,8 +14,9 @@ module HomeAssistant
|
|
15
14
|
@automations = []
|
16
15
|
end
|
17
16
|
|
18
|
-
def eval(file_path)
|
19
|
-
instance_eval(File.read(file_path), file_path)
|
17
|
+
def eval(file_path = nil, &block)
|
18
|
+
instance_eval(File.read(file_path), file_path) if file_path
|
19
|
+
instance_eval(&block) if block_given?
|
20
20
|
end
|
21
21
|
|
22
22
|
def method_missing(name, *args, &block)
|
@@ -36,17 +36,18 @@ module HomeAssistant
|
|
36
36
|
end
|
37
37
|
|
38
38
|
def automation(name, &block)
|
39
|
-
Automation.new(name, &block).tap { automations <<
|
39
|
+
Automation.new(name, &block).tap { |auto| automations << auto }
|
40
40
|
end
|
41
41
|
|
42
42
|
def to_s
|
43
|
-
config = component_list.inject(
|
44
|
-
mem[component.component_class] ||= []
|
45
|
-
mem[component.component_class] << component.to_h
|
43
|
+
config = component_list.inject({}) do |mem, component|
|
44
|
+
mem[component.component_class.to_s] ||= []
|
45
|
+
mem[component.component_class.to_s] << component.to_h
|
46
46
|
mem
|
47
47
|
end
|
48
48
|
|
49
|
-
config.
|
49
|
+
config = config.merge('automation' => automations.map(&:to_h))
|
50
|
+
config.to_h.to_yaml
|
50
51
|
end
|
51
52
|
|
52
53
|
private
|
@@ -0,0 +1,43 @@
|
|
1
|
+
class Hash
|
2
|
+
# reimplem of ruby 2.4 transform_values
|
3
|
+
if RUBY_VERSION < '2.4'
|
4
|
+
def transform_values
|
5
|
+
Hash[
|
6
|
+
self.map do |k, v|
|
7
|
+
[k, (yield v)]
|
8
|
+
end
|
9
|
+
]
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
module HomeAssistant
|
14
|
+
module Generator
|
15
|
+
# can be prepended by any class with properties hash
|
16
|
+
module Properties
|
17
|
+
attr_reader :properties
|
18
|
+
|
19
|
+
def initialize(*args)
|
20
|
+
@properties = {}
|
21
|
+
super
|
22
|
+
end
|
23
|
+
|
24
|
+
def to_h
|
25
|
+
has_to_h = ->(x) { x.respond_to?(:to_h) }
|
26
|
+
properties.transform_values do |value|
|
27
|
+
case value
|
28
|
+
when String, Integer, TrueClass, FalseClass
|
29
|
+
value
|
30
|
+
when Symbol
|
31
|
+
value.to_s
|
32
|
+
when has_to_h
|
33
|
+
value.to_h
|
34
|
+
when Array
|
35
|
+
raise NotImplementedError, 'should be implemented for arrays as well!'
|
36
|
+
else
|
37
|
+
raise "Can't convert #{value} to a hash"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: home_assistant-generator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.0.pre.alpha.pre.
|
4
|
+
version: 0.1.0.pre.alpha.pre.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Grégoire Seux
|
@@ -88,6 +88,7 @@ files:
|
|
88
88
|
- lib/home_assistant/generator/automation.rb
|
89
89
|
- lib/home_assistant/generator/component.rb
|
90
90
|
- lib/home_assistant/generator/dsl.rb
|
91
|
+
- lib/home_assistant/generator/properties.rb
|
91
92
|
- lib/home_assistant/generator/version.rb
|
92
93
|
homepage:
|
93
94
|
licenses:
|