ladder_drive 0.6.5 → 0.6.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9b8a4c3fda62348e4b5e414860c9f3e9b26c962c
4
- data.tar.gz: ed8bdb8780a0ba01078c741457b9c40e769c4743
3
+ metadata.gz: 4b731ff279520977d619483b357253a15205272c
4
+ data.tar.gz: a4c34a0845a577d90863425fe580dc88de6b35c9
5
5
  SHA512:
6
- metadata.gz: 4d66f4ebbfc6ca268290c4915419b8413c71595bab618e45b3e52f0c470a6e1e8a6ab669179c232b5559b5e7d9ff3b52a2d7e0951488fe51f0536a82633d1179
7
- data.tar.gz: 2fc3b6a350452c327c1e8d8336cd61812028f7f682e6ad74e84ee2a93cc751beb44666635aced2604c21d1581563680d4a64c62219cf8f571389893afe93d02f
6
+ metadata.gz: 5e905098c2fb5bc0ec527cce4ebf9987f1ebfd8dbf1957766034b29357f80e051186afbf41ad76b391d7d64caa798ce385038afec52013f8cfe143ebb1f6dbe7
7
+ data.tar.gz: 6c7e458870f0c73f5383dcd2ca46fbc5480f214892a9fb7ee0d840db16af15c1f30c9f965e86109e66d917b748902d83c1e5b02019da7f7f557a83768613573f
@@ -54,11 +54,23 @@ module LadderDrive
54
54
  desc "plugin", "Install the specified plugin."
55
55
  def plugin(name)
56
56
  root_dir = File.expand_path(File.join(File.dirname(__FILE__), "..", ".."))
57
- plugins_path = File.join(root_dir, "plugins")
58
- path = File.join(plugins_path, "#{name}_plugin.rb")
59
- if File.exist? path
57
+
58
+ # copy plugin
59
+ plugins_dir = File.join(root_dir, "plugins")
60
+ plugin_path = File.join(plugins_dir, "#{name}_plugin.rb")
61
+ if File.exist? plugin_path
60
62
  mkdir_p "plugins"
61
- cp path, "plugins/#{name}_plugin.rb"
63
+ cp plugin_path, "plugins/#{name}_plugin.rb"
64
+ end
65
+
66
+ # copy sample settings
67
+ config_dir = File.join(plugins_dir, "config")
68
+ config_path = File.join(config_dir, "#{name}.yaml.example")
69
+ if File.exist? config_path
70
+ dst_dir = "config/plugins"
71
+ mkdir_p dst_dir
72
+ dst_path = "config/plugins/#{name}.yaml.example"
73
+ cp config_path, dst_path unless File.exist? dst_path
62
74
  end
63
75
  end
64
76
 
@@ -22,5 +22,5 @@
22
22
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
23
 
24
24
  module LadderDrive
25
- VERSION = "0.6.5"
25
+ VERSION = "0.6.6"
26
26
  end
