brewer 0.0.70 → 0.0.71

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: 2c655c6d8ba7ce57f7c070c08ab1e91522bfbaca
4
- data.tar.gz: 00e256b45d4a5c69d90f162e72a4204a00c8fbcf
3
+ metadata.gz: dd9b1df8720156b66f88424e65d7ebd530440ecf
4
+ data.tar.gz: 98e6e8df275b44be023a37cff481fced3ac20888
5
5
  SHA512:
6
- metadata.gz: 4a1c5a24b3fcd10c61699c07581e0e9a61d59b26ddc18f17e413f4998a2e28b2444d181655ce2ad73e61b2d267085eb5603f0cfbbcc205815a997c63a5faa0ac
7
- data.tar.gz: 012545ecda2b43f92014e6bbc226c6ec767e0461639a192f9220803f70d5ea8eeb4239fab439146e80683308ebc5c1445b497a36c0cbdeeec334177fe66cc1f7
6
+ metadata.gz: a6d1f4a460c83ee94be5ec03fdcba1460c2fcdd196409412c5b690e9032ea2977b15f869995a36a62f9c8da1d8cf73b2c61f410d3642eae7249e97e2244a3ab2
7
+ data.tar.gz: 2163b804379374756c9ed1161bca468dae3993ae3cd079d6da16474cec2150b36ce8c6c6d9dda858c9eddafe0665c65403059e3c75e9cb17b378079e7f6a1425
data/bin/brewer CHANGED
@@ -1,17 +1,10 @@
1
1
  #!/usr/bin/env ruby
2
- # This executable will start a Ripl shell with a 'brewer' and 'adaptibrew' objects
2
+ require_relative "../lib/autoload"
3
3
 
4
- require 'ripl'
5
-
6
- require_relative "../lib/adaptibrew"
7
- require_relative "../lib/brewer"
8
- require_relative "../lib/helpers"
9
-
10
- include Helpers
11
-
12
- # Refresh to make sure we have the lastest version of adaptibrew
13
4
  brewer = Brewer.new
14
5
  adaptibrew = Adaptibrew.new.refresh
6
+ com = Communicator.new
7
+ procedures = Procedures.new
15
8
 
16
9
  puts "🍺 have fun 🍺"
17
10
  Ripl.start :binding => binding
@@ -2,7 +2,7 @@ require 'rake'
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "brewer"
5
- s.version = "0.0.70"
5
+ s.version = "0.0.71"
6
6
  s.default_executable = "brewer"
7
7
 
8
8
  s.authors = ["Luke Sweeney"]
@@ -24,7 +24,11 @@ Gem::Specification.new do |s|
24
24
  s.add_runtime_dependency 'git', '~> 1.3', '>= 1.3.0'
25
25
  s.add_runtime_dependency 'ripl', '~> 0.7.0'
26
26
  s.add_runtime_dependency 'net-ping', '~> 1.7'
27
+ s.add_runtime_dependency 'wannabe_bool', '~> 1.7'
27
28
  s.add_runtime_dependency 'slack-notifier'
29
+ s.add_runtime_dependency 'require_all'
30
+ s.add_runtime_dependency 'terminal-table'
31
+
28
32
 
29
33
  # Dev dependencies
30
34
  s.add_development_dependency 'rake', '~> 12.0', '>= 12.0.0'
@@ -1,8 +1,4 @@
1
- require 'git'
2
- require 'fileutils'
3
- require_relative 'helpers'
4
-
5
- include Helpers
1
+ require_relative "autoload"
6
2
 
7
3
  # This is the 'manager' for the adaptibrew repo. It handles cloning and such.
8
4
  class Adaptibrew
@@ -0,0 +1,14 @@
1
+ require "require_all"
2
+ require 'git'
3
+ require 'fileutils'
4
+ require 'slack-notifier'
5
+ require 'yaml'
6
+ require 'yaml/store'
7
+ require 'net/ping'
8
+ require 'ripl'
9
+ require 'wannabe_bool'
10
+ require 'terminal-table'
11
+
12
+ require_all 'lib'
13
+
14
+ include Helpers
@@ -1,20 +1,14 @@
1
- # TODO: Test monitor method
2
- require_relative 'helpers'
3
- require_relative 'adaptibrew'
4
- require_relative 'settings'
5
-
6
- include Helpers
1
+ require_relative "autoload"
7
2
 
8
3
  class Brewer
9
4
 
10
5
  attr_reader :base_path
11
- attr_accessor :out, :log, :temps
6
+ attr_accessor :out, :temps
12
7
 
13
8
  def initialize
14
9
  @base_path = Dir.home + '/.brewer'
15
10
  # Output of adaptibrew
16
11
  @out = []
17
- @log = @base_path + '/logs/output'
18
12
  @temps = {}
19
13
  end
20
14
 
@@ -24,23 +18,10 @@ class Brewer
24
18
  # general utilities for the brewer class
25
19
 
26
20
  def wait(time=30)
27
- sleep(time)
21
+ sleep(time.to_f)
28
22
  true
29
23
  end
30
24
 
31
- # Sends a slack message in #brewing
32
- def ping(message="ping at #{Time.now}")
33
- require_relative 'slacker'
34
- $slack.ping(message)
35
- end
36
-
37
- # Only works on Mac :(
38
- # :nocov:
39
- def say(message="done")
40
- system("say #{message}")
41
- end
42
- # :nocov:
43
-
44
25
  # Runs an adaptibrew script
