home_assistant-generator 0.1.0.pre.alpha.pre.7 → 0.1.0.pre.alpha.pre.8

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: 5b6710fd1102ee7993244f1341dec7192f53cc71
4
- data.tar.gz: c2a27fd09dd2dddf2c3b7d05ea4e651c40c19010
3
+ metadata.gz: cf97a0d12c7f105117561c6e0b502cbad6dd1a3f
4
+ data.tar.gz: 4b444399b1ec740d7098ccff7fe12855f86bafd2
5
5
  SHA512:
6
- metadata.gz: a7d3399b25b23caa4ba7dc6098dafd0f26dc475d971624d884b6b4ed141df99eea4ca93d35a9e2cefb2e0ddae7f46b2c18c42db694a14c7769e5a19b8f910587
7
- data.tar.gz: 3abd0c3a30c9bf001672407091290d371b29462ff2f15a755b925b63697793571d2249321dead4a741717929d2f1f1a2147ab4c03e2aa866382a46f7c229c6a5
6
+ metadata.gz: 277d45c284966d5fb14949dda657bb4764df3a99a70fb50fa495618c4896f68caf7cd1cb3323a5a5be63d4e38fc57eeda6dab124611f70e4f709cb564c9731a5
7
+ data.tar.gz: 065109efbe395e7119372a03951838abdf5e86fbfefd092e2ec53563f56f6c5e992c19966c0384823eaff694cf45bc3eaa9679d8d19977ded1a52b4b005bc8a9
data/example_config.rb CHANGED
@@ -4,7 +4,21 @@ media_player 'KoKodi' do
4
4
  port 8080
5
5
  end
6
6
 
7
- #
8
- #automation 'Activate movie playing scene' do
9
- # trigger.when('KoKodi').state(to: 'playing')
10
- #end
7
+
8
+ automation 'Activate movie playing scene' do
9
+ trigger.when('KoKodi').from(:paused).to(:playing)
10
+
11
+ # Other examples
12
+ # trigger.when('KoKodi').playing
13
+ # equivalent to:
14
+ # trigger.when('KoKodi').to(:playing)
15
+
16
+ # trigger.at('18:00:00')
17
+ # trigger.when('sun').set
18
+ # trigger.on('my_event_name') # using platform 'event'
19
+ #
20
+ # Documentation:
21
+ # trigger.when('a component short name') creates a trigger on the component state. It is possible to call:
22
+ # from('old state') and to('new state') on it.
23
+ # It is also possible to call any method whose name is the new state, like .playing
24
+ end
@@ -0,0 +1,46 @@
1
+ module HomeAssistant
2
+ module Generator
3
+ # describe an automation from home-assistant
4
+ class Automation
5
+ attr_reader :properties
6
+
7
+ def initialize(name, &block)
8
+ @properties = {}
9
+ properties[:alias] = name
10
+ instance_eval(&block)
11
+ end
12
+
13
+ def trigger
14
+ properties[:trigger] ||= Trigger.new
15
+ properties[:trigger]
16
+ end
17
+
18
+ class Trigger
19
+ attr_reader :properties
20
+ def initialize
21
+ @properties = {}
22
+ end
23
+
24
+ def when(component_short_name)
25
+ # TODO: search for real entity_id
26
+ properties[:entity_id] = component_short_name
27
+ properties[:platform] = 'state'
28
+ self
29
+ end
30
+
31
+ def method_missing(name, *args)
32
+ case args.size
33
+ when 1
34
+ properties[name] = args.first
35
+ when 0
36
+ properties[:to] = name
37
+ else
38
+ super
39
+ end
40
+ self
41
+ end
42
+
43
+ end
44
+ end
45
+ end
46
+ end
@@ -2,15 +2,17 @@ require 'mash'
2
2
  require 'yaml'
3
3
 
4
4
  require_relative 'component'
5
+ require_relative 'automation'
5
6
 
6
7
  module HomeAssistant
7
8
  module Generator
8
9
  # dsl class to read config file and evaluate it
9
10
  class DSL
10
- attr_reader :component_list
11
+ attr_reader :component_list, :automations
11
12
 
12
13
  def initialize
13
14
  @component_list = []
15
+ @automations = []
14
16
  end
15
17
 
16
18
  def eval(file_path)
@@ -33,16 +35,24 @@ module HomeAssistant
33
35
  element
34
36
  end
35
37
 
36
- def debug(message)
37
- $stderr.puts message if ENV['DEBUG']
38
+ def automation(name, &block)
39
+ Automation.new(name, &block).tap { automations << automation }
38
40
  end
39
41
 
40
42
  def to_s
41
- component_list.inject(Mash.new) do |mem, component|
43
+ config = component_list.inject(Mash.new) do |mem, component|
42
44
  mem[component.component_class] ||= []
43
45
  mem[component.component_class] << component.to_h
44
46
  mem
45
- end.to_hash.to_yaml
47
+ end
48
+
49
+ config.to_hash.to_yaml
50
+ end
51
+
52
+ private
53
+
54
+ def debug(message)
55
+ $stderr.puts message if ENV['DEBUG']
46
56
  end
47
57
  end
48
58
  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.7
4
+ version: 0.1.0.pre.alpha.pre.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Grégoire Seux
@@ -85,6 +85,7 @@ files:
85
85
  - example_config.rb
86
86
  - home_assistant-generator.gemspec
87
87
  - lib/home_assistant/generator.rb
88
+ - lib/home_assistant/generator/automation.rb
88
89
  - lib/home_assistant/generator/component.rb
89
90
  - lib/home_assistant/generator/dsl.rb
90
91
  - lib/home_assistant/generator/version.rb