@@ -0,0 +1,34 @@
1
+ # This is a sample setting for ambient plugin
2
+ # Copy this file to ambient.yaml or rename.
3
+
4
+ # If you want to disable this plugin, uncomment it.
5
+ #disable: true
6
+
7
+ # Configure ambient channels
8
+ # Set the Ambient channel, which is to send data you want to.
9
+ channels:
10
+
11
+ # set ambient configuration.
12
+ # We recommend setting write_key from an environment variable.
13
+ - channel_id: 12824
14
+ write_key: <%= ENV['AMBIENT_WRITE_KEY'] %>
15
+
16
+ # Set trigger conditions
17
+ # You can use type raise, fall, raise_and_fall, changed, and interval.
18
+ triggers:
19
+ - type: raise_and_fall
20
+ device: M100
21
+ - type: interval
22
+ interval: 60
23
+
24
+ # Set data to send, if triggered.
25
+ devices:
26
+ d1:
27
+ device: D10
28
+ value_type: value
29
+ d2:
30
+ device: D11
31
+ value_type: value
32
+ d3:
33
+ device: D12
34
+ value_type: value
@@ -0,0 +1,39 @@
1
+ # This is a sample setting for google drive plugin
2
+ # Copy this file to google_drive.yaml or rename.
3
+
4
+ # If you want to disable this plugin, uncomment it.
5
+ #disable: true
6
+
7
+ # Api configuration.
8
+ client_id: <%= ENV['GOOGLE_CLIENT_ID'] %>
9
+ client_secret: <%= ENV['GOOGLE_CLIENT_SECRET'] %>
10
+ access_token: <%= ENV['GOOGLE_ACCESS_TOKEN'] %>
11
+ refresh_token: <%= ENV['GOOGLE_REFRESH_TOKEN'] %>
12
+
13
+ # Logging setting
14
+ loggings:
15
+ - name: temperature
16
+
17
+ # Set trigger conditions
18
+ # You can use type raise, fall, raise_and_fall, changed, and interval.
19
+ trigger:
20
+ device: M0
21
+ type: raise_and_fall
22
+ value_type: bool
23
+
24
+ # Column header
25
+ columns: D0,D1,D2,D3,D4,D5,D6,D7,D8,D9,D20,M0
26
+
27
+ # Devices for logging
28
+ devices:
29
+ - device: D0-D9
30
+ type: value
31
+ - device: D20
32
+ type: value
33
+ - device: M0
34
+ type: bool
35
+
36
+ # Spreadsheet to access
37
+ spread_sheet:
38
+ spread_sheet_key: <%= ENV['GOOGLE_SPREADSHEET_KEY'] %>
39
+ sheet_no: 0
@@ -0,0 +1,24 @@
1
+ # This is a sample setting for ifttt plugin
2
+ # Copy this file to ifttt.yaml or rename.
3
+
4
+ # If you want to disable this plugin, uncomment it.
5
+ #disable: true
6
+
7
+ # Set webhook key of Webhooks service for IFTTT.
8
+ # To see your webhook key, to open https://ifttt.com/maker_webhook
9
+ # and click the Documentation link.
10
+ # We recommend setting web_hook_key from an environment variable.
11
+ web_hook_key: <%= ENV['IFTTT_WEBHOOK_KEY'] %>
12
+
13
+ # Set trigger event of webhook.
14
+ # Set event name to name attribute.
15
+ # Pass values to the params to display information.
16
+ events:
17
+ - name: rubyworldconference2019
18
+ trigger:
19
+ type: raise
20
+ device: M100
21
+ params:
22
+ value1: Abnormal temperature
23
+ value2: Something additional information.
24
+ value3: and more.
@@ -0,0 +1,36 @@
1
+ # This is a sample setting for Plc mapper plugin
2
+ # Copy this file to plc_mapper.yaml or rename.
3
+
4
+ # If you want to disable this plugin, uncomment it.
5
+ #disable: true
6
+
7
+ # This is a sample setting for Plc mapper plugin
8
+ plcs:
9
+ - description: Machine A-123
10
+
11
+ # Set connection conditions between PLC
12
+ protocol: mc_protocol
13
+ host: 192.168.1.10
14
+ port: 5010
15
+ interval: 10
16
+
17
+ # Set address mapping.
18
+ mapping:
19
+
20
+ # Read from PLC to set Ladder drive.
21
+ # plc: PLC address area
22
+ # ld: Ladder drive area
23
+ read:
24
+ - plc: M1000-M1099
25
+ ld: M0
26
+ - plc: D1000-D1099
27
+ ld: D0
28
+ # Read from Ladder drive to set PLC.
29
+ # plc: PLC address area
30
+ # ld: Ladder drive area
31
+ write:
32
+ # LadderDrive address: PLC address
33
+ - plc: M100-M199
34
+ ld: M1100
35
+ - plc: D100-D199
36
+ ld: D1100
@@ -0,0 +1,36 @@
1
+ # This is a sample setting for Slack plugin
2
+ # Copy this file to slack.yaml or rename.
3
+
4
+ # If you want to disable this plugin, uncomment it.
5
+ #disable: true
6
+
7
+ # Define comment for a device
8
+ device_comments:
9
+ M210: Full error
10
+ D10: Running
11
+
12
+ # Event setting
13
+ events:
14
+
15
+ # Set webhook url for IFTTT.
16
+ # We recommend setting web_hook_key from an environment variable.
17
+ - webhook_url: <%= ENV['SLACK_WEBHOOK_NOTIFICATION_URL'] %>
18
+
19
+ # Set trigger conditions
20
+ # You can use type raise, fall, raise_and_fall, changed, and interval.
21
+ trigger:
22
+ type: raise_and_fall
23
+
24
+ # String format to send Slack.
25
+ format:
26
+ raise: __device_comment__ has occurred at __time__ .
27
+ fall: __device_comment__ was reset at __time__ .
28
+ devices: M210
29
+
30
+ - webhook_url: <%= ENV['SLACK_WEBHOOK_URL'] %>
31
+ trigger:
32
+ type: raise_and_fall
33
+ format:
34
+ raise: Start __device_comment__ at __time__ .
35
+ fall: Stop __device_comment__ at __time__ .
36
+ devices: M100
@@ -0,0 +1,41 @@
1
+ # This is a sample setting for Trello plugin
2
+ # Copy this file to trello.yaml or rename.
3
+
4
+ # If you want to disable this plugin, uncomment it.
5
+ #disable: true
6
+
7
+ # Connection configuration.
8
+ consumer_key: <%= ENV['TRELLO_CONSUMER_KEY'] %>
9
+ consumer_secret: <%= ENV['TRELLO_CONSUMMER_SECRET'] %>
10
+ oauth_token: <%= ENV['TRELLO_OAUTH_TOKEN'] %>
11
+
12
+ events:
13
+
14
+ # Set trigger conditions
15
+ # You can use type raise, fall, raise_and_fall, changed, and interval.
16
+ - trigger:
17
+ device: M100
18
+ type: raise
19
+
20
+ # Board name
21
+ board_name: Floor 1
22
+ # List name.
23
+ # If you set it, move the card into this list.
24
+ list_name: RUNNING
25
+ # Card name.
26
+ card_name: Machine A
27
+
28
+ # color label
29
+ color:
30
+ # Add color label
31
+ add: green
32
+
33
+ - trigger:
34
+ device: M100
35
+ type: fall
36
+ board_name: Floor 1
37
+ list_name: STOPPING
38
+ card_name: Machine A
39
+ color:
40
+ # Remove color label
41
+ remove: green
@@ -90,6 +90,7 @@ class SlackPlugin < Plugin
90
90
  v = nil