45
26
  # Output will be stored in @out
46
27
  # you may see `echo` quite a bit. This will almost always be directly after calling a script
@@ -50,31 +31,22 @@ class Brewer
50
31
  @out.first
51
32
  end
52
33
 
53
- # Clears the @out array
54
- # Writes current @out to log
55
34
  def clear
56
35
  @out = []
57
36
  end
58
37
 
59
- # This lil' divider is default for large return blocks
60
- def echo(string=nil)
61
- if string == nil
62
- puts @out.first
63
- return @out.first
64
- end
65
- puts string
66
- return string
67
- end
68
-
69
-
70
38
  # Adaptibrew methods ----------------------------------------------
71
39
  # for working with the rig
72
40
 
73
- def pump(state=0)
41
+ def pump(state="status")
42
+ if state == "status"
43
+ return relay_status($settings['pumpRelay'])
44
+ end
45
+
74
46
  if state == 1
75
47
  return script("set_pump_on")
76
- elsif state == 0
77
- if pid['pid_running'] == "True"
48
+ else
49
+ if pid['pid_running'].to_b
78
50
  pid(0)
79
51
  echo
80
52
  end
@@ -96,27 +68,30 @@ class Brewer
96
68
  script('set_pid_on')
97
69
  pump(1)
98
70
  return "Pump and PID are now on"
99
- elsif state == 0
71
+ else
100
72
  return script("set_pid_off")
101
73
  end
102
74
  end
103
75
 
104
76
  def sv(temp=nil)
105
77
  if temp
106
- raise "Temperature input needs to be an integer" unless temp.is_a? Integer
107
- return script('set_sv', temp)
108
- else
109
- return script('get_sv')
78
+ return script('set_sv', temp).to_f
110
79
  end
80
+ script('get_sv').to_f
111
81
  end
112
82
 
113
83
  def pv
114
- return script('get_pv')
84
+ script('get_pv').to_f
115
85
  end
116
86
 
117
87
  def relay(relay, state)
88
+ # If you try to turn the relay to a state that it is already in, this skips the wait
89
+ if relay_status(relay).to_b == state.to_b
90
+ return true
91
+ end
118
92
  script("set_relay", "#{relay} #{state}")
119
93
  wait(10)
94
+ true
120
95
  end
121
96
 
122
97
  def all_relays_status
@@ -126,59 +101,24 @@ class Brewer
126
101
  true
127
102
  end
128
103
 
129
- # TODO: Fix the return value here
130
104
  def relay_status(relay)
131
- raise "Relay number needs to be an integer" unless relay.is_a? Integer
132
105
  script("get_relay_status", "#{relay}")
133
- return @out.first.split('\n')
134
- end
135
-
136
- # :nocov:
137
- def watch
138
- until pv.to_f >= sv.to_f do
139
- wait(8)
140
- end
141
- true
142
- end
143
- # :nocov:
144
-
145
- def monitor
146
- while true do
147
- ping("#{puts pid}")
148
- wait(10)
106
+ if @out.include? "on"
107
+ return "on"
108
+ else
109
+ return "off"
149
110
  end
150
111
  end
151
112
 
152
- # WaterVolInQuarts, GrainMassInPounds, GrainTemp, MashTemp
153
113
  # :nocov:
154
- def get_strike_temp
155
- print "Input amount of water in quarts: "
156
- water = gets.chomp
157
-
158
- print "Input amount of grain in lbs: "
159
- grain = gets.chomp
160
-
161
- print "Input current grain temp (#{pv}): "
162
- grain_temp = gets.chomp
163
- if grain_temp == ""
164
- grain_temp = pv.to_i
165
- end
166
-
167
- print "Input desired mash temp (150): "
168
- desired_mash_temp = gets.chomp
169
- if desired_mash_temp == ""
170
- desired_mash_temp = 150
114
+ def watch
115
+ until pv >= sv do
116
+ wait(2)
171
117
  end
172
- @temps['desired_mash'] = desired_mash_temp
173
-
174
- # this is where the magic happens
175
- @temps['strike_water_temp'] = script('get_strike_temp', "#{water} #{grain} #{grain_temp} #{desired_mash_temp}")
176
- sv(echo.to_i)
177
- puts "SV has been set to #{sv} degrees"
118
+ self
178
119
  end
179
120
  # :nocov:
180
121
 
181
- # Relays ----------
182
122
  def rims_to(location)
183
123
  if location == "mash"
184
124
  # we ended up swapping this relay, so the name is backwards
@@ -186,7 +126,7 @@ class Brewer
186
126
  elsif location == "boil"
187
127
  relay($settings['rimsToMashRelay'], 1)
188
128
  end
189
- true
129
+ self
190
130
  end
191
131
 
192
132
  def hlt_to(location)
@@ -195,221 +135,16 @@ class Brewer
195
135
  elsif location == "boil"
196
136
  relay($settings['spargeToMashRelay'], 1)
197
137
  end
198
- true
138
+ self
199
139
  end
200
140
 
201
141
  def hlt(state)
202
- if state == "open"
142
+ if state.to_b
203
143
  relay($settings['spargeRelay'], 1)
204
- elsif state == "close"
144
+ elsif !state.to_b
205
145
  relay($settings['spargeRelay'], 0)
