brewer 0.0.83 → 0.0.89

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.
@@ -1,67 +1,69 @@
1
1
  require_relative "../brewer"
2
2
 
3
- class Communicator
3
+ module Brewer
4
+ class Communicator
4
5
 
5
- attr_accessor :slack, :brewer
6
+ attr_accessor :slack, :brewer
6
7
 
7
- def initialize
8
- @settings = Settings.new
9
- @brewer = Brewer.new
10
- @slack = configure_slack
11
- end
8
+ def initialize
9
+ @settings = Settings.new
10
+ @brewer = Brewer.new
11
+ @slack = configure_slack
12
+ end
12
13
 
13
- def configure_slack
14
- unless @settings.settings['webhook_url']
15
- print "Slack Webhook URL: "
16
- webhook_url = gets.chomp
17
- @settings.add({
18
- 'webhook_url' => webhook_url
19
- })
14
+ def configure_slack
15
+ unless @settings.settings['webhook_url']
16
+ print "Slack Webhook URL: "
17
+ webhook_url = gets.chomp
18
+ @settings.add({
19
+ 'webhook_url' => webhook_url
20
+ })
21
+ end
22
+ return Slack::Notifier.new @settings.settings['webhook_url']
20
23
  end
21
- return Slack::Notifier.new @settings.settings['webhook_url']
22
- end
23
24
 
24
- def ping(message="ping at #{Time.now}")
25
- if message.is_a? Array
26
- final = message.join("\n")
27
- @slack.ping(final)
25
+ def ping(message="ping at #{Time.now}")
26
+ if message.is_a? Array
27
+ final = message.join("\n")
28
+ @slack.ping(final)
29
+ end
30
+ @slack.ping(message)
28
31
  end
29
- @slack.ping(message)
30
- end
31
32
 
32
- # TODO: test these methods
33
- def slack_monitor(delay=10)
34
- while true do
35
- before_temp = @brewer.pv
36
- @brewer.wait(to_seconds(delay))
37
- diff = @brewer.pv - before_temp
33
+ # TODO: test these methods
34
+ def slack_monitor(delay=10)
35
+ while true do
36
+ before_temp = @brewer.pv
37
+ @brewer.wait(to_seconds(delay))
38
+ diff = @brewer.pv - before_temp
38
39
 
39
- ping([
40
- "Current Temperature: #{@brewer.pid['pv_temp']} F",
41
- "Set Value Temperature: #{@brewer.pid['sv_temp']} F",
42
- "Current temperature has climed #{diff} F since #{delay} minute(s) ago",
43
- "Sent at #{Time.now.strftime("%H:%M")}",
44
- ""
45
- ])
40
+ ping([
41
+ "Current Temperature: #{@brewer.pid['pv_temp']} F",
42
+ "Set Value Temperature: #{@brewer.pid['sv_temp']} F",
43
+ "Current temperature has climed #{diff} F since #{delay} minute(s) ago",
44
+ "Sent at #{Time.now.strftime("%H:%M")}",
45
+ ""
46
+ ])
47
+ end
48
+ true
46
49
  end
47
- true
48
- end
49
50
 
50
- def monitor
51
- while true do
52
- status_table_rows = [
53
- ["Current Temp", @brewer.pv],
54
- ["Set Value Temp", @brewer.sv],
55
- ["PID is: ", @brewer.pid['pid_running'].to_b ? "on" : "off"],
56
- ["Pump is: ", @brewer.pump]
57
- ]
51
+ def monitor
52
+ while true do
53
+ status_table_rows = [
54
+ ["Current Temp", @brewer.pv],
55
+ ["Set Value Temp", @brewer.sv],
56
+ ["PID is: ", @brewer.pid['pid_running'].to_b ? "on" : "off"],
57
+ ["Pump is: ", @brewer.pump]
58
+ ]
58
59
 
