brewer 0.0.83 → 0.0.89
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +13 -1
- data/README.md +59 -6
- data/Rakefile +11 -3
- data/bin/brewer +5 -7
- data/bin/brewer-server +61 -0
- data/lib/brewer.rb +1 -11
- data/lib/brewer/adaptibrew.rb +34 -35
- data/lib/brewer/brewer.rb +125 -106
- data/lib/brewer/communicator.rb +52 -50
- data/lib/brewer/helpers.rb +18 -1
- data/lib/brewer/procedures.rb +183 -167
- data/lib/brewer/recipe.rb +40 -39
- data/lib/brewer/settings.rb +107 -105
- data/lib/gems.rb +11 -0
- data/spec/brewer_spec.rb +3 -3
- data/spec/hardware_spec.rb +17 -13
- data/spec/helpers_spec.rb +0 -0
- data/spec/settings_spec.rb +1 -13
- data/spec/spec_helper.rb +2 -0
- data/views/index.erb +216 -0
- data/views/not_found.erb +24 -0
- metadata +45 -12
data/lib/brewer/recipe.rb
CHANGED
@@ -1,56 +1,57 @@
|
|
1
1
|
require_relative "../brewer"
|
2
2
|
|
3
|
-
|
3
|
+
module Brewer
|
4
|
+
class Recipe
|
4
5
|
|
5
|
-
|
6
|
+
attr_accessor :mash_temp, :mash_time, :mashout_temp, :water, :grain, :grain_temp, :desired_mash_temp, :strike_water_temp, :starting_strike_temp
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
8
|
+
def initialize(brewer)
|
9
|
+
@brewer = brewer
|
10
|
+
end
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
def get_recipe_vars(vars=false)
|
13
|
+
if vars
|
14
|
+
raise "Vars must be a hash" unless vars.is_a? Hash
|
15
|
+
vars.each do |recipe_key, value|
|
16
|
+
instance_variable_set("@" + recipe_key, value)
|
17
|
+
end
|
16
18
|
end
|
17
|
-
end
|
18
19
|
|
19
|
-
|
20
|
-
get_strike_temp
|
20
|
+
puts Rainbow("Variables for the brew").green
|
21
21
|
|
22
|
-
|
23
|
-
print "Enter mash temperature: "
|
24
|
-
@mash_temp = gets.chomp.to_f
|
25
|
-
print "Enter mash time in minutes: "
|
26
|
-
@mash_time = to_seconds(gets.chomp.to_f)
|
22
|
+
get_strike_temp
|
27
23
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
24
|
+
print Rainbow("Enter mash temperature: ").yellow
|
25
|
+
@mash_temp = gets.chomp.to_f
|
26
|
+
print Rainbow("Enter mash time in minutes: ").yellow
|
27
|
+
@mash_time = to_seconds(gets.chomp.to_f)
|
32
28
|
|
33
|
-
|
34
|
-
|
35
|
-
|
29
|
+
print Rainbow("Enter mashout temp: ").yellow
|
30
|
+
@mashout_temp = gets.chomp.to_f
|
31
|
+
end
|
36
32
|
|
37
|
-
|
38
|
-
|
33
|
+
def get_strike_temp
|
34
|
+
print Rainbow("Input amount of water in quarts: ").yellow
|
35
|
+
@water = gets.chomp.to_f
|
39
36
|
|
40
|
-
|
41
|
-
|
42
|
-
if @grain_temp == ""
|
43
|
-
@grain_temp = @brewer.pv
|
44
|
-
end
|
37
|
+
print Rainbow("Input amount of grain in lbs: ").yellow
|
38
|
+
@grain = gets.chomp.to_f
|
45
39
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
40
|
+
print Rainbow("Input current grain temp (#{@brewer.pv.to_s} F): ").yellow
|
41
|
+
@grain_temp = gets.chomp.to_f
|
42
|
+
if @grain_temp == ""
|
43
|
+
@grain_temp = @brewer.pv
|
44
|
+
end
|
45
|
+
|
46
|
+
print Rainbow("Input desired mash temp (150 F): ").yellow
|
47
|
+
@desired_mash_temp = gets.chomp
|
48
|
+
if @desired_mash_temp == ""
|
49
|
+
@desired_mash_temp = 150
|
50
|
+
end
|
51
|
+
@desired_mash_temp
|
52
|
+
|
53
|
+
@strike_water_temp = @brewer.script('get_strike_temp', "#{@water} #{@grain} #{@grain_temp} #{@desired_mash_temp}").to_f
|
50
54
|
end
|
51
|
-
@desired_mash_temp
|
52
55
|
|
53
|
-
@strike_water_temp = script('get_strike_temp', "#{@water} #{@grain} #{@grain_temp} #{@desired_mash_temp}").to_f
|
54
56
|
end
|
55
|
-
|
56
57
|
end
|
data/lib/brewer/settings.rb
CHANGED
@@ -1,137 +1,139 @@
|
|
1
|
-
require_relative "
|
1
|
+
require_relative "adaptibrew"
|
2
2
|
|
3
|
-
|
3
|
+
module Brewer
|
4
|
+
class Settings
|
4
5
|
|
5
|
-
|
6
|
-
|
6
|
+
attr_accessor :settings
|
7
|
+
attr_reader :cache_file, :source
|
7
8
|
|
8
|
-
|
9
|
+
def initialize(testing=false)
|
9
10
|
|
10
|
-
|
11
|
-
|
11
|
+
@source = adaptibrew_dir('settings.py')
|
12
|
+
@cache_file = brewer_dir('settings.yml')
|
12
13
|
|
13
|
-
|
14
|
+
@settings = Hash.new
|
14
15
|
|
15
|
-
|
16
|
-
|
16
|
+
if !testing
|
17
|
+
Adaptibrew.new.clone
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
19
|
+
if !cache?
|
20
|
+
parse_and_cache
|
21
|
+
else
|
22
|
+
load_cached_settings
|
23
|
+
end
|
23
24
|
|
24
|
-
|
25
|
+
load_global
|
26
|
+
end
|
25
27
|
end
|
26
|
-
end
|
27
28
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
29
|
+
# This will create the cache and populate
|
30
|
+
# it with settings from settings.py
|
31
|
+
def parse_and_cache
|
32
|
+
parse
|
33
|
+
cache
|
34
|
+
end
|
34
35
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
36
|
+
# Loads cached settings
|
37
|
+
# If no cached settings, it returns false
|
38
|
+
def load_cached_settings
|
39
|
+
if cache?
|
40
|
+
@settings = YAML.load(File.open(@cache_file))
|
41
|
+
return true
|
42
|
+
end
|
43
|
+
false
|
41
44
|
end
|
42
|
-
false
|
43
|
-
end
|
44
45
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
46
|
+
# Checks if there are settings in the cache
|
47
|
+
def cache?
|
48
|
+
if File.exists?(@cache_file) and File.readlines(@cache_file).grep(/DEBUG/).size > 0
|
49
|
+
return true
|
50
|
+
end
|
51
|
+
false
|
49
52
|
end
|
50
|
-
false
|
51
|
-
end
|
52
53
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
54
|
+
# Parse the settings from the source file into @settings
|
55
|
+
def parse
|
56
|
+
File.open(@source, 'r') do |file|
|
57
|
+
file.each_line do |line|
|
58
|
+
if line.include? "=" and line[0] != "#"
|
59
|
+
key, value = line.match(/(.+)=(.+)/).captures
|
60
|
+
@settings[key.strip.chomp] = value.strip.chomp
|
61
|
+
end
|
60
62
|
end
|
63
|
+
type_cast
|
64
|
+
return true
|
61
65
|
end
|
62
|
-
|
63
|
-
|
66
|
+
false
|
67
|
+
end
|
68
|
+
|
69
|
+
# Creates the cache if there isn't one already
|
70
|
+
def create_cache
|
71
|
+
unless File.exists?(@cache_file)
|
72
|
+
File.open(@cache_file, 'w')
|
73
|
+
end
|
74
|
+
true
|
64
75
|
end
|
65
|
-
false
|
66
|
-
end
|
67
76
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
77
|
+
# This will add a new element to the @settings hash
|
78
|
+
# AND re-cache the settings
|
79
|
+
def add(setting)
|
80
|
+
raise "Setting needs to be a hash" unless setting.is_a? Hash
|
81
|
+
setting.each do |key, value|
|
82
|
+
@settings[key] = value
|
83
|
+
end
|
84
|
+
cache
|
72
85
|
end
|
73
|
-
true
|
74
|
-
end
|
75
86
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
87
|
+
# Stores the currents @settings in settings.yml
|
88
|
+
def cache
|
89
|
+
create_cache
|
90
|
+
store = YAML::Store.new @cache_file
|
91
|
+
store.transaction {
|
92
|
+
@settings.each do |k, v|
|
93
|
+
store[k] = v
|
94
|
+
end
|
95
|
+
}
|
96
|
+
true
|
82
97
|
end
|
83
|
-
cache
|
84
|
-
end
|
85
98
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
store.transaction {
|
91
|
-
@settings.each do |k, v|
|
92
|
-
store[k] = v
|
99
|
+
# This deletes the cache file
|
100
|
+
def clear_cache
|
101
|
+
if File.exists?(@cache_file)
|
102
|
+
FileUtils.rm_f @cache_file
|
93
103
|
end
|
94
|
-
|
95
|
-
|
96
|
-
end
|
104
|
+
true
|
105
|
+
end
|
97
106
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
107
|
+
# This is so that the settings are easier to use in my code
|
108
|
+
# and for backwards compatability purposes
|
109
|
+
def load_global
|
110
|
+
raise "settings instance variable does not exist yet. Run Settings#parse first" unless !@settings.empty?
|
111
|
+
$settings = @settings
|
102
112
|
end
|
103
|
-
true
|
104
|
-
end
|
105
113
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
114
|
+
def change(values)
|
115
|
+
raise "Values to change must be a hash" unless values.is_a? Hash
|
116
|
+
values.each do |k, v|
|
117
|
+
@settings[k] = v
|
118
|
+
end
|
119
|
+
return true
|
120
|
+
end
|
112
121
|
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
122
|
+
# This method is r/badcode, i know
|
123
|
+
def type_cast
|
124
|
+
# Super janky
|
125
|
+
change({
|
126
|
+
'rimsaddressint' => @settings['rimsaddressint'].to_i,
|
127
|
+
'switchaddressint' => @settings['switchaddressint'].to_i,
|
128
|
+
'baudrate' => @settings['baudrate'].to_i,
|
129
|
+
'timeout' => @settings['timeout'].to_i,
|
130
|
+
'spargeToMashRelay' => @settings['spargeToMashRelay'].to_i,
|
131
|
+
'spargeRelay' => @settings['spargeRelay'].to_i,
|
132
|
+
'rimsToMashRelay' => @settings['rimsToMashRelay'].to_i,
|
133
|
+
'pumpRelay' => @settings['pumpRelay'].to_i,
|
134
|
+
'DEBUG' => @settings['DEBUG'].to_b,
|
135
|
+
})
|
117
136
|
end
|
118
|
-
return true
|
119
|
-
end
|
120
137
|
|
121
|
-
# This method is r/badcode, i know
|
122
|
-
def type_cast
|
123
|
-
# Super janky
|
124
|
-
change({
|
125
|
-
'rimsaddressint' => @settings['rimsaddressint'].to_i,
|
126
|
-
'switchaddressint' => @settings['switchaddressint'].to_i,
|
127
|
-
'baudrate' => @settings['baudrate'].to_i,
|
128
|
-
'timeout' => @settings['timeout'].to_i,
|
129
|
-
'spargeToMashRelay' => @settings['spargeToMashRelay'].to_i,
|
130
|
-
'spargeRelay' => @settings['spargeRelay'].to_i,
|
131
|
-
'rimsToMashRelay' => @settings['rimsToMashRelay'].to_i,
|
132
|
-
'pumpRelay' => @settings['pumpRelay'].to_i,
|
133
|
-
'DEBUG' => @settings['DEBUG'].to_b,
|
134
|
-
})
|
135
138
|
end
|
136
|
-
|
137
139
|
end
|
data/lib/gems.rb
ADDED
data/spec/brewer_spec.rb
CHANGED
@@ -3,7 +3,7 @@ require_relative 'spec_helper'
|
|
3
3
|
describe Brewer do
|
4
4
|
|
5
5
|
before :each do
|
6
|
-
@brewer = Brewer.new
|
6
|
+
@brewer = Brewer::Brewer.new
|
7
7
|
end
|
8
8
|
|
9
9
|
before :all do
|
@@ -12,10 +12,10 @@ describe Brewer do
|
|
12
12
|
|
13
13
|
describe "#new" do
|
14
14
|
it "returns a brewer object" do
|
15
|
-
expect(Brewer.new).to be_an_instance_of Brewer
|
15
|
+
expect(Brewer::Brewer.new).to be_an_instance_of Brewer::Brewer
|
16
16
|
end
|
17
17
|
it "does not accept args" do
|
18
|
-
expect {
|
18
|
+
expect {Brewer::Brewer.new('heres an arg')}.to raise_exception(ArgumentError)
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
data/spec/hardware_spec.rb
CHANGED
@@ -2,26 +2,24 @@ require_relative 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Brewer do
|
4
4
|
before :each do
|
5
|
-
@brewer = Brewer.new
|
5
|
+
@brewer = Brewer::Brewer.new
|
6
6
|
end
|
7
7
|
|
8
8
|
before :all do
|
9
|
-
Adaptibrew.new.refresh
|
9
|
+
Brewer::Adaptibrew.new.refresh
|
10
10
|
end
|
11
11
|
|
12
12
|
after :all do
|
13
13
|
# in case something goes wrong, everything needs to be reset
|
14
|
-
@brewer = Brewer.new
|
14
|
+
@brewer = Brewer::Brewer.new
|
15
15
|
@brewer.pump(0)
|
16
16
|
@brewer.pid(0)
|
17
|
-
@brewer.boot
|
18
17
|
end
|
19
18
|
|
20
19
|
describe ".pump" do
|
21
20
|
# If the pump is already on it does nothing
|
22
21
|
it "turns the pump on" do
|
23
22
|
expect(@brewer.pump(1)).to eq("pump on")
|
24
|
-
@brewer.wait(2)
|
25
23
|
end
|
26
24
|
|
27
25
|
# If the pump is already off it does nothing
|
@@ -41,20 +39,17 @@ describe Brewer do
|
|
41
39
|
|
42
40
|
describe ".relay" do
|
43
41
|
it "turns the relay on" do
|
44
|
-
expect(@brewer.relay(2, 1)).to
|
45
|
-
@brewer.wait(7)
|
42
|
+
expect(@brewer.relay(2, 1)).to be true
|
46
43
|
end
|
47
44
|
|
48
45
|
it "turns the relay off" do
|
49
|
-
expect(@brewer.relay(2, 0)).to
|
50
|
-
@brewer.wait(7)
|
46
|
+
expect(@brewer.relay(2, 0)).to be true
|
51
47
|
end
|
52
48
|
end
|
53
49
|
|
54
50
|
describe ".pid" do
|
55
51
|
it "turns the pid on" do
|
56
52
|
expect(@brewer.pid(1)).to eq("Pump and PID are now on")
|
57
|
-
@brewer.wait(2)
|
58
53
|
end
|
59
54
|
|
60
55
|
it "turns the pid off" do
|
@@ -69,20 +64,20 @@ describe Brewer do
|
|
69
64
|
describe ".sv" do
|
70
65
|
context "when there is no argument" do
|
71
66
|
it "returns the sv temp" do
|
72
|
-
expect(@brewer.sv).to be_an_instance_of
|
67
|
+
expect(@brewer.sv).to be_an_instance_of Float
|
73
68
|
end
|
74
69
|
end
|
75
70
|
|
76
71
|
context "when there is an argument" do
|
77
72
|
it "sets the sv temp" do
|
78
|
-
expect(@brewer.sv(150)).to be_an_instance_of
|
73
|
+
expect(@brewer.sv(150)).to be_an_instance_of Float
|
79
74
|
end
|
80
75
|
end
|
81
76
|
end
|
82
77
|
|
83
78
|
describe ".pv" do
|
84
79
|
it "returns the pv" do
|
85
|
-
expect(@brewer.pv).to be_an_instance_of
|
80
|
+
expect(@brewer.pv).to be_an_instance_of Float
|
86
81
|
end
|
87
82
|
end
|
88
83
|
|
@@ -92,4 +87,13 @@ describe Brewer do
|
|
92
87
|
end
|
93
88
|
end
|
94
89
|
|
90
|
+
describe ".relays_status" do
|
91
|
+
it "returns the status of the 4 main relays" do
|
92
|
+
statuses = @brewer.relays_status
|
93
|
+
expect(statuses).to be_an_instance_of Hash
|
94
|
+
expect(statuses).to_not be_empty
|
95
|
+
expect(statuses['spargeRelay']).to be_an_instance_of String
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
95
99
|
end
|