brewer 0.0.46 → 0.0.50

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: 631103298e3b03a620cf2685b98de4badda41dde
4
- data.tar.gz: 5ad112f308ace464b72b45528e2f302d2f92b5a1
3
+ metadata.gz: 4b64a285ed132424529cae2bee9cefe0acac647a
4
+ data.tar.gz: 11a20637683536d2072822de7e56a7e674c6d92b
5
5
  SHA512:
6
- metadata.gz: 9b3aa10a4a56c5e8fee6df0eaaf5fdc1a31eed2f31972f2d8eaf97b8d50dd86035d97e54975f7c6bce982bcc2f38f6db2a5f9c1aa286a575b33603b186662a1f
7
- data.tar.gz: 0d494424f3ba1039c9f24de9ff7805e4c9af38500e6cd1649f3590b0df48d366fc55dac7e2d997528d1efa4e14268d60094ebf3480bdbbb668f04d88ea4c08d9
6
+ metadata.gz: 081b6a644613fa2465b651351fc3fec63fbe767c4da00186ef353ea499714a6a0eca1f19a70d0bf2d976e8e7b72eed402c075ed9b9698616ec5c1effe1dd1adc
7
+ data.tar.gz: 17526d90dfeb30d86a548f2e911eec030cad868c0ea5e24a3b9dcd2f241f31220699fe742f391db86b196a26bc50c789d691a8f3f94663243a5513c6a40f2a92
@@ -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.46"
5
+ s.version = "0.0.50"
6
6
  s.default_executable = "brewer"
7
7
 
8
8
  s.authors = ["Luke Sweeney"]
@@ -7,11 +7,15 @@ include Helpers
7
7
  # This is the 'manager' for the adaptibrew repo. It handles cloning and such.
8
8
  class Adaptibrew
9
9
 
10
+ def initialize
11
+ @install_dir = Dir.home + "/.brewer/"
12
+ end
13
+
10
14
  # If used in IRB, Ripl, etc. it will clone into the directory IRB was started in
11
- def clone(path=nil)
15
+ def clone
12
16
  raise "🛑 Cannot clone, no network connection" unless network?
13
- if !Dir.exists?('adaptibrew')
14
- Git.clone('https://github.com/llamicron/adaptibrew.git', 'adaptibrew', :path => path)
17
+ if !Dir.exists?(@install_dir + "adaptibrew")
18
+ Git.clone('https://github.com/llamicron/adaptibrew.git', 'adaptibrew', :path => @install_dir)
15
19
  end
16
20
  self
17
21
  end
@@ -26,7 +30,7 @@ class Adaptibrew
26
30
  end
27
31
  end
28
32
  # :nocov:
29
- FileUtils.rm_rf('adaptibrew')
33
+ FileUtils.rm_rf(@install_dir + 'adaptibrew')
30
34
  self
31
35
  end
32
36
 
@@ -38,7 +42,7 @@ class Adaptibrew
38
42
  end
39
43
 
40
44
  def present?
41
- if Dir.exists?('adaptibrew')
45
+ if Dir.exists?(@install_dir + 'adaptibrew/')
42
46
  return true
43
47
  end
44
48
  false
@@ -10,7 +10,7 @@ class Brewer
10
10
  attr_accessor :out, :log, :temps
11
11
 
12
12
  def initialize
13
- @base_path = Dir.pwd
13
+ @base_path = Dir.home + '/.brewer'
14
14
  # Output of adaptibrew
15
15
  @out = []
16
16
  @log = @base_path + '/logs/output'
@@ -24,7 +24,7 @@ class Brewer
24
24
 
25
25
  def wait(time=30)
26
26
  sleep(time)
27
- self
27
+ true
28
28
  end
29
29
 
30
30
  # Sends a slack message in #brewing
@@ -44,23 +44,21 @@ class Brewer
44
44
  # It will be set to the output of the last script. I can't just return the output because i need to return self
45
45
  def script(script, params=nil)
46
46
  @out.unshift(`python #{@base_path}/adaptibrew/#{script}.py #{params}`.chomp)
47
- self
47
+ @out.first
48
48
  end
49
49
 
50
50
  # Clears the @out array
51
51
  # Writes current @out to log
52
52
  def clear
53
- write_log(@log, @out)
54
53
  @out = []
55
- self
56
54
  end
57
55
 
58
56
  # This lil' divider is default for large return blocks
59
57
  def echo(string=nil)
60
58
  if string == nil