206
146
  end
207
- true
208
- end
209
-
210
- # Master Procedures -----------------------------------------------------
211
- # The main steps in the brewing proccess
212
- def boot
213
- # These are the states required for starting. Should be called on boot.
214
- # Print PID status at end
215
- ping("booting...")
216
- pid(0)
217
- pump(0)
218
- rims_to('mash')
219
- hlt_to('mash')
220
- all_relays_status
221
- puts pid
222
-
223
- clear
224
- puts "Boot successful!"
225
- @out.unshift("successful boot at #{Time.now}")
226
- ping("🍺 boot successful 🍺")
227
- true
228
- end
229
-
230
- # :nocov:
231
- def heat_strike_water
232
- puts "heat-strike-water procedure started"
233
- # Confirm strike water is in the mash tun
234
- print "Is the strike water in the mash tun? "
235
- # -> response
236
- confirm ? nil : abort
237
-
238
- # confirm return manifold is in the mash tun
239
- print "Is the return manifold in the mash tun? "
240
- # -> response
241
- confirm ? nil : abort
242
-
243
- print "Is the mash tun valve open? "
244
- confirm ? nil : abort
245
-
246
- # confirm RIMS relay is on
247
- rims_to('mash')
248
- puts "RIMS-to-mash relay is now on"
249
-
250
- # turn on pump
251
- pump(1)
252
- puts "Pump is now on"
253
-
254
- # wait ~30 seconds
255
- print "How long do you want to wait for the water to start circulating? (30) "
256
- time = gets.chomp
257
- if time == ""
258
- time = 30
259
- end
260
- puts "Waiting for #{time} seconds for strike water to start circulating"
261
- puts "(ctrl-c to exit proccess now)"
262
- wait(time.to_i)
263
-
264
- # confirm that strike water is circulating well
265
- print "Is the strike water circulating well? "
266
- # -> response
267
- confirm ? nil : abort
268
-
269
-
270
- # calculate strike temp & set PID to strike temp
271
- # this sets PID SV to calculated strike temp automagically
272
- get_strike_temp
273
- # turn on RIMS heater
274
- pid(1)
275
-
276
- # measure current strike water temp and save
277
- @temps['starting_strike_temp'] = pv.to_i
278
- puts "current strike water temp is #{pv}. Saved."
279
- puts "Heating to #{sv}"
280
-
281
- ping("Strike water beginning to heat. This may take a few minutes.")
282
-
283
- # when strike temp is reached, ping slack
284
- watch
285
- ping("Strike water heated to #{pv}. Maintaining temperature.")
286
- ping("Next step: dough in")
287
- puts "Next step: dough in"
288
- puts "command: brewer.dough_in"
289
-
290
- true
291
- end
292
- # :nocov:
293
-
294
- def dough_in
295
- ping("dough-in procedure started")
296
- puts "dough-in procedure started"
297
- # turn pump off
298
- # turn PID off
299
- pump(0)
300
- ping("Ready to dough in")
301
- puts "Ready to dough in"
302
-
303
- print "Confirm when you're done with dough-in (y): "
304
- confirm ? nil : abort
305
-
306
- ping("next step: mash")
307
- puts "Next step: mash"
308
- puts "command: brewer.mash"
309
- # pour in grain
310
- true
311
- end
312
-
313
- def mash
314
- print "Enter mash temperature (#{@temps['desired_mash'].to_s} F): "
315
- temp = gets.chomp
316
-
317
- if temp != ""
318
- @temps['desired_mash'] = temp.to_i
319
- end
320
-
321
- sv(@temps['desired_mash'])
322
-
323
- print "Enter mash time in seconds (3600 seconds for 1 hour). This timer will start once mash temp has been reached: "
324
- mash_time_input = gets.chomp
325
-
326
- puts "This will take a while. You'll get a slack message next time you need to do something."
327
- ping("Mash started. This will take a while. You'll get a slack message next time you need to do something.")
328
-
329
- if mash_time_input == ""
330
- mash_time = 3600
331
- else
332
- mash_time = mash_time_input.to_i
333
- end
334
-
335
- rims_to('mash')
336
-
337
- pump(1)
338
- pid(1)
339
-
340
- watch
341
- ping("Mash temp (#{pv} F) reached. Starting timer for #{mash_time} seconds. You'll get a slack message next time you need to do something.")
342
- puts "Mash temp (#{pv} F) reached. Starting timer for #{mash_time} seconds. You'll get a slack message next time you need to do something."
343
- wait(mash_time)
344
- ping("🍺 Mash complete 🍺. Check for starch conversion. Next step: mashout")
345
- puts "Mash complete"
346
- puts "Check for starch conversion"
347
- puts "next step: mashout"
348
- puts "command: brewer.mashout"
349
- end
350
-
351
- def mashout
352
- puts "mashout procedure started"
353
-
354
- print "Enter mashout temp (172 F): "
355
- mashout_temp_input = gets.chomp
356
-
357
- ping("Start heating sparge water")
358
-
359
- if mashout_temp_input == ""
360
- mashout_temp = 172.0
361
- else
362
- mashout_temp == mashout_temp_input.to_f
363
- end
364
-
365
- sv(mashout_temp)
366
-
367
- pump(1)
368
- pid(1)
369
-
370
- ping("Heating to #{sv}... this could take a few minutes.")
371
- watch
372
- ping("Mashout temperature (#{pv}) reached. Mashout complete.")
373
- end
374
-
375
- def sparge
376
- print "Is the sparge water heated to the correct temperature? "
377
- confirm ? nil : abort
378
-
379
- hlt_to('mash')
380
- hlt('open')
381
-
382
- puts "Waiting for 30 seconds. Regulate sparge balance."
383
- puts "(ctrl-c to abort proccess)"
384
- wait(30)
385
-
386
- rims_to('boil')
387
- pump(1)
388
-
389
- ping("Please check the sparge balance and ignite boil tun burner")
390
-
391
- puts "Waiting until intervention to turn off pump (y): "
392
- confirm ? nil : abort
393
-
394
- pid(0)
395
- pump(0)
396
-
397
- hlt('close')
398
-
399
- ping("Sparge complete")
400
- end
401
-
402
- def top_off
403
- hlt_to('boil')
404
-
405
- hlt('open')
406
-
407
- print "waiting for intervention to turn off hlt (y): "
408
- confirm ? nil : abort
409
-
410
- hlt('close')
411
-
412
- ping('Topping off completed')
147
+ self
413
148
  end
