home_assistant-generator 0.1.0.pre.alpha.pre.11 → 0.1.0.pre.alpha.pre.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/home_assistant/generator/dsl.rb +19 -4
- data/lib/home_assistant/generator/properties.rb +0 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fb0ed7625bc552cdd4966be0ce5e54b4760a05c4
|
4
|
+
data.tar.gz: eb05fbedd343a26d180f63c2619d75481000624e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fa944d0f48f706cd55232a88a5ebfecb7f32c0f52b4ed0c99a99179d629cfa93ff0c526967ca9b079a3e187ae5147534abce8a64d4af5bffa0ae7238ff38efb5
|
7
|
+
data.tar.gz: 1b1d2a6afb2a0af9a1d4cb57c0039454285c5a3d087987da88ad5a95f3cb0349252e8e499177149ed6d9d4ff182a0e3309c1d9cc2c151add4eb402d9c8dfd001
|
@@ -19,6 +19,18 @@ module CamelCase
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
+
module IfEmpty
|
23
|
+
refine Hash do
|
24
|
+
def if_empty(default)
|
25
|
+
if empty?
|
26
|
+
default
|
27
|
+
else
|
28
|
+
self
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
22
34
|
module HomeAssistant
|
23
35
|
module Generator
|
24
36
|
# dsl class to read config file and evaluate it
|
@@ -26,6 +38,7 @@ module HomeAssistant
|
|
26
38
|
attr_reader :component_list, :automations
|
27
39
|
|
28
40
|
using CamelCase
|
41
|
+
using IfEmpty
|
29
42
|
|
30
43
|
def initialize
|
31
44
|
@component_list = []
|
@@ -56,10 +69,12 @@ module HomeAssistant
|
|
56
69
|
end
|
57
70
|
|
58
71
|
def to_s
|
59
|
-
config = component_list.
|
60
|
-
|
61
|
-
|
62
|
-
|
72
|
+
config = component_list.group_by { |component| component.class.name.split('::').last.snake_case }
|
73
|
+
.transform_values do |components|
|
74
|
+
if components.one?
|
75
|
+
components.first.to_h.if_empty(nil)
|
76
|
+
else
|
77
|
+
components.map(&:to_h)
|
63
78
|
end
|
64
79
|
end
|
65
80
|
|