brewer 0.0.83 → 0.0.89

Sign up to get free protection for your applications and to get access to all the features.
data/lib/brewer/recipe.rb CHANGED
@@ -1,56 +1,57 @@
1
1
  require_relative "../brewer"
2
2
 
3
- class Recipe
3
+ module Brewer
4
+ class Recipe
4
5
 
5
- attr_accessor :mash_temp, :mash_time, :mashout_temp, :water, :grain, :grain_temp, :desired_mash_temp, :strike_water_temp, :starting_strike_temp
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
- def initialize(brewer)
8
- @brewer = brewer
9
- end
8
+ def initialize(brewer)
9
+ @brewer = brewer
10
+ end
10
11
 
11
- def get_recipe_vars(vars=false)
12
- if vars
13
- raise "Vars must be a hash" unless vars.is_a? Hash
14
- vars.each do |recipe_key, value|
15
- instance_variable_set("@" + recipe_key, value)
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
- puts "Variables for heating strike water"
20
- get_strike_temp
20
+ puts Rainbow("Variables for the brew").green
21
21
 
22
- puts "Variables for mash ---"
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
- puts "Variables for mashout ---"
29
- print "Enter mashout temp: "
30
- @mashout_temp = gets.chomp.to_f
31
- end
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
- def get_strike_temp
34
- print "Input amount of water in quarts: "
35
- @water = gets.chomp.to_f
29
+ print Rainbow("Enter mashout temp: ").yellow
30
+ @mashout_temp = gets.chomp.to_f
31
+ end
36
32
 
37
- print "Input amount of grain in lbs: "
38
- @grain = gets.chomp.to_f
33
+ def get_strike_temp
34
+ print Rainbow("Input amount of water in quarts: ").yellow
35
+ @water = gets.chomp.to_f
39
36
 
40
- print "Input current grain temp (#{@brewer.pv.to_s} F): "
41
- @grain_temp = gets.chomp.to_f
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
- print "Input desired mash temp (150 F): "
47
- @desired_mash_temp = gets.chomp
48
- if @desired_mash_temp == ""
49
- @desired_mash_temp = 150
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
@@ -1,137 +1,139 @@
1
- require_relative "../brewer"
1
+ require_relative "adaptibrew"
2
2
 
3
- class Settings
3
+ module Brewer
4
+ class Settings
4
5
 
5
- attr_accessor :settings
6
- attr_reader :cache_file, :source
6
+ attr_accessor :settings
7
+ attr_reader :cache_file, :source
7
8
 
8
- def initialize(testing=false)
9
+ def initialize(testing=false)
9
10
 
10
- @source = adaptibrew_dir('settings.py')
11
- @cache_file = brewer_dir('settings.yml')
11
+ @source = adaptibrew_dir('settings.py')
12
+ @cache_file = brewer_dir('settings.yml')
12
13
 
13
- @settings = Hash.new
14
+ @settings = Hash.new
14
15
 
15
- if !testing
16
- Adaptibrew.new.clone
16
+ if !testing
17
+ Adaptibrew.new.clone
17
18
 
18
- unless cache?
19
- parse_and_cache
20
- else
21
- load_cached_settings
22
- end
19
+ if !cache?
20
+ parse_and_cache
21
+ else
22
+ load_cached_settings
23
+ end
23
24
 
24
- load_global
25
+ load_global
26
+ end
25
27
  end
26
- end
27
28
 
28
- # This will create the cache and populate
29
- # it with settings from settings.py
30
- def parse_and_cache
31
- parse
32
- cache
33
- end
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
- # Loads cached settings
36
- # If no cached settings, it returns false
37
- def load_cached_settings
38
- if cache?
39
- @settings = YAML.load(File.open(@cache_file))
40
- return true
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
- # Checks if there are settings in the cache
46
- def cache?
47
- if File.exists?(@cache_file) and File.readlines(@cache_file).grep(/DEBUG/).size > 0
48
- return true
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
- # Parse the settings from the source file into @settings
54
- def parse
55
- File.open(@source, 'r') do |file|
56
- file.each_line do |line|
57
- if line.include? "=" and line[0] != "#"
58
- key, value = line.match(/(.+)=(.+)/).captures
59
- @settings[key.strip.chomp] = value.strip.chomp
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
- type_cast
63
- return true
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
- # Creates the cache if there isn't one already
69
- def create_cache
70
- unless File.exists?(@cache_file)
71
- File.open(@cache_file, 'w')
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
- # This will add a new element to the @settings hash
77
- # AND re-cache the settings
78
- def add(setting)
79
- raise "Setting needs to be a hash" unless setting.is_a? Hash
80
- setting.each do |key, value|
81
- @settings[key] = value
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
- # Stores the currents @settings in settings.yml
87
- def cache
88
- create_cache
89
- store = YAML::Store.new @cache_file
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
- true
96
- end
104
+ true
105
+ end
97
106
 
98
- # This deletes the cache file
99
- def clear_cache
100
- if File.exists?(@cache_file)
101
- FileUtils.rm_f @cache_file
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
- # This is so that the settings are easier to use in my code
107
- # and for backwards compatability purposes
108
- def load_global
109
- parse_and_cache
110
- $settings = @settings
111
- end
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
- def change(values)
114
- raise "Values to change must be a hash" unless values.is_a? Hash
115
- values.each do |k, v|
116
- @settings[k] = v
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
@@ -0,0 +1,11 @@
1
+ require 'pry'
2
+ require "require_all"
3
+ require 'git'
4
+ require 'fileutils'
5
+ require 'slack-notifier'
6
+ require 'yaml'
7
+ require 'yaml/store'
8
+ require 'net/ping'
9
+ require 'wannabe_bool'
10
+ require 'terminal-table'
11
+ require "rainbow"
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 { Brewer.new('heres an arg') }.to raise_exception(ArgumentError)
18
+ expect {Brewer::Brewer.new('heres an arg')}.to raise_exception(ArgumentError)
19
19
  end
20
20
  end
21
21
 
@@ -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 eq("relay 2 on")
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 eq("relay 2 off")
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 String
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 String
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 String
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