414
149
 
415
150
  end
@@ -0,0 +1,66 @@
1
+ require_relative "autoload"
2
+
3
+ class Communicator
4
+
5
+ attr_accessor :slack, :brewer
6
+
7
+ def initialize
8
+ @slack = configure_slack
9
+ @brewer = Brewer.new
10
+ end
11
+
12
+ def configure_slack
13
+ slack_file = Dir.home + "/.brewer/.slack.yml"
14
+ if !File.file?(slack_file)
15
+ store = YAML::Store.new slack_file
16
+ print "Enter your Slack webhook url: "
17
+ webhook_url = gets.chomp
18
+ store.transaction { store['webhook_url'] = webhook_url }
19
+ end
20
+ return Slack::Notifier.new YAML.load(File.open(slack_file))['webhook_url']
21
+ end
22
+
23
+ def ping(message="ping at #{Time.now}")
24
+ if message.is_a? Array
25
+ final = message.join("\n")
26
+ @slack.ping(final)
27
+ end
28
+ @slack.ping(message)
29
+ end
30
+
31
+ # TODO: test these methods
32
+ def slack_monitor(delay=10)
33
+ while true do
34
+ before_temp = @brewer.pv
35
+ @brewer.wait(to_seconds(delay))
36
+ diff = @brewer.pv - before_temp
37
+
38
+ ping([
39
+ "Current Temperature: #{@brewer.pid['pv_temp']} F",
40
+ "Set Value Temperature: #{@brewer.pid['sv_temp']} F",
41
+ "Current temperature has climed #{diff} F since #{delay} minute(s) ago",
42
+ "Sent at #{Time.now.strftime("%H:%M")}",
43
+ ""
44
+ ])
45
+ end
46
+ true
47
+ end
48
+
49
+ def monitor
50
+ while true do
51
+ status_table_rows = [
52
+ ["Current Temp", @brewer.pv],
53
+ ["Set Value Temp", @brewer.sv],
54
+ ["PID is: ", @brewer.pid['pid_running'].to_b ? "on" : "off"],
55
+ ["Pump is: ", @brewer.pump]
56
+ ]
57
+
58
+ status_table = Terminal::Table.new :headings ["Item", "Status"], :rows => status_table_rows
59
+
60
+ clear_screen
61
+ puts status_table
62
+ sleep(1)
63
+ end
64
+ end
65
+
66
+ end
@@ -1,11 +1,7 @@
1
- require 'net/ping'
1
+ require_relative "autoload"
2
2
 
3
3
  module Helpers
4
4
 
5
- def log
6
- Dir.pwd + '/logs/output'
7
- end
8
-
9
5
  # Formatted as: 03/07/2017 14:26
10
6
  def time
11
7
  Time.now.strftime("%m/%d/%Y %H:%M")
@@ -16,22 +12,23 @@ module Helpers
16
12
  connection.ping?
17
13
  end
18
14
 
19
- def clear_log(log)
20
- File.truncate(log, 0)
15
+ def confirm(input=gets.chomp)
16
+ if input.to_b
17
+ return true
18
+ end
19
+ false
21
20
  end
22
21
 
23
- def write_log(log, lines)
24
- File.open(log, 'a') do |file|
25
- lines.each do |line|
26
- file.puts "[#{time}]: #{line}"
27
- end
28
- end
22
+ def to_minutes(seconds)
23
+ seconds.to_f / 60
29
24
  end
30
25
 
31
- def confirm(input=gets.chomp)
32
- if ["y", "Y", "yes", "Yes", "YES", "k"].include? input
33
- true
34
- end
26
+ def to_seconds(minutes)
27
+ minutes.to_f * 60
28
+ end
29
+
30
+ def clear_screen
31
+ Gem.win_platform? ? (system "cls") : (system "clear")
35
32
  end
36
33
 
37
34
  end