61
- return @out.first
59
+ puts @out.first
62
60
  end
63
- string
61
+ puts string
64
62
  end
65
63
 
66
64
 
@@ -69,74 +67,73 @@ class Brewer
69
67
 
70
68
  def pump(state=0)
71
69
  if state == 1
72
- script("set_pump_on")
73
- else
74
- script("set_pump_off")
70
+ return script("set_pump_on")
71
+ elsif state == 0
72
+ if pid['pid_running'] == "True"
73
+ pid(0)
74
+ echo
75
+ end
76
+ return script("set_pump_off")
75
77
  end
76
- self
77
- end
78
-
79
- def relay(relay, state)
80
- script("set_relay", "#{relay} #{state}")
81
- self
82
78
  end
83
79
 
84
80
  # Turns PID on or off, or gets state if no arg is provided
85
81
  def pid(state="status")
86
82
  if state == "status"
87
- echo('----------')
88
- script("is_pid_running")
89
- puts "PID is running? " + echo
90
- sv.echo
91
- pv.echo
83
+ return {
84
+ 'pid_running' => script("is_pid_running"),
85
+ 'sv_temp' => sv,
86
+ 'pv_temp' => pv
87
+ }
92
88
  end
93
89
 
94
90
  if state == 1
95
91
  script('set_pid_on')
96
- puts "PID is now on"
97
92
  pump(1)
98
- puts "Pump is now on"
93
+ return "Pump and PID are now on"
99
94
  elsif state == 0
100
- script("set_pid_off")
101
- puts "PID is now off"
95
+ return script("set_pid_off")
102
96
  end
103
97
 
104
- self
105
- end
106
-
107
- def all_relays_status
108
- script("get_relay_status_test")
109
- puts @out.first.split('\n')
110
- @out.shift
111
- self
112
- end
113
-
114
- def relay_status(relay)
115
- raise "Relay number needs to be an integer" unless relay.is_a? Integer
116
- script("get_relay_status", "#{relay}")
117
- puts @out.first
118
- self
98
+ true
119
99
  end
120
100
 
121
101
  def sv(temp=nil)
122
102
  if temp
123
103
  raise "Temperature input needs to be an integer" unless temp.is_a? Integer
124
- script('set_sv', temp)
104
+ return script('set_sv', temp)
125
105
  else
126
- script('get_sv')
106
+ return script('get_sv')
127
107
  end
128
- self
108
+ true
129
109
  end
130
110
 
131
111
  def pv
132
112
  script('get_pv')
133
- self
113
+ end
114
+
115
+ def relay(relay, state)
116
+ script("set_relay", "#{relay} #{state}")
117
+ end
118
+
119
+ def all_relays_status
120
+ script("get_relay_status_test")
121
+ puts @out.first.split('\n')
122
+ @out.shift
123
+ true
124
+ end
125
+
126
+ def relay_status(relay)
127
+ raise "Relay number needs to be an integer" unless relay.is_a? Integer
128
+ script("get_relay_status", "#{relay}")
129
+ return @out.first.split('\n')
134
130
  end
135
131
 
136
132
  def watch
137
- until pv.out.first.to_i == sv.out.first.to_i do
133
+ until pv.to_i == sv.to_i do
138
134
  wait(8)
139
135
  end
136
+ true
140
137
  end
141
138
 
142
139
  # WaterVolInQuarts, GrainMassInPounds, GrainTemp, MashTemp
@@ -147,10 +144,10 @@ class Brewer
147
144
  print "Input amount of grain in lbs: "
148
145
  grain = gets.chomp
149
146
 
150
- print "Input current grain temp (#{pv.echo}): "
147
+ print "Input current grain temp (#{pv}): "
151
148
  grain_temp = gets.chomp
152
149
  if grain_temp == ""
153
- grain_temp = pv.echo.to_i
150
+ grain_temp = pv.to_i
154
151
  end
155
152
 
156
153
  print "Input desired mash temp (150): "
@@ -161,10 +158,9 @@ class Brewer
161
158
  @temps['desired_mash'] = desired_mash_temp
162
159
 
163
160
  # this is where the magic happens
164
- script('get_strike_temp', "#{water} #{grain} #{grain_temp} #{desired_mash_temp}")
165
- @temps['strike_water_temp'] = @out.first.to_i
161
+ @temps['strike_water_temp'] = script('get_strike_temp', "#{water} #{grain} #{grain_temp} #{desired_mash_temp}")
166
162
  sv(echo.to_i)