59
- status_table = Terminal::Table.new :headings ["Item", "Status"], :rows => status_table_rows
60
+ status_table = Terminal::Table.new :headings ["Item", "Status"], :rows => status_table_rows
60
61
 
61
- clear_screen
62
- puts status_table
63
- sleep(1)
62
+ clear_screen
63
+ puts status_table
64
+ sleep(1)
65
+ end
64
66
  end
65
- end
66
67
 
68
+ end
67
69
  end
@@ -1,12 +1,18 @@
1
- require_relative "../brewer"
1
+ require_relative "../gems"
2
2
 
3
3
  module Helpers
4
4
 
5
+ # Returns the current time
5
6
  # Formatted as: 03/07/2017 14:26
6
7
  def time
7
8
  Time.now.strftime("%m/%d/%Y %H:%M")
8
9
  end
9
10
 
11
+ def view(view)
12
+ File.open(File.join(__dir__ + "/../../views/#{view}.html.erb"))
13
+ end
14
+
15
+ # Returns true if there is a network connection
10
16
  def network?
11
17
  connection = Net::Ping::TCP.new('google.com', 80, 5)
12
18
  connection.ping?
@@ -39,4 +45,15 @@ module Helpers
39
45
  return brewer_dir + "adaptibrew/#{path}"
40
46
  end
41
47
 
48
+ def capture_stdout(&block)
49
+ original_stdout = $stdout
50
+ $stdout = fake = StringIO.new
51
+ begin
52
+ yield
53
+ ensure
54
+ $stdout = original_stdout
55
+ end
56
+ fake.string
57
+ end
58
+
42
59
  end
@@ -1,202 +1,218 @@
1
1
  require_relative "../brewer"
2
2
 
3
- class Procedures
3
+ module Brewer
4
+ class Procedures
4
5
 
5
- attr_accessor :com, :brewer, :recipe
6
+ attr_accessor :com, :brewer, :recipe
6
7
 
7
- def initialize
8
- @brewer = Brewer.new
9
- @com = Communicator.new
10
- @recipe = Recipe.new(@brewer)
11
- end
12
-
13
- def master
14
- @recipe.get_recipe_vars
15
- boot
16
- heat_strike_water
17
- dough_in
18
- mash
19
- mashout
20
- sparge
21
- top_off
22
- boil
23
- end
24
-
25
- def boot
26
- puts Rainbow("booting...").yellow
27
- @brewer.pid(0)
28
- @brewer.pump(0)
29
- @brewer.rims_to('mash')
30
- @brewer.hlt_to('mash')
31
- @brewer.all_relays_status
32
- puts @brewer.pid
33
-
34
- puts Rainbow("Boot finished!").green
35
- @com.ping("🍺 boot finished 🍺")
36
- true
37
- end
38
-
39
- # :nocov:
40
- def heat_strike_water
41
- puts "heat-strike-water procedure started"
42
-
43
- # Confirm strike water is in the mash tun
44
- print Rainbow("Is the strike water in the mash tun? ").yellow
45
- # -> response
46
- confirm ? nil : abort
47
-
48
- # confirm return manifold is in the mash tun
49
- print Rainbow("Is the return manifold in the mash tun? ").yellow
50
- # -> response
51
- confirm ? nil : abort
52
-
53
- print Rainbow("Is the mash tun valve open? ").yellow
54
- confirm ? nil : abort
55
-
56
- # confirm RIMS relay is on
57
- @brewer.rims_to('mash')
58
- puts "RIMS-to-mash relay is now on"
59
-
60
- # turn on pump
61
- @brewer.pump(1)
62
- puts "Pump is now on"
63
-
64
- puts Rainbow("Is the pump running properly? ").yellow
65
- # TODO: Test this
66
- until confirm
67
- puts "restarting pump"
68
- @brewer.pump(0)
69
- @brewer.wait(2)
70
- @brewer.pump(1)
8
+ def initialize
9
+ @brewer = Brewer.new
10
+ @com = Communicator.new
11
+ @recipe = Recipe.new(@brewer)
71
12
  end