@@ -0,0 +1,243 @@
1
+ require_relative "autoload"
2
+
3
+ include Helpers
4
+
5
+ class Procedures
6
+
7
+ attr_accessor :com, :brewer, :recipe
8
+
9
+ def initialize
10
+ @brewer = Brewer.new
11
+ @com = Communicator.new
12
+ @recipe = {}
13
+ end
14
+
15
+ def get_recipe_vars
16
+ puts "Variables for heating strike water ---"
17
+ get_strike_temp
18
+
19
+ puts "Variables for mash ---"
20
+ print "Enter mash temperature: "
21
+ @recipe['mash_temp'] = gets.chomp.to_f
22
+ print "Enter mash time in minutes: "
23
+ @recipe['mash_time'] = to_seconds(gets.chomp.to_f)
24
+
25
+ puts "Variables for mashout ---"
26
+ print "Enter mashout temp: "
27
+ @recipe['mashout_temp'] = gets.chomp.to_f
28
+ end
29
+
30
+ def get_strike_temp
31
+ print "Input amount of water in quarts: "
32
+ @recipe['water'] = gets.chomp.to_f
33
+
34
+ print "Input amount of grain in lbs: "
35
+ @recipe['grain'] = gets.chomp.to_f
36
+
37
+ print "Input current grain temp (#{pv.to_s} F): "
38
+ @recipe['grain_temp'] = gets.chomp.to_f
39
+ if @recipe['grain_temp'] == ""
40
+ @recipe['grain_temp'] = pv
41
+ end
42
+
43
+ print "Input desired mash temp (150 F): "
44
+ @recipe['desired_mash_temp'] = gets.chomp
45
+ if @recipe['desired_mash_temp'] == ""
46
+ @recipe['desired_mash_temp'] = 150
47
+ end
48
+ @recipe['desired_mash_temp']
49
+
50
+ @recipe['strike_water_temp'] = script('get_strike_temp', "#{water} #{grain} #{grain_temp} #{@recipe['desired_mash_temp']}").to_f
51
+ end
52
+
53
+ def master
54
+ get_recipe_vars
55
+ boot
56
+ heat_strike_water
57
+ dough_in
58
+ mash
59
+ mashout
60
+ sparge
61
+ top_off
62
+ boil
63
+ end
64
+
65
+ def boot
66
+ puts "booting..."
67
+ @brewer.pid(0)
68
+ @brewer.pump(0)
69
+ @brewer.rims_to('mash')
70
+ @brewer.hlt_to('mash')
71
+ @brewer.all_relays_status
72
+ puts @brewer.pid
73
+
74
+ @brewer.clear
75
+ puts "Boot successful!"
76
+ @brewer.out.unshift("successful boot at #{Time.now}")
77
+ @com.ping("🍺 boot successful 🍺")
78
+ true
79
+ end
80
+
81
+ # :nocov:
82
+ def heat_strike_water
83
+ puts "heat-strike-water procedure started"
84
+
85
+ # Confirm strike water is in the mash tun
86
+ print "Is the strike water in the mash tun? "
87
+ # -> response
88
+ confirm ? nil : abort
89
+
90
+ # confirm return manifold is in the mash tun
91
+ print "Is the return manifold in the mash tun? "
92
+ # -> response
93
+ confirm ? nil : abort
94
+
95
+ print "Is the mash tun valve open? "
96
+ confirm ? nil : abort
97
+
98
+ # confirm RIMS relay is on
99
+ @brewer.rims_to('mash')
100
+ puts "RIMS-to-mash relay is now on"
101
+
102
+ # turn on pump
103
+ @brewer.pump(1)
104
+ puts "Pump is now on"
105
+
106
+ puts "Is the pump running properly? "
107
+ until confirm
108
+ puts "restarting pump"
109
+ @brewer.pump(0)
110
+ @brewer.wait(2)
111
+ @brewer.pump(1)
112
+ end
113
+
114
+ # confirm that strike water is circulating well
115
+ print "Is the strike water circulating well? "
116
+ # -> response
117
+ confirm ? nil : abort
118
+
119
+
120
+ # calculate strike temp & set PID to strike temp
121
+ # this sets PID SV to calculated strike temp automagically
122
+ @brewer.sv(@recipe['strike_water_temp'])
123
+ puts "SV has been set to calculated strike water temp"
124
+ # turn on RIMS heater
125
+ @brewer.pid(1)
126
+
127
+ # measure current strike water temp and save
128
+ @recipe['starting_strike_temp'] = @brewer.pv
129
+ puts "current strike water temp is #{@brewer.pv}. Saved."
130
+ puts "Heating to #{@brewer.sv}"
131
+
132
+ @com.ping("Strike water beginning to heat. This may take a few minutes.")
133
+
134
+ # when strike temp is reached, @com.ping slack
135
+ @brewer.watch
136
+ @com.ping("Strike water heated to #{@brewer.pv}. Maintaining temperature.")
137
+ @com.ping("Next step: dough in")
138
+ puts "Next step: dough in"
139
+ puts "command: brewer.dough_in"
140
+
141
+ true
142
+ end
143
+ # :nocov:
144
+
145
+ def dough_in
146
+ # turn pump off
147
+ @brewer.pump(0)
148
+ # turn PID off
149
+ @brewer.pid(0)
150
+ @brewer.wait(3)
151
+ @com.ping("Ready to dough in")
152
+ puts "Ready to dough in"
153
+
154
+ # pour in grain
155
+
156
+ print "Confirm when you're done with dough-in (y): "
157
+ confirm ? nil : abort
158
+ true
159
+ end
160
+
161
+ def mash
162
+ @brewer.sv(@recipe['mash_temp'])
163
+
164
+ puts "mash stated. This will take a while."
165
+ @com.ping("Mash started. This will take a while.")
166
+
167
+ @brewer.rims_to('mash')
168
+
169
+ @brewer.pump(1)
170
+ @brewer.pid(1)
171
+
172
+ @brewer.watch
173
+ @com.ping("Mash temp (#{@brewer.pv} F) reached. Starting timer for #{@recipe['mash_time']} minutes.")
174
+ @brewer.wait(@recipe['mash_time'])
175
+ @com.ping("🍺 Mash complete 🍺. Check for starch conversion.")
176
+ puts "Mash complete"
177
+ puts "Check for starch conversion"
178
+ end
179
+
180
+ def mashout
181
+ @com.ping("Start heating sparge water")
182
+
183
+ @brewer.sv(@recipe['mashout_temp'])
184
+
185
+ @brewer.pump(1)
186
+ @brewer.pid(1)
187
+
188
+ @com.ping("Heating to #{@brewer.sv}... this could take a few minutes.")
189
+ @brewer.watch
190
+ @com.ping("Mashout temperature (#{@brewer.pv}) reached. Mashout complete.")
191
+ end
192
+
193
+ def sparge
194
+ print "Is the sparge water heated to the correct temperature? "
195
+ confirm ? nil : abort
196
+
197
+ @brewer.hlt_to('mash')
198
+ @brewer.hlt(1)
199
+
200
+ puts "Waiting for 10 seconds. Regulate sparge balance."
201
+ puts "(ctrl-c to abort proccess)"
202
+ @brewer.wait(30)
203
+
204
+ @brewer.rims_to('boil')
205
+ @brewer.pump(1)
206
+
207
+ @com.ping("Please check the sparge balance and ignite boil tun burner")
208
+
209
+ puts "Waiting until intervention to turn off pump (y): "
210
+ confirm ? nil : abort
211
+
212
+ @brewer.pid(0)
213
+ @brewer.pump(0)
214
+
215
+ @brewer.hlt(0)
216
+ end
217
+
218
+ def top_off
219
+ @brewer.hlt_to('boil')
220
+
221
+ @brewer.hlt(1)
222
+
223
+ print "waiting for intervention to turn off hlt (y): "
224
+ confirm ? nil : abort
225
+
226
+ @brewer.hlt(0)
227
+
228
+ @com.ping('Topping off completed')
229
+ end
230
+
231
+ def boil
232
+ @com.ping("starting boil procedure")
233
+ @brewer.wait(to_seconds(5))
234
+ @com.ping("Add boil hops")
235
+ @brewer.wait(to_seconds(40))
236
+ @com.ping("Add flovering hops")
237
+ @brewer.wait(to_seconds(13))
238
+ @com.ping("Add finishing hops")
239
+ @brewer.wait(30)
240
+ @com.ping("All done")
241
+ end
242
+
243
+ end
@@ -1,5 +1,4 @@
1
- # This just parses the adaptibrew/settings.py
2
- require 'adaptibrew'
1
+ require_relative "autoload"
3
2
 
