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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 22d3c600869a40dd7a3b5c67fe8224e8d0f5f110
4
- data.tar.gz: 22d869bdfe2d224c73b45199fc657cc6108a6198
3
+ metadata.gz: fb0ed7625bc552cdd4966be0ce5e54b4760a05c4
4
+ data.tar.gz: eb05fbedd343a26d180f63c2619d75481000624e
5
5
  SHA512:
6
- metadata.gz: 0723602233c498fd153dc3b7aebea11496bc742fb29e1a76b122a120ae32a0d17762729925298705b70b1a9199d55d5b195b20ad06f9f86d337e6f0cc871f34a
7
- data.tar.gz: a93f5ee3b4ba73712951e73760915d651868670b9242d1f34c43094b47fbc3cf9a1914a056fdbfb7dd8b2afe43c71d89e367fa2765eaae3453e4020d322215fe
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.each_with_object({}) do |component, mem|
60
- component.class.name.split('::').last.snake_case.tap do |name|
61
- mem[name] ||= []
62
- mem[name] << component.to_h
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
 
@@ -46,7 +46,6 @@ module HomeAssistant
46
46
  when Symbol
47
47
  value.to_s
48
48
  when Hash
49
- puts value.inspect
50
49
  Mash.new(value).to_h
51
50
  when has_to_h
52
51
  value.to_h
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.11
4
+ version: 0.1.0.pre.alpha.pre.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Grégoire Seux