167
- puts "SV has been set to #{sv.echo} degrees"
163
+ puts "SV has been set to #{sv} degrees"
168
164
  end
169
165
 
170
166
  # Master Procedures -----------------------------------------------------
@@ -172,12 +168,16 @@ class Brewer
172
168
  def boot
173
169
  # These are the states required for starting. Should be called on boot.
174
170
  # Print PID status at end
175
- pid(0).pump(0).relay($settings['rimsToMashRelay'], 1).all_relays_status.pid
171
+ pid(0)
172
+ pump(0)
173
+ relay($settings['rimsToMashRelay'], 1)
174
+ all_relays_status
175
+ puts pid
176
176
 
177
- @out.shift(4)
178
- @out.unshift("Boot successful")
179
- puts @out[0] + "!"
180
- self
177
+ clear
178
+ puts "Boot successful!"
179
+ @out.unshift("successful boot")
180
+ true
181
181
  end
182
182
 
183
183
  def heat_strike_water
@@ -193,31 +193,34 @@ class Brewer
193
193
  pump(1)
194
194
  puts "Pump is now on"
195
195
 
196
- time = 30
196
+ print "How long do you want to wait for the water to start circulating? (30) "
197
+ time = gets.chomp
198
+ if time == ""
199
+ time = 30
200
+ end
201
+
197
202
  puts "Waiting for #{time} seconds for strike water to start circulating"
198
203
  puts "(ctrl-c to stop now)"
199
- wait(time)
204
+ wait(time.to_i)
200
205
 
201
206
  print "Is the strike water circulating well? "
202
207
  confirm ? nil : abort
203
208
 
204
- @temps['starting_strike_temp'] = pv.out.first.to_i
205
- pv
206
- puts "current strike water temp is #{echo}. Saved."
209
+ @temps['starting_strike_temp'] = pv.to_i
210
+ puts "current strike water temp is #{pv}. Saved."
207
211
  puts "Warning: if you exit this brewer shell, the strike water temp will be lost"
208
212
  puts ""
209
213
  puts "--- Calculate strike temp ---"
210
214
  # this sets PID to strike temp
211
215
  get_strike_temp
212
216
  # turn on pid heater
213
- # XXX: This?
214
217
  pid(1)
215
218
 
216
219
  # when strike temp is reached, ping
217
220
  watch
218
221
  ping("strike water is now at #{pv.echo} degrees")
219
222
 
220
- self
223
+ true
221
224
  end
222
225
 
223
226
  end
@@ -1,7 +1,7 @@
1
1
  # This just parses the adaptibrew/settings.py
2
2
  $settings = {}
3
3
 
4
- File.open('adaptibrew/settings.py') do |file|
4
+ File.open(Dir.home + '/adaptibrew/settings.py') do |file|
5
5
  file.each_line do |line|
6
6
  if line.match(/=/) == nil
7
7
  next
@@ -2,10 +2,12 @@ require 'slack-notifier'
2
2
  require 'yaml'
3
3
  require 'yaml/store'
4
4
 
5
- if !File.file?('.slack.yml')
5
+ slack_file = Dir.home + "/.brewer/.slack.yml"
6
+
7
+ if !File.file?(slack_file)
6
8
 
7
9
  # this will create the file if it doesn't exists, which it doesn't in this context
8
- store = YAML::Store.new '.slack.yml'
10
+ store = YAML::Store.new slack_file
9
11
 
10
12
  # you can get this from your slack app integrations page
11
13
  print "Enter your Slack webhook url: "
@@ -17,7 +19,7 @@ if !File.file?('.slack.yml')
17
19
  end
18
20
 
19
21
  # Here's a comment in .slack.yml so if you find it by accident you'll know what it does
20
- File.open(".slack.yml", 'a') do |file|
22
+ File.open(slack_file, 'a') do |file|
21
23
  file.puts "# This is the slack configuration file for the brewer gem"
22
24
  file.puts "# You can delete this file and brewer will re-create it on start-up"
23
25
  end
@@ -26,4 +28,4 @@ end
26
28
 
27
29
  # finally, start up a global variable for the brewer class to use
28
30
  # A full `Slacker` class is not needed, since this only does one thing
29
- $slack = Slack::Notifier.new YAML.load(File.open('.slack.yml'))['webhook_url']
31
+ $slack = Slack::Notifier.new YAML.load(File.open(slack_file))['webhook_url']
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.46
4
+ version: 0.0.50
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luke Sweeney