4
3
  adaptibrew = Adaptibrew.new
5
4
 
@@ -0,0 +1,16 @@
1
+ class roles:
2
+ Brewer:
3
+ - Directly control each component of the physical brew rig
4
+
5
+ Procedures:
6
+ - compile brewer methods into scripted procedures
7
+
8
+ Helpers:
9
+ - assorted methods, helpers module
10
+
11
+ Adaptibrew:
12
+ - Clone and maintain the adaptibrew directory
13
+
14
+ Communicator:
15
+ - Communicates the status of the brew rig
16
+ - Communicates actions the brew rig is doing/actions that the brewer class does
@@ -10,14 +10,6 @@ describe Brewer do
10
10
  Adaptibrew.new.refresh
11
11
  end
12
12
 
13
- after :all do
14
- # in case something goes wrong, everything needs to be reset
15
- @brewer = Brewer.new
16
- @brewer.pump(0)
17
- @brewer.pid(0)
18
- @brewer.boot
19
- end
20
-
21
13
  describe "#new" do
22
14
  it "returns a brewer object" do
23
15
  expect(Brewer.new).to be_an_instance_of Brewer
@@ -32,9 +24,9 @@ describe Brewer do
32
24
  it "can wait for a number of seconds" do
33
25
  # not using let(:current_time) etc. because
34
26
  # the var is created upon the first calling, which is in the expect()
35
- current_time = Time.now.to_i
27
+ current_time = Time.now.to_f
36
28
  @brewer.wait(1)
37
- expect(current_time + 1).to eq(Time.now.to_i)
29
+ expect(current_time + 1).to eq(Time.now.to_f)
38
30
  end
39
31
  end
40
32
 
@@ -57,100 +49,4 @@ describe Brewer do
57
49
  end
58
50
  end
59
51
 