72
13
 
73
- # confirm that strike water is circulating well
74
- print Rainbow("Is the strike water circulating well? ").yellow
75
- # -> response
76
- confirm ? nil : abort
77
-
14
+ # def minified_master(recipe_vars)
15
+ # @recipe.get_recipe_vars(recipe_vars)
16
+ # end
17
+
18
+ def master
19
+ @recipe.get_recipe_vars
20
+ boot
21
+ heat_strike_water
22
+ dough_in
23
+ mash
24
+ mashout
25
+ sparge
26
+ top_off
27
+ boil
28
+ true
29
+ end
78
30
 
79
- # calculate strike temp & set PID to strike temp
80
- # this sets PID SV to calculated strike temp automagically
81
- @brewer.sv(@recipe.strike_water_temp)
82
- puts "SV has been set to calculated strike water temp"
83
- # turn on RIMS heater
84
- @brewer.pid(1)
31
+ def boot
32
+ puts Rainbow("booting...").yellow
33
+ @brewer.relay_config({
34
+ 'pid' => 0,
35
+ 'pump' => 0,
36
+ 'rims_to' => 'mash',
37
+ 'hlt_to' => 'mash'
38
+ })
39
+ # puts @brewer.all_relays_status
40
+ # puts @brewer.pid
41
+
42
+ puts Rainbow("Boot finished!").green
43
+ @com.ping("🍺 boot finished 🍺")
44
+ true
45
+ end
85
46
 
86
- # measure current strike water temp and save
87
- @recipe.starting_strike_temp = @brewer.pv
88
- puts "current strike water temp is #{@brewer.pv}. Saved."
89
- puts "Heating to #{@brewer.sv}"
47
+ # :nocov:
48
+ def heat_strike_water
49
+ puts Rainbow("About to heat strike water").yellow
90
50
 
91
- @com.ping("Strike water beginning to heat. This may take a few minutes.")
51
+ # Confirm strike water is in the mash tun
52
+ print Rainbow("Is the strike water in the mash tun? ").yellow
53
+ confirm ? nil : abort
92
54
 
93
- # when strike temp is reached, @com.ping slack
94
- @brewer.watch
95
- @com.ping("Strike water heated to #{@brewer.pv}. Maintaining temperature.")
96
- puts Rainbow("Strike water heated. Maintaining temp.").green
97
- true
98
- end
99
- # :nocov:
100
-
101
- def dough_in
102
- # turn pump off
103
- @brewer.pump(0)
104
- # turn PID off
105
- @brewer.pid(0)
106
- @brewer.wait(3)
107
- @com.ping("Ready to dough in")
108
- puts Rainbow("Ready to dough in").green
109
-
110
- # pour in grain
111
-
112
- print Rainbow("Confirm when you're done with dough-in (y): ").yellow
113
- confirm ? nil : abort
114
- true
115
- end
55
+ # confirm return manifold is in the mash tun
56
+ print Rainbow("Is the return manifold in the mash tun? ").yellow
57
+ confirm ? nil : abort
116
58
 
117
- def mash
118
- @brewer.sv(@recipe.mash_temp)
59
+ print Rainbow("Is the manual mash tun valve open? ").yellow
60
+ confirm ? nil : abort
119
61
 
120
- puts Rainbow("mash stated. This will take a while.").green
121
- @com.ping("Mash started. This will take a while.")
62
+ # confirm RIMS relay is on
63
+ @brewer.rims_to('mash')
64
+ puts "RIMS-to-mash relay is now on"
122
65
 