91
91
  case event[:trigger][:type]
92
92
  when "interval"
93
+
93
94
  t = @times[event.object_id] || now
94
95
  triggered = t <= now
95
96
  if triggered
@@ -97,7 +98,7 @@ class SlackPlugin < Plugin
97
98
  t += event[:trigger][:interval] || 300
98
99
  @times[event.object_id] = t
99
100
  end
100
- v = device.send event[:value_type] || :device, event[:trigger][:text_length] || 8
101
+ v = device.send event[:value_type] || :value, event[:trigger][:text_length] || 8
101
102
  else
102
103
  v = device.send event[:value_type] || :value, event[:text_length] || 8
103
104
  unless @values[device.name] == v
@@ -149,7 +150,15 @@ puts $@
149
150
  req["Content-Type"] = "application/json"
150
151
 
151
152
  format = event[:format] || "__comment__ occured at __time__"
152
- format = arg[:value] ? format[:raise] : format[:fall] unless format.is_a? String
153
+ case format
154
+ when Hash
155
+ case arg[:value]
156
+ when false, nil, 0
157
+ format = format[:fall]
158
+ else
159
+ format = format[:interval] || format[:raise]
160
+ end
161
+ end
153
162
 
154
163
  device_name = arg[:device_name]
155
164
  comment = @comments[device_name] || device_name
@@ -102,6 +102,11 @@ puts $@
102
102
  }
103
103
  end
104
104
 
105
+ def label_in_board_with_color board, color
106
+ l = board.labels.find{|l| l.name == color}
107
+ l ||= Trello::Label.create board_id:board.id, name:color, color:color
108
+ end
109
+
105
110
  def thread_proc
106
111
  while arg = @worker_queue.pop
107
112
  begin
@@ -114,16 +119,23 @@ puts $@
114
119
  card_name.gsub!(/__value__/, arg[:value] || "") if arg[:value].is_a? String
115
120
  next if (card_name || "").empty?
116
121
 
117
- list_name = event[:list_name]
118
- next unless list_name
119
- list = board.lists.find{|l| l.name == list_name}
120
- next unless list
121
-
122
- card = board.lists.map{|l| l.cards.map{|c| c}}.flatten.find{|c| c.name == card_name}
123
- if card
124
- card.move_to_list list
125
- else
126
- card = Trello::Card.create name:card_name, list_id:list.id
122
+ card = board.cards.find{|c| c.name == card_name}
123
+ card ||= Trello::Card.create name:card_name
124
+
125
+ # move card into a list
126
+ list = board.lists.find{|l| l.name == event[:list_name]} if event[:list_name]
127
+ card.move_to_list list if list
128
+
129
+ # set color label
130
+ if event[:color]
131
+ if event[:color][:add]
132
+ label = label_in_board_with_color board, event[:color][:add]
133
+ card.add_label label
134
+ end
135
+ if event[:color][:remove]
136
+ label = label_in_board_with_color board, event[:color][:remove]
137
+ card.remove_label label
138
+ end
127
139
  end
128
140
 
129
141
  rescue => e
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ladder_drive
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.5
4
+ version: 0.6.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Katsuyoshi Ito
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-10-21 00:00:00.000000000 Z
11
+ date: 2019-11-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -279,6 +279,12 @@ files:
279
279
  - lib/plc/raspberrypi/raspberrypi_plc_server.rb
280
280
  - plugins/ambient_plugin.rb
281
281
  - plugins/blank_plugin.rb
282
+ - plugins/config/ambient.yaml.example
283
+ - plugins/config/google_drive.yaml.example
284
+ - plugins/config/ifttt.yaml.example
285
+ - plugins/config/plc_mapper.yaml.example
286
+ - plugins/config/slack.yaml.example
287
+ - plugins/config/trello.yaml.example
282
288
  - plugins/google_drive_plugin.rb
283
289
  - plugins/ifttt_plugin.rb
284
290
  - plugins/plc_mapper_plugin.rb