60
- describe ".pump" do
61
- # If the pump is already on it does nothing
62
- it "turns the pump on" do
63
- expect(@brewer.pump(1)).to eq("pump on")
64
- @brewer.wait(2)
65
- end
66
-
67
- # If the pump is already off it does nothing
68
- it "turns the pump off" do
69
- expect(@brewer.pump(0)).to eq("pump off")
70
- end
71
-
72
- # cant really test this one...
73
- context "when the pid is also on" do
74
- # This turns on both pump and pid
75
- before { @brewer.pid(1) }
76
- it "turns the pump and pid off" do
77
- expect(@brewer.pump(0)).to eq("pump off")
78
- end
79
- end
80
- end
81
-
82
- describe ".relay" do
83
- it "turns the relay on" do
84
- expect(@brewer.relay(2, 1)).to eq("relay 2 on")
85
- @brewer.wait(7)
86
- end
87
-
88
- it "turns the relay off" do
89
- expect(@brewer.relay(2, 0)).to eq("relay 2 off")
90
- @brewer.wait(7)
91
- end
92
- end
93
-
94
- describe ".pid" do
95
- it "turns the pid on" do
96
- expect(@brewer.pid(1)).to eq("Pump and PID are now on")
97
- @brewer.wait(2)
98
- end
99
-
100
- it "turns the pid off" do
101
- expect(@brewer.pid(0)).to eq("PID off")
102
- end
103
-
104
- it "returns the pid status" do
105
- expect(@brewer.pid).to be_an_instance_of Hash
106
- end
107
- end
108
-
109
- describe ".sv" do
110
- context "when there is no argument" do
111
- it "returns the sv temp" do
112
- expect(@brewer.sv).to be_an_instance_of String
113
- end
114
- end
115
-
116
- context "when there is an argument" do
117
- it "sets the sv temp" do
118
- expect(@brewer.sv(150)).to be_an_instance_of String
119
- end
120
- end
121
- end
122
-
123
- describe ".pv" do
124
- it "returns the pv" do
125
- expect(@brewer.pv).to be_an_instance_of String
126
- end
127
- end
128
-
129
- describe ".ping" do
130
- it "pings slack" do
131
- expect(@brewer.ping("Tests are passing :D")).to be_an_instance_of Net::HTTPOK
132
- end
133
- end
134
-
135
- describe ".echo" do
136
- context "when there is an argument" do
137
- it "prints the arg" do
138
- expect(@brewer.echo("just part of a test")).to eq("just part of a test")
139
- end
140
- end
141
-
142
- context "when there is no argument" do
143
- before { @brewer.pv }
144
- it "prints the last output" do
145
- expect(@brewer.echo).to be_an_instance_of String
146
- end
147
- end
148
- end
149
-
150
- describe ".relay_status" do
151
- it "returns the status of a relay" do
152
- expect(@brewer.relay_status($settings['rimsToMashRelay'].to_i)).not_to be_empty
153
- end
154
- end
155
-
156
52
  end
@@ -0,0 +1,95 @@
1
+ require_relative 'spec_helper'
2
+
3
+ describe Brewer do
4
+ before :each do
5
+ @brewer = Brewer.new
6
+ end
7
+
8
+ before :all do
9
+ Adaptibrew.new.refresh
10
+ end
11
+
12
+ after :all do
13
+ # in case something goes wrong, everything needs to be reset
14
+ @brewer = Brewer.new
15
+ @brewer.pump(0)
16
+ @brewer.pid(0)
17
+ @brewer.boot
18
+ end
19
+
20
+ describe ".pump" do
21
+ # If the pump is already on it does nothing
22
+ it "turns the pump on" do
23
+ expect(@brewer.pump(1)).to eq("pump on")
24
+ @brewer.wait(2)
25
+ end
26
+
27
+ # If the pump is already off it does nothing
28
+ it "turns the pump off" do
29
+ expect(@brewer.pump(0)).to eq("pump off")
30
+ end
31
+
32
+ # cant really test this one...
33
+ context "when the pid is also on" do
34
+ # This turns on both pump and pid
35
+ before { @brewer.pid(1) }
36
+ it "turns the pump and pid off" do
37
+ expect(@brewer.pump(0)).to eq("pump off")
38
+ end
39
+ end
40
+ end
41
+
42
+ describe ".relay" do
43
+ it "turns the relay on" do
44
+ expect(@brewer.relay(2, 1)).to eq("relay 2 on")
45
+ @brewer.wait(7)
46
+ end
47
+
48
+ it "turns the relay off" do
49
+ expect(@brewer.relay(2, 0)).to eq("relay 2 off")
50
+ @brewer.wait(7)
51
+ end
52
+ end
53
+
54
+ describe ".pid" do
55
+ it "turns the pid on" do
56
+ expect(@brewer.pid(1)).to eq("Pump and PID are now on")
57
+ @brewer.wait(2)
58
+ end
59
+
60
+ it "turns the pid off" do
61
+ expect(@brewer.pid(0)).to eq("PID off")
62
+ end
63
+
64
+ it "returns the pid status" do
65
+ expect(@brewer.pid).to be_an_instance_of Hash
66
+ end
67
+ end
68
+
69
+ describe ".sv" do
70
+ context "when there is no argument" do
71
+ it "returns the sv temp" do
72
+ expect(@brewer.sv).to be_an_instance_of String
73
+ end
74
+ end
75
+
76
+ context "when there is an argument" do
77
+ it "sets the sv temp" do
78
+ expect(@brewer.sv(150)).to be_an_instance_of String
79
+ end
80
+ end
81
+ end
82
+
83
+ describe ".pv" do
84
+ it "returns the pv" do
85
+ expect(@brewer.pv).to be_an_instance_of String
86
+ end
87
+ end
88
+
89
+ describe ".relay_status" do
90
+ it "returns the status of a relay" do
91
+ expect(@brewer.relay_status($settings['rimsToMashRelay'].to_i)).not_to be_empty
92
+ end
93
+ end
94
+
95
+ end
@@ -4,12 +4,6 @@ include Helpers
4
4
 
5
5
  describe "Helpers" do
6
6
 
7
- describe "#log" do
8
- it "returns the log file path" do
9
- expect(log).to eq(Dir.pwd + '/logs/output')
10
- end
11
- end
12
-
13
7
  describe "#time" do
14
8
  it "can return the date/time" do
15
9
  # This might not be consistent???
@@ -19,26 +13,6 @@ describe "Helpers" do
19
13
  end
20
14
  end
21
15
 
22
- describe "#write_log and #clear_log" do
23
- context "when the log is empty" do
24
- before { clear_log(log) }
25
- specify { expect(File.zero?(log)).to be true }
26
- it "can write to the log" do
27
- write_log(log, ['log entry'])
28
- expect(File.zero?(log)).to be false
29
- end
30
- end
31
-
32
- context "when the log is not empty" do
33
- write_log(log, ['log entry'])
34
- specify { expect(File.zero?(log)).to be false }
35
- it "can clear the log" do
36
- clear_log(log)
37
- expect(File.zero?(log)).to be true
38
- end
39
- end
40
- end
41
-
42
16
  describe "#confirm" do
43
17
  it "should return true" do
44
18
  expect(confirm('y')).to be true
@@ -5,7 +5,4 @@ require 'simplecov'
5
5
  SimpleCov.command_name 'RSpec'
6
6
  SimpleCov.start
7
7
 
8
- require_relative '../lib/adaptibrew.rb'
9
- require_relative '../lib/brewer.rb'
10
- require_relative '../lib/helpers.rb'
11
- require_relative '../lib/settings.rb'
8
+ require_relative "../lib/autoload"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: brewer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.70
4
+ version: 0.0.71
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luke Sweeney
@@ -58,6 +58,20 @@ dependencies:
58
58
  - - "~>"
59
59
  - !ruby/object:Gem::Version
60
60
  version: '1.7'
61
+ - !ruby/object:Gem::Dependency
62
+ name: wannabe_bool
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '1.7'
68
+ type: :runtime
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '1.7'
61
75
  - !ruby/object:Gem::Dependency
62
76
  name: slack-notifier
63
77
  requirement: !ruby/object:Gem::Requirement
@@ -72,6 +86,34 @@ dependencies:
72
86
  - - ">="
73
87
  - !ruby/object:Gem::Version
74
88
  version: '0'
89
+ - !ruby/object:Gem::Dependency
90
+ name: require_all
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ type: :runtime
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ - !ruby/object:Gem::Dependency
104
+ name: terminal-table
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ type: :runtime
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
75
117
  - !ruby/object:Gem::Dependency
76
118
  name: rake
77
119
  requirement: !ruby/object:Gem::Requirement
@@ -194,12 +236,16 @@ files:
194
236
  - bin/brewer
195
237
  - brewer.gemspec
196
238
  - lib/adaptibrew.rb
239
+ - lib/autoload.rb
197
240
  - lib/brewer.rb
241
+ - lib/communicator.rb
198
242
  - lib/helpers.rb
243
+ - lib/procedures.rb
199
244
  - lib/settings.rb
200
- - lib/slacker.rb
245
+ - notes.md
201
246
  - spec/adaptibrew_spec.rb
202
247
  - spec/brewer_spec.rb
248
+ - spec/hardware_spec.rb
203
249
  - spec/helpers_spec.rb
204
250
  - spec/settings_spec.rb
205
251
  - spec/spec_helper.rb
@@ -231,6 +277,7 @@ summary: A shell interface for adaptibrew
231
277
  test_files:
232
278
  - spec/adaptibrew_spec.rb
233
279
  - spec/brewer_spec.rb
280
+ - spec/hardware_spec.rb
234
281
  - spec/helpers_spec.rb
235
282
  - spec/settings_spec.rb
236
283
  - spec/spec_helper.rb
@@ -1,31 +0,0 @@
1
- require 'slack-notifier'
2
- require 'yaml'
3
- require 'yaml/store'
4
-
5
- slack_file = Dir.home + "/.brewer/.slack.yml"
6
-
7
- if !File.file?(slack_file)
8
-
9
- # this will create the file if it doesn't exists, which it doesn't in this context
10
- store = YAML::Store.new slack_file
11
-
12
- # you can get this from your slack app integrations page
13
- print "Enter your Slack webhook url: "
14
- webhook_url = gets.chomp
15
-
16
- # This just stores the webhook_url so you only have to enter it once
17
- store.transaction do
18
- store['webhook_url'] = webhook_url
19
- end
20
-
21
- # Here's a comment in .slack.yml so if you find it by accident you'll know what it does
22
- File.open(slack_file, 'a') do |file|
23
- file.puts "# This is the slack configuration file for the brewer gem"
24
- file.puts "# You can delete this file and brewer will re-create it on start-up"
25
- end
26
- end
27
-
28
-
29
- # finally, start up a global variable for the brewer class to use
30
- # A full `Slacker` class is not needed, since this only does one thing
31
- $slack = Slack::Notifier.new YAML.load(File.open(slack_file))['webhook_url']