123
- @brewer.rims_to('mash')
66
+ # turn on pump
67
+ @brewer.pump(1)
68
+ puts "Pump is now on"
69
+
70
+ print Rainbow("Is the pump running properly? ").yellow
71
+ unless confirm
72
+ puts "restarting pump"
73
+ @brewer.pump(0)
74
+ @brewer.wait(2)
75
+ @brewer.pump(1)
76
+ end
77
+
78
+ # confirm that strike water is circulating well
79
+ print Rainbow("Is the strike water circulating well? ").yellow
80
+ # -> response
81
+ confirm ? nil : abort
82
+
83
+
84
+ # calculate strike temp & set PID to strike temp
85
+ # this sets PID SV to calculated strike temp automagically
86
+ @brewer.sv(@recipe.strike_water_temp)
87
+ puts "SV has been set to calculated strike water temp"
88
+ # turn on RIMS heater
89
+ @brewer.pid(1)
90
+
91
+ # measure current strike water temp and save
92
+ @recipe.starting_strike_temp = @brewer.pv
93
+ puts "current strike water temp is #{@brewer.pv}."
94
+ puts "Heating to #{@brewer.sv}"
95
+
96
+ @com.ping("Strike water beginning to heat. This may take a few minutes.")
97
+
98
+ # when strike temp is reached, @com.ping slack
99
+ @brewer.watch
100
+ puts Rainbow("Strike water heated. Maintaining temp.").green
101
+ true
102
+ end
103
+ # :nocov:
104
+
105
+ def dough_in
106
+ @brewer.relay_config({
107
+ 'pid' => 0,
108
+ 'pump' => 0
109
+ })
110
+ @brewer.wait(3)
111
+ @com.ping("Ready to dough in")
112
+ puts Rainbow("Ready to dough in").green
113
+
114
+ # pour in grain
115
+
116
+ print Rainbow("Confirm when you're done with dough-in (y): ").yellow
117
+ confirm ? nil : abort
118
+ true
119
+ end
124
120
 
125
- @brewer.pump(1)
126
- @brewer.pid(1)
121
+ def mash
122
+ @brewer.sv(@recipe.mash_temp)
127
123
 
128
- @brewer.watch
129
- @com.ping("Mash temp (#{@brewer.pv} F) reached. Starting timer for #{@recipe.mash_time} minutes.")
130
- @brewer.wait(@recipe.mash_time)
131
- @com.ping("🍺 Mash complete 🍺. Check for starch conversion.")
132
- puts Rainbow("Mash complete").green
133
- puts "Check for starch conversion"
134
- end
124
+ puts Rainbow("Mash started. This will take a while.").green
125
+ @com.ping("Mash started. This will take a while.")
135
126
 
136
- def mashout
137
- @com.ping("Start heating sparge water")
127
+ @brewer.relay_config({
128
+ 'rims_to' => 'mash',
129
+ 'pid' => 1,
130
+ 'pump' => 1
131
+ })
138
132
 
139
- @brewer.sv(@recipe.mashout_temp)
133
+ @brewer.watch
134
+ @com.ping("Starting timer for #{to_minutes(@recipe.mash_time)} minutes.")
135
+ @brewer.wait(@recipe.mash_time)
136
+ @com.ping("🍺 Mash complete 🍺. Check for starch conversion.")
137
+ puts Rainbow("Mash complete").green
138
+ puts "Check for starch conversion"
139
+ end
140
140
 
141
- @brewer.pump(1)
142
- @brewer.pid(1)
141
+ def mashout
142
+ @com.ping("Start heating sparge water")
143
143
 
144
- @com.ping("Heating to #{@brewer.sv}... this could take a few minutes.")
145
- @brewer.watch
146
- @com.ping("Mashout temperature (#{@brewer.pv}) reached. Mashout complete.")
147
- end
144
+ @brewer.sv(@recipe.mashout_temp)
148
145
 
149
- def sparge
150
- print Rainbow("Is the sparge water heated to the correct temperature? ").yellow
151
- confirm ? nil : abort
146
+ @brewer.relay_config({
147
+ 'pid' => 1,
148
+ 'pump' => 1
149
+ })
150
+ @com.ping("Heating to #{@brewer.sv}... this could take a few minutes.")
151
+ @brewer.watch
152
+ @com.ping("Mashout complete.")
153
+ end
152
154
 
153
- @brewer.hlt_to('mash')
154
- @brewer.hlt(1)
155
+ def sparge
156
+ print Rainbow("Is the sparge water heated to the correct temperature? ").yellow
157
+ confirm ? nil : abort
155
158
 
156
- print "Waiting for 10 seconds. "
157
- puts Rainbow("Regulate sparge balance.").yellow
158
- puts "(ctrl-c to abort proccess)"
159
- @brewer.wait(30)
159
+ @brewer.relay_config({
160
+ 'hlt_to' => 'mash',
161
+ 'hlt' => 1
162
+ })
160
163
 
161
- @brewer.rims_to('boil')
162
- @brewer.pump(1)
164
+ print "Waiting for 10 seconds. "
165
+ puts Rainbow("Regulate sparge balance.").yellow
166
+ puts "(ctrl-c to abort proccess)"
167
+ @brewer.wait(10)
163
168
 
164
- @com.ping("Please check the sparge balance and ignite boil tun burner")
169
+ @brewer.relay_config({
170
+ 'rims_to' => 'boil',
171
+ 'pump' => 1
172
+ })
165
173
 
166
- puts Rainbow("Waiting until intervention to turn off pump (y): ").yellow
167
- confirm ? nil : abort
174
+ @com.ping("Please check the sparge balance and ignite boil tun burner")
168
175
 
169
- @brewer.pid(0)
170
- @brewer.pump(0)
176
+ print Rainbow("Waiting until intervention to turn off pump (y): ").yellow
177
+ confirm ? nil : abort
171
178
 
172
- @brewer.hlt(0)
173
- end
179
+ @brewer.relay_config({
180
+ 'pid' => 0,
181
+ 'pump' => 0,
182
+ 'hlt' => 0
183
+ })
184
+ true
185
+ end
174
186
 
175
- def top_off
176
- @brewer.hlt_to('boil')
187
+ def top_off
188
+ @brewer.relay_config({
189
+ 'hlt_to' => 'boil',
190
+ 'hlt' => 1
191
+ })
177
192
 
178
- @brewer.hlt(1)
193
+ print Rainbow("waiting for intervention to turn off hlt (y): ").yellow
194
+ confirm ? nil : abort
179
195
 
180
- print Rainbow("waiting for intervention to turn off hlt (y): ").yellow
181
- confirm ? nil : abort
196
+ @brewer.hlt(0)
182
197
 
183
- @brewer.hlt(0)
198
+ @com.ping('Topping off complete')
199
+ puts Rainbow("Topping off complete").green
200
+ end
184
201
 
185
- @com.ping('Topping off complete')
186
- puts Rainbow("Topping off complete").green
187
- end
202
+ def boil
203
+ puts "Timers started... You'll be notified when you need to add hops."
204
+ @com.ping("starting boil procedure")
205
+ @brewer.wait(to_seconds(5))
206
+ @com.ping("Add boil hops")
207
+ @brewer.wait(to_seconds(40))
208
+ @com.ping("Add flovering hops")
209
+ @brewer.wait(to_seconds(13))
210
+ @com.ping("Add finishing hops")
211
+ @brewer.wait(30)
212
+ @com.ping("Done.")
213
+ puts Rainbow("Done.").green
214
+ true
215
+ end
188
216
 
189
- def boil
190
- @com.ping("starting boil procedure")
191
- @brewer.wait(to_seconds(5))
192
- @com.ping("Add boil hops")
193
- @brewer.wait(to_seconds(40))
194
- @com.ping("Add flovering hops")
195
- @brewer.wait(to_seconds(13))
196
- @com.ping("Add finishing hops")
197
- @brewer.wait(30)
198
- @com.ping("Done.")
199
- puts Rainbow("Done.").green
200
217
  end
201
-
202
218
  end