home_assistant-generator 0.1.0.pre.alpha.pre.10 → 0.1.0.pre.alpha.pre.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +17 -0
- data/Rakefile +3 -3
- data/example_config.rb +16 -2
- data/home_assistant-generator.gemspec +9 -9
- data/lib/home_assistant/generator/component.rb +9 -8
- data/lib/home_assistant/generator/dsl.rb +31 -14
- data/lib/home_assistant/generator/properties.rb +22 -3
- data/lib/home_assistant/generator/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 22d3c600869a40dd7a3b5c67fe8224e8d0f5f110
|
4
|
+
data.tar.gz: 22d869bdfe2d224c73b45199fc657cc6108a6198
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0723602233c498fd153dc3b7aebea11496bc742fb29e1a76b122a120ae32a0d17762729925298705b70b1a9199d55d5b195b20ad06f9f86d337e6f0cc871f34a
|
7
|
+
data.tar.gz: a93f5ee3b4ba73712951e73760915d651868670b9242d1f34c43094b47fbc3cf9a1914a056fdbfb7dd8b2afe43c71d89e367fa2765eaae3453e4020d322215fe
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.3
|
3
|
+
|
4
|
+
Style/FrozenStringLiteralComment:
|
5
|
+
Enabled: false
|
6
|
+
|
7
|
+
Metrics/LineLength:
|
8
|
+
Max: 120
|
9
|
+
|
10
|
+
Metrics/MethodLength:
|
11
|
+
Max: 20
|
12
|
+
|
13
|
+
Metrics/AbcSize:
|
14
|
+
Enabled: false
|
15
|
+
|
16
|
+
Style/Documentation:
|
17
|
+
Enabled: false # not yet
|
data/Rakefile
CHANGED
data/example_config.rb
CHANGED
@@ -1,15 +1,29 @@
|
|
1
|
+
homeassistant 'home' do
|
2
|
+
longitude 2.3267746000000216
|
3
|
+
latitude 48.8264967
|
4
|
+
elevation 66
|
5
|
+
unit_system 'metric'
|
6
|
+
time_zone 'Europe/Paris'
|
7
|
+
customize('switch.capodimonte_led': { icon: 'mdi:led-variant-on' })
|
8
|
+
end
|
9
|
+
|
1
10
|
media_player 'KoKodi' do
|
2
11
|
platform :kodi
|
3
12
|
host 'http://192.168.0.13'
|
4
13
|
port 8080
|
5
14
|
end
|
6
15
|
|
16
|
+
sun
|
17
|
+
|
18
|
+
recorder do
|
19
|
+
purge_days 14
|
20
|
+
end
|
7
21
|
|
8
22
|
automation 'Activate movie playing scene' do
|
9
|
-
#trigger.when('KoKodi').from(:paused).to(:playing)
|
23
|
+
# trigger.when('KoKodi').from(:paused).to(:playing)
|
10
24
|
|
11
25
|
# Other examples
|
12
|
-
|
26
|
+
trigger.when('KoKodi').playing
|
13
27
|
# equivalent to:
|
14
28
|
# trigger.when('KoKodi').to(:playing)
|
15
29
|
|
@@ -4,23 +4,23 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'home_assistant/generator/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
7
|
+
spec.name = 'home_assistant-generator'
|
8
8
|
spec.version = HomeAssistant::Generator::VERSION
|
9
9
|
spec.version = "#{spec.version}-alpha-#{ENV['TRAVIS_BUILD_NUMBER']}" if ENV['TRAVIS']
|
10
10
|
spec.authors = ["Grégoire Seux"]
|
11
|
-
spec.email = [
|
11
|
+
spec.email = ['grego_homeassistant@familleseux.net']
|
12
12
|
|
13
|
-
spec.summary =
|
14
|
-
spec.license =
|
13
|
+
spec.summary = 'Helper to generate home-assistant configuration'
|
14
|
+
spec.license = 'Apache License v2'
|
15
15
|
|
16
16
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
-
spec.bindir =
|
17
|
+
spec.bindir = 'bin'
|
18
18
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
|
-
spec.require_paths = [
|
19
|
+
spec.require_paths = ['lib']
|
20
20
|
|
21
|
-
spec.add_development_dependency
|
22
|
-
spec.add_development_dependency
|
23
|
-
spec.add_development_dependency
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.11'
|
22
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
23
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
24
24
|
|
25
25
|
spec.add_runtime_dependency 'mash'
|
26
26
|
end
|
@@ -4,11 +4,12 @@ module HomeAssistant
|
|
4
4
|
module Generator
|
5
5
|
# generic home-assistant component
|
6
6
|
class Component
|
7
|
+
EMPTY_CONF_ALLOWED = %i(sun history logbook).freeze
|
8
|
+
|
7
9
|
prepend Properties
|
8
10
|
|
9
|
-
|
10
|
-
|
11
|
-
send(name_property, name)
|
11
|
+
def initialize(name = nil)
|
12
|
+
send(name_property, name) if name
|
12
13
|
end
|
13
14
|
|
14
15
|
def name_property
|
@@ -19,11 +20,11 @@ module HomeAssistant
|
|
19
20
|
super unless args.one?
|
20
21
|
|
21
22
|
properties[name.to_s] = case args.first
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
23
|
+
when Symbol
|
24
|
+
args.first.to_s
|
25
|
+
else
|
26
|
+
args.first
|
27
|
+
end
|
27
28
|
end
|
28
29
|
end
|
29
30
|
end
|
@@ -3,12 +3,30 @@ require 'yaml'
|
|
3
3
|
require_relative 'component'
|
4
4
|
require_relative 'automation'
|
5
5
|
|
6
|
+
module CamelCase
|
7
|
+
refine String do
|
8
|
+
def snake_case
|
9
|
+
gsub(/::/, '/')
|
10
|
+
.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
|
11
|
+
.gsub(/([a-z\d])([A-Z])/, '\1_\2')
|
12
|
+
.tr('-', '_')
|
13
|
+
.downcase
|
14
|
+
end
|
15
|
+
|
16
|
+
def camel_case
|
17
|
+
split('_').collect(&:capitalize).join
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
6
22
|
module HomeAssistant
|
7
23
|
module Generator
|
8
24
|
# dsl class to read config file and evaluate it
|
9
25
|
class DSL
|
10
26
|
attr_reader :component_list, :automations
|
11
27
|
|
28
|
+
using CamelCase
|
29
|
+
|
12
30
|
def initialize
|
13
31
|
@component_list = []
|
14
32
|
@automations = []
|
@@ -20,16 +38,14 @@ module HomeAssistant
|
|
20
38
|
end
|
21
39
|
|
22
40
|
def method_missing(name, *args, &block)
|
23
|
-
super unless args.one?
|
24
|
-
|
25
|
-
klass_name = name.to_s.
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
Component.new(*args).tap { |c| c.component_class = name }
|
32
|
-
end
|
41
|
+
super unless args.one? || Component::EMPTY_CONF_ALLOWED.include?(name) || block_given?
|
42
|
+
|
43
|
+
klass_name = name.to_s.camel_case
|
44
|
+
unless DSL.const_defined?(klass_name)
|
45
|
+
debug("No #{klass_name} class, defining dynamic class")
|
46
|
+
DSL.const_set(klass_name, Class.new(Component) {})
|
47
|
+
end
|
48
|
+
element = DSL.const_get(klass_name).new(*args)
|
33
49
|
component_list << element
|
34
50
|
element.instance_eval(&block) if block_given?
|
35
51
|
element
|
@@ -40,10 +56,11 @@ module HomeAssistant
|
|
40
56
|
end
|
41
57
|
|
42
58
|
def to_s
|
43
|
-
config = component_list.
|
44
|
-
|
45
|
-
|
46
|
-
|
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
|
63
|
+
end
|
47
64
|
end
|
48
65
|
|
49
66
|
config = config.merge('automation' => automations.map(&:to_h))
|
@@ -1,15 +1,31 @@
|
|
1
|
+
require 'mash'
|
2
|
+
|
1
3
|
class Hash
|
2
4
|
# reimplem of ruby 2.4 transform_values
|
3
5
|
if RUBY_VERSION < '2.4'
|
4
6
|
def transform_values
|
5
7
|
Hash[
|
6
|
-
|
8
|
+
map do |k, v|
|
7
9
|
[k, (yield v)]
|
8
10
|
end
|
9
11
|
]
|
10
12
|
end
|
11
13
|
end
|
12
14
|
end
|
15
|
+
|
16
|
+
class Mash
|
17
|
+
def to_h
|
18
|
+
keys.each_with_object({}) do |key, hash|
|
19
|
+
hash[key] = case self[key]
|
20
|
+
when Mash
|
21
|
+
self[key].to_h
|
22
|
+
else
|
23
|
+
self[key]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
13
29
|
module HomeAssistant
|
14
30
|
module Generator
|
15
31
|
# can be prepended by any class with properties hash
|
@@ -25,16 +41,19 @@ module HomeAssistant
|
|
25
41
|
has_to_h = ->(x) { x.respond_to?(:to_h) }
|
26
42
|
properties.transform_values do |value|
|
27
43
|
case value
|
28
|
-
when String,
|
44
|
+
when String, Numeric, TrueClass, FalseClass
|
29
45
|
value
|
30
46
|
when Symbol
|
31
47
|
value.to_s
|
48
|
+
when Hash
|
49
|
+
puts value.inspect
|
50
|
+
Mash.new(value).to_h
|
32
51
|
when has_to_h
|
33
52
|
value.to_h
|
34
53
|
when Array
|
35
54
|
raise NotImplementedError, 'should be implemented for arrays as well!'
|
36
55
|
else
|
37
|
-
raise "Can't convert #{value} to a hash"
|
56
|
+
raise "Can't convert #{value.inspect} to a hash"
|
38
57
|
end
|
39
58
|
end
|
40
59
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Grégoire Seux
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-02-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -76,6 +76,7 @@ extra_rdoc_files: []
|
|
76
76
|
files:
|
77
77
|
- ".gitignore"
|
78
78
|
- ".rspec"
|
79
|
+
- ".rubocop.yml"
|
79
80
|
- ".travis.yml"
|
80
81
|
- Gemfile
|
81
82
|
- LICENSE
|