brewer 0.0.90 → 0.0.91

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: ff9777547e993c71abde8a3cb0ef655b1e35af34
4
- data.tar.gz: 131e57b9e7b484407d52c7f212f1f2f5992de946
3
+ metadata.gz: 746d9ad1ef9499a452104dafee8d2050ee9e23e6
4
+ data.tar.gz: 411773a35835954dd35f7052c039210b5293890d
5
5
  SHA512:
6
- metadata.gz: f0d92e3c6f570b4f8d6a522d305438dd28118d4d99c48cfd792672f808f3f1f915a48699285bb9db8d81b8bca168e2d51b2319dd0d97a42814e9721365e1e619
7
- data.tar.gz: c9f8e759f63d4e6265f6ad1a4ebc9c8060602dbc19860c706c26472c31bbc430ad29eab8a0b3c10a3923af43cb1f3ed263e8037f5846c51e5dd3ff1641c6f556
6
+ metadata.gz: a0dc5c48f26a7ed2f82a474299b937c64cf7db558661e1d7655771db5119e856ca668652bf0574d19a5f2e292405245c5a3d2532ae5c6e8c17603ba2c34bdceb
7
+ data.tar.gz: 344adf9d708285bfd486fd3852dfae0100c5d639dab074a7e8a7c089f9d2a298f3f4339d8f485c33198cf0c144362d879122785a328eddb999408ab9a5bf4500
data/Gemfile CHANGED
File without changes
data/README.md CHANGED
@@ -85,4 +85,4 @@ Documentation is in `doc/` or on rubygems.org
85
85
 
86
86
  ---
87
87
 
88
- *This line is for CI build triggers, please ignore*
88
+ *This line is for Travis CI build triggers, please ignore*
data/lib/brewer.rb CHANGED
File without changes
File without changes
data/lib/brewer/brewer.rb CHANGED
@@ -10,7 +10,9 @@ module Brewer
10
10
 
11
11
  def initialize
12
12
  if !Dir.exists?(brewer_dir)
13
+ # :nocov:
13
14
  Dir.mkdir(brewer_dir)
15
+ # :nocov:
14
16
  end
15
17
  @base_path = Dir.home + '/.brewer'
16
18
  Settings.new
@@ -30,7 +32,6 @@ module Brewer
30
32
  `python #{@base_path}/adaptibrew/#{script}.py #{params}`.chomp
31
33
  end
32
34
 
33
-
34
35
  # Turns the pump on and off, or returns the status if no arg
35
36
  # Turning the pump off will turn the pid off too, as it should not be on when the pump is off
36
37
  def pump(state="status")
@@ -84,7 +85,7 @@ module Brewer
84
85
  # Basically when the mash tun is at the set temperate, it will ping and return self.
85
86
  # It will also display a status table every 2 seconds
86
87
  # :nocov:
87
- def watch
88
+ def watch
88
89
  until pv >= sv do
89
90
  wait(2)
90
91
  end
@@ -94,6 +95,7 @@ module Brewer
94
95
  # :nocov:
95
96
 
96
97
  # This will display an updated status table every second
98
+ # :nocov:
97
99
  def monitor
98
100
  while true do
99
101
  # Making a new table with TerminalTable takes about 1 second. I assign
@@ -105,6 +107,7 @@ module Brewer
105
107
  puts table
106
108
  end
107
109
  end
110
+ # :nocov:
108
111
 
109
112
  # This returns a status table
110
113
  def status_table
@@ -10,10 +10,12 @@ module Helpers
10
10
  end
11
11
 
12
12
  # Returns true if there is a network connection
13
+ # :nocov:
13
14
  def network?
14
15
  connection = Net::Ping::TCP.new('google.com', 80, 5)
15
16
  connection.ping?
16
17
  end
18
+ # :nocov:
17
19
 
18
20
  # waits for user input, if 'y' return true, else return false
19
21
  def confirm(input=gets.chomp)
@@ -34,9 +36,11 @@ module Helpers
34
36
  end
35
37
 
36
38
  # Clears the terminal screen
39
+ # :nocov:
37
40
  def clear_screen
38
41
  Gem.win_platform? ? (system "cls") : (system "clear")
39
42
  end
43
+ # :nocov:
40
44
 
41
45
  # Returns the path of the ~/.brewer directory, where everything is stored
42
46
  def brewer_dir(path="")
@@ -49,11 +53,13 @@ module Helpers
49
53
  brewer_dir + "adaptibrew/#{path}"
50
54
  end
51
55
 
56
+ # Returns the path of the recipe storage
52
57
  def recipe_dir(path="")
53
58
  brewer_dir + "recipes/#{path}"
54
59
  end
55
60
 
56
61
  # Captures standard output, mostly used for testing
62
+ # :nocov:
57
63
  def capture_stdout(&block)
58
64
  original_stdout = $stdout
59
65
  $stdout = fake = StringIO.new
@@ -64,5 +70,20 @@ module Helpers
64
70
  end
65
71
  fake.string
66
72
  end
73
+ # :nocov:
74
+
75
+ def dummy_recipe_vars
76
+ return {
77
+ 'name' => "dummy_recipe",
78
+ 'mash_temp' => 150,
79
+ 'mash_time' => 10,
80
+ 'mashout_temp' => 172,
81
+ 'water' => 14,
82
+ 'grain' => 5,
83
+ 'grain_temp' => 80.1,
84
+ 'desired_mash_temp' => 150,
85
+ 'strike_water_temp' => 168.6,
86
+ }
87
+ end
67
88
 
68
89
  end
File without changes
data/lib/brewer/recipe.rb CHANGED
@@ -7,25 +7,38 @@ module Brewer
7
7
 
8
8
  def initialize(brewer)
9
9
  @brewer = brewer
10
+ @vars = Hash.new(0)
11
+ make_recipe_dir
12
+ end
13
+
14
+ def make_recipe_dir
10
15
  if !Dir.exists?(recipe_dir)
11
16
  Dir.mkdir(recipe_dir)
12
17
  end
13
- @vars = Hash.new(0)
18
+ true
19
+ end
20
+
21
+ def new_dummy
22
+ @vars = dummy_recipe_vars
14
23
  end
15
24
 
25
+ # These methods require a lot of user input. Not going to test them.
26
+ # :nocov:
16
27
  def get_recipe_vars(vars=false)
28
+ if vars
29
+ raise "Vars must be a hash" unless vars.is_a? Hash
30
+ @vars = vars
31
+ return true
32
+ end
33
+
17
34
  print "Enter a recipe name to load an existing recipe, or nothing to start a new one: "
18
35
  name = gets.chomp.strip
19
36
 
20
37
  unless name.empty?
21
- load_recipe(name)
38
+ load(name)
22
39
  return true
23
40
  end
24
41
 
25
- if vars
26
- raise "Vars must be a hash" unless vars.is_a? Hash
27
- @vars = vars
28
- end
29
42
 
30
43
  puts Rainbow("Variables for the brew").green
31
44
 
@@ -41,7 +54,9 @@ module Brewer
41
54
 
42
55
  true
43
56
  end
57
+ # :nocov:
44
58
 
59
+ # :nocov:
45
60
  def get_strike_temp
46
61
  print Rainbow("Input amount of water in quarts: ").yellow
47
62
  @vars['water'] = gets.chomp.to_f
@@ -64,23 +79,34 @@ module Brewer
64
79
 
65
80
  @vars['strike_water_temp'] = @brewer.script('get_strike_temp', "#{@vars['water']} #{@vars['grain']} #{@vars['grain_temp']} #{@vars['desired_mash_temp']}").to_f
66
81
  end
82
+ # :nocov:
83
+
84
+ def store(name=false)
85
+ raise "Nothing to store! Please run `.get_recipe_vars` to fill in the recipe variables before storing." unless !@vars.empty?
86
+
87
+ # :nocov:
88
+ if @vars['name'].empty?
89
+ if !name
90
+ print "Please enter a name for this recipe: "
91
+ @vars['name'] = gets.chomp
92
+ else
93
+ @vars['name'] = name
94
+ end
95
+ end
96
+ # :nocov:
67
97
 
68
- def store
69
- print "Please enter a name for this recipe: "
70
- name = gets.chomp
71
-
72
- store = YAML::Store.new recipe_dir(name + ".yml")
98
+ store = YAML::Store.new recipe_dir(@vars['name'] + ".yml")
73
99
  store.transaction {
74
- store["name"] = name
100
+ store["name"] = @vars['name']
75
101
  @vars.each do |k, v|
76
102
  store[k] = v
77
103
  end
78
104
  store["created_on"] = time
79
105
  }
80
- return true
106
+ true
81
107
  end
82
108
 
83
- def load_recipe(recipe)
109
+ def load(recipe)
84
110
  raise "Recipe does not exist" unless File.exists?(recipe_dir(recipe) + ".yml")
85
111
  @vars = YAML.load(File.open(recipe_dir(recipe) + ".yml"))
86
112
  puts "Recipe Loaded"
@@ -94,7 +120,23 @@ module Brewer
94
120
  recipes.each do |recipe|
95
121
  recipe.slice! ".yml"
96
122
  end
97
- return recipes
123
+ recipes
124
+ end
125
+
126
+ def loaded_recipe?
127
+ if File.exists?(recipe_dir(@vars['name']) + ".yml")
128
+ return true
129
+ end
130
+ false
131
+ end
132
+
133
+ def clear
134
+ @vars = {}
135
+ end
136
+
137
+ def delete_recipe_file
138
+ FileUtils.rm_rf(recipe_dir + @vars['name'] + ".yml")
139
+ true
98
140
  end
99
141
 
100
142
  end
data/lib/gems.rb CHANGED
@@ -9,5 +9,3 @@ require 'net/ping'
9
9
  require 'wannabe_bool'
10
10
  require 'terminal-table'
11
11
  require "rainbow"
12
- require 'rack-flash'
13
- require 'sinatra/base'
File without changes
data/spec/brewer_spec.rb CHANGED
File without changes
@@ -12,8 +12,13 @@ describe Brewer do
12
12
  after :all do
13
13
  # in case something goes wrong, everything needs to be reset
14
14
  @brewer = Brewer::Brewer.new
15
- @brewer.pump(0)
16
- @brewer.pid(0)
15
+ @brewer.relay_config({
16
+ 'pump' => 0,
17
+ 'pid' => 0,
18
+ 'rims_to' => 'mash',
19
+ 'hlt_to' => 'mash',
20
+ 'hlt' => 0,
21
+ })
17
22
  end
18
23
 
19
24
  describe ".pump" do
@@ -27,6 +32,10 @@ describe Brewer do
27
32
  expect(@brewer.pump(0)).to eq("pump off")
28
33
  end
29
34
 
35
+ it "returns the pump status" do
36
+ expect(@brewer.pump).to be_an_instance_of String
37
+ end
38
+
30
39
  # cant really test this one...
31
40
  context "when the pid is also on" do
32
41
  # This turns on both pump and pid
@@ -83,7 +92,10 @@ describe Brewer do
83
92
 
84
93
  describe ".relay_status" do
85
94
  it "returns the status of a relay" do
86
- expect(@brewer.relay_status($settings['rimsToMashRelay'].to_i)).not_to be_empty
95
+ @brewer.relay($settings['rimsToMashRelay'], 1)
96
+ expect(@brewer.relay_status($settings['rimsToMashRelay'].to_i)).to eq("on")
97
+ @brewer.relay($settings['rimsToMashRelay'], 0)
98
+ expect(@brewer.relay_status($settings['rimsToMashRelay'].to_i)).to eq("off")
87
99
  end
88
100
  end
89
101
 
@@ -96,4 +108,59 @@ describe Brewer do
96
108
  end
97
109
  end
98
110
 
111
+ describe ".status_table" do
112
+ it "returns a current status table" do
113
+ expect(@brewer.status_table).to be_an_instance_of Terminal::Table
114
+ end
115
+ end
116
+
117
+ describe ".relay_config" do
118
+ it "sets the relays to the configuration" do
119
+ @brewer.relay_config({
120
+ 'hlt' => 1,
121
+ 'pump' => 0,
122
+ })
123
+ expect(@brewer.relay_status($settings['spargeRelay'])).to eq("on")
124
+ end
125
+ end
126
+
127
+ describe ".hlt" do
128
+ it "opens or closes the hlt valve" do
129
+ @brewer.hlt(0)
130
+ expect(@brewer.relay_status($settings['spargeRelay'])).to eq("off")
131
+ @brewer.hlt(1)
132
+ expect(@brewer.relay_status($settings['spargeRelay'])).to eq("on")
133
+ end
134
+ end
135
+
136
+ describe ".rims_to" do
137
+ it "diverts the rims relay to boil or mash tuns" do
138
+ @brewer.rims_to("boil")
139
+ expect(@brewer.relay_status($settings['rimsToMashRelay'])).to eq("on")
140
+ @brewer.rims_to("mash")
141
+ expect(@brewer.relay_status($settings['rimsToMashRelay'])).to eq("off")
142
+ end
143
+
144
+ context "when the location is not valid" do
145
+ it "raises an error" do
146
+ expect { @brewer.rims_to("not_valid") }.to raise_error(/valid location/)
147
+ end
148
+ end
149
+ end
150
+
151
+ describe ".hlt_to" do
152
+ it "diverts the hlt relay to boil or mash tuns" do
153
+ @brewer.hlt_to("boil")
154
+ expect(@brewer.relay_status($settings['spargeToMashRelay'])).to eq("on")
155
+ @brewer.hlt_to("mash")
156
+ expect(@brewer.relay_status($settings['spargeToMashRelay'])).to eq("off")
157
+ end
158
+
159
+ context "when the location is not valid" do
160
+ it "raises an error" do
161
+ expect { @brewer.hlt_to("not_valid") }.to raise_error(/valid location/)
162
+ end
163
+ end
164
+ end
165
+
99
166
  end
data/spec/helpers_spec.rb CHANGED
@@ -14,8 +14,16 @@ describe "Helpers" do
14
14
  end
15
15
 
16
16
  describe "#confirm" do
17
- it "should return true" do
18
- expect(confirm('y')).to be true
17
+ context "when y is given" do
18
+ it "should return true" do
19
+ expect(confirm('y')).to be true
20
+ end
21
+ end
22
+
23
+ context "when n is given" do
24
+ it "should return false" do
25
+ expect(confirm('n')).to be false
26
+ end
19
27
  end
20
28
  end
21
29
 
@@ -31,4 +39,30 @@ describe "Helpers" do
31
39
  end
32
40
  end
33
41
 
42
+ describe ".to_minutes" do
43
+ it "turns seconds to minutes" do
44
+ expect(to_minutes(60)).to eq(1)
45
+ end
46
+ end
47
+
48
+ describe ".to_seconds" do
49
+ it "turns minutes to seconds" do
50
+ expect(to_seconds(1)).to eq(60)
51
+ end
52
+ end
53
+
54
+ describe ".recipe_dir" do
55
+ it "returns the path to the recipe storage dir" do
56
+ expect(recipe_dir).to eq(Dir.home + "/.brewer/recipes/")
57
+ end
58
+ end
59
+
60
+ describe ".dummy_recipe_vars" do
61
+ it "returns a hash of dummy recipe vars" do
62
+ dummy = dummy_recipe_vars
63
+ expect(dummy).to be_an_instance_of Hash
64
+ expect(dummy).not_to be_empty
65
+ end
66
+ end
67
+
34
68
  end
@@ -0,0 +1,81 @@
1
+ require_relative "spec_helper"
2
+ require 'fileutils'
3
+
4
+ include Helpers
5
+
6
+ describe Recipe do
7
+ before :each do
8
+ @brewer = Brewer::Brewer.new
9
+ @recipe = Brewer::Recipe.new(@brewer)
10
+ @recipe.new_dummy
11
+ @recipe.store
12
+ end
13
+
14
+ describe "#new" do
15
+ it "returns a new recipe object" do
16
+ expect(Brewer::Recipe.new(@brewer)).to be_an_instance_of Brewer::Recipe
17
+ end
18
+ end
19
+
20
+ describe ".new_dummy" do
21
+ before { @recipe.clear }
22
+ it "returns a new dummy recipe" do
23
+ expect(@recipe.vars).to be_empty
24
+ @recipe.new_dummy
25
+ expect(@recipe.vars).not_to be_empty
26
+ expect(@recipe.vars['name']).to eq("dummy_recipe")
27
+ end
28
+ end
29
+
30
+ describe ".make_recipe_dir" do
31
+ before { FileUtils.rm_rf(recipe_dir) }
32
+ specify { !Dir.exists?(recipe_dir) }
33
+ it "makes the recipe storage directory" do
34
+ expect(@recipe.make_recipe_dir).to be true
35
+ end
36
+ specify { Dir.exists?(recipe_dir) }
37
+ end
38
+
39
+ describe ".store" do
40
+ context "when there is a loaded recipe" do
41
+ before { @recipe.delete_recipe_file }
42
+ it "stores the loaded recipe" do
43
+ expect(@recipe.loaded_recipe?).to be false
44
+ @recipe.store
45
+ expect(@recipe.loaded_recipe?).to be true
46
+ end
47
+ end
48
+
49
+ context "when there is no loaded recipe" do
50
+ before { @recipe.clear }
51
+ specify { expect(@recipe.vars).to be_empty }
52
+ it "raises an exception" do
53
+ expect { @recipe.store }.to raise_error(/store/)
54
+ end
55
+ end
56
+ end
57
+
58
+ describe ".load" do
59
+ context "when the recipe exists" do
60
+ before { @recipe.clear }
61
+ it "loads the recipe" do
62
+ capture_stdout { expect(@recipe.load("dummy_recipe")).to be true }
63
+ expect(@recipe.loaded_recipe?).to be true
64
+ end
65
+ end
66
+
67
+ context "when the recipe does not exist" do
68
+ it "raises an error" do
69
+ expect { @recipe.load("not_a_real_recipe") }.to raise_error(/does not exist/)
70
+ end
71
+ end
72
+ end
73
+
74
+ describe ".list_recipes" do
75
+ it "returns an array of recipes" do
76
+ expect(@recipe.list_recipes).to be_an_instance_of Array
77
+ expect(@recipe.list_recipes).not_to be_empty
78
+ end
79
+ end
80
+
81
+ end
File without changes
data/spec/spec_helper.rb CHANGED
File without changes
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.90
4
+ version: 0.0.91
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luke Sweeney
@@ -86,20 +86,6 @@ dependencies:
86
86
  - - ">="
87
87
  - !ruby/object:Gem::Version
88
88
  version: '0'
89
- - !ruby/object:Gem::Dependency
90
- name: sinatra
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
89
  - !ruby/object:Gem::Dependency
104
90
  name: terminal-table
105
91
  requirement: !ruby/object:Gem::Requirement
@@ -128,20 +114,6 @@ dependencies:
128
114
  - - ">="
129
115
  - !ruby/object:Gem::Version
130
116
  version: '0'
131
- - !ruby/object:Gem::Dependency
132
- name: rack-flash3
133
- requirement: !ruby/object:Gem::Requirement
134
- requirements:
135
- - - ">="
136
- - !ruby/object:Gem::Version
137
- version: '0'
138
- type: :runtime
139
- prerelease: false
140
- version_requirements: !ruby/object:Gem::Requirement
141
- requirements:
142
- - - ">="
143
- - !ruby/object:Gem::Version
144
- version: '0'
145
117
  - !ruby/object:Gem::Dependency
146
118
  name: pry
147
119
  requirement: !ruby/object:Gem::Requirement
@@ -268,16 +240,13 @@ description: A Ruby API for adaptiman/adaptibrew
268
240
  email: luke@thesweeneys.org
269
241
  executables:
270
242
  - brewer
271
- - brewer-server
272
243
  extensions: []
273
244
  extra_rdoc_files: []
274
245
  files:
275
246
  - Gemfile
276
- - Gemfile.lock
277
247
  - README.md
278
248
  - Rakefile
279
249
  - bin/brewer
280
- - bin/brewer-server
281
250
  - lib/brewer.rb
282
251
  - lib/brewer/adaptibrew.rb
283
252
  - lib/brewer/brewer.rb
@@ -291,10 +260,9 @@ files:
291
260
  - spec/brewer_spec.rb
292
261
  - spec/hardware_spec.rb
293
262
  - spec/helpers_spec.rb
263
+ - spec/recipe_spec.rb
294
264
  - spec/settings_spec.rb
295
265
  - spec/spec_helper.rb
296
- - views/index.erb
297
- - views/not_found.erb
298
266
  homepage: https://rubygems.org/gems/brewer
299
267
  licenses:
300
268
  - MIT
@@ -325,5 +293,6 @@ test_files:
325
293
  - spec/brewer_spec.rb
326
294
  - spec/hardware_spec.rb
327
295
  - spec/helpers_spec.rb
296
+ - spec/recipe_spec.rb
328
297
  - spec/settings_spec.rb
329
298
  - spec/spec_helper.rb
data/Gemfile.lock DELETED
@@ -1,83 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- brewer (0.0.88)
5
- git (~> 1.3, >= 1.3.0)
6
- net-ping (~> 1.7)
7
- rack-flash3
8
- rainbow
9
- require_all
10
- ripl (~> 0.7.0)
11
- sinatra
12
- slack-notifier
13
- terminal-table
14
- wannabe_bool
15
-
16
- GEM
17
- remote: https://rubygems.org/
18
- specs:
19
- addressable (2.5.1)
20
- public_suffix (~> 2.0, >= 2.0.2)
21
- bond (0.5.1)
22
- diff-lcs (1.3)
23
- docile (1.1.5)
24
- git (1.3.0)
25
- json (2.0.4)
26
- launchy (2.4.3)
27
- addressable (~> 2.3)
28
- net-ping (1.7.8)
29
- public_suffix (2.0.5)
30
- rack (1.6.5)
31
- rack-flash3 (1.0.5)
32
- rack
33
- rack-protection (1.5.3)
34
- rack
35
- rainbow (2.2.1)
36
- rake (12.0.0)
37
- rdoc (5.1.0)
38
- require_all (1.4.0)
39
- ripl (0.7.1)
40
- bond (~> 0.5.1)
41
- rspec (3.5.0)
42
- rspec-core (~> 3.5.0)
43
- rspec-expectations (~> 3.5.0)
44
- rspec-mocks (~> 3.5.0)
45
- rspec-core (3.5.4)
46
- rspec-support (~> 3.5.0)
47
- rspec-expectations (3.5.0)
48
- diff-lcs (>= 1.2.0, < 2.0)
49
- rspec-support (~> 3.5.0)
50
- rspec-mocks (3.5.0)
51
- diff-lcs (>= 1.2.0, < 2.0)
52
- rspec-support (~> 3.5.0)
53
- rspec-support (3.5.0)
54
- simplecov (0.13.0)
55
- docile (~> 1.1.0)
56
- json (>= 1.8, < 3)
57
- simplecov-html (~> 0.10.0)
58
- simplecov-html (0.10.0)
59
- sinatra (1.4.8)
60
- rack (~> 1.5)
61
- rack-protection (~> 1.4)
62
- tilt (>= 1.3, < 3)
63
- slack-notifier (2.1.0)
64
- terminal-table (1.7.3)
65
- unicode-display_width (~> 1.1.1)
66
- tilt (2.0.7)
67
- unicode-display_width (1.1.3)
68
- wannabe_bool (0.6.0)
69
-
70
- PLATFORMS
71
- ruby
72
-
73
- DEPENDENCIES
74
- brewer!
75
- launchy (~> 2.4, >= 2.4.0)
76
- rake (~> 12.0, >= 12.0.0)
77
- rdoc (~> 5.1, >= 5.1.0)
78
- rspec (~> 3.5.0, >= 3.5.0)
79
- simplecov (~> 0.13.0)
80
- simplecov-html (~> 0.10.0)
81
-
82
- BUNDLED WITH
83
- 1.14.6
data/bin/brewer-server DELETED
@@ -1,56 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require_relative "../lib/brewer"
3
-
4
- include Brewer
5
-
6
- module Brewer
7
- class Server < Sinatra::Base
8
-
9
- configure do
10
-
11
- use Rack::Flash
12
-
13
- if ARGV.include? "-p"
14
- port = ARGV[ARGV.index("-p") + 1].to_i
15
- if port < 1024
16
- print Rainbow("Warning: ").yellow
17
- puts "The port you selected is less than 1024. This will require sudo."
18
- puts "Either use sudo or choose a different port. Sinatra default is 4567."
19
- puts ""
20
- end
21
- else
22
- port = 4567
23
- end
24
-
25
- # Configuration
26
- set :port, port
27
- set :bind, '0.0.0.0'
28
- set :views, Proc.new { File.join(File.expand_path("..", __dir__), "views") }
29
- enable :run
30
- enable :sessions
31
-
32
- $brewer = Brewer.new
33
- end
34
-
35
- # Routes
36
- not_found do
37
- erb :not_found
38
- end
39
-
40
- get '/' do
41
- @relays_status = $brewer.relays_status
42
- @pid_status = $brewer.pid
43
-
44
- erb :index
45
- end
46
-
47
- post '/apply-relay-config' do
48
- $brewer.relay_config(params)
49
- flash[:config_done] = "Relay Configuration Applied"
50
-
51
- redirect '/'
52
- end
53
-
54
- run!
55
- end
56
- end
data/views/index.erb DELETED
@@ -1,216 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8">
5
- <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/css/bootstrap.min.css">
6
- <link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
7
- <link rel="stylesheet" href="https://code.getmdl.io/1.2.1/material.blue_grey-indigo.min.css" />
8
- <script defer src="https://code.getmdl.io/1.2.1/material.min.js"></script>
9
- <link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Roboto:300,400,500,700" type="text/css">
10
- <title>Brewer Home</title>
11
- <style media="screen">
12
- .card-wide {
13
- width: 100%;
14
- margin-top: 2em;
15
- }
16
- </style>
17
- </head>
18
- <body>
19
- <div class="mdl-layout mdl-js-layout mdl-layout--fixed-header">
20
- <header class="mdl-layout__header">
21
- <div class="mdl-layout__tab-bar mdl-js-ripple-effect">
22
- <a href="#scroll-tab-1" class="mdl-layout__tab is-active">Relays & Pump</a>
23
- <a href="#scroll-tab-2" class="mdl-layout__tab">PID</a>
24
- <a href="#scroll-tab-3" class="mdl-layout__tab">Procedures</a>
25
- </div>
26
- </header>
27
-
28
- <main class="mdl-layout__content">
29
- <div class="container">
30
- <div class="page-content">
31
- <div class="row">
32
- <!-- Tab 1 -->
33
- <section class="mdl-layout__tab-panel is-active" id="scroll-tab-1">
34
- <div class="col-md-6">
35
- <br>
36
- <!-- Relay Status Card / Table -->
37
- <div class="mdl-card card-wide mdl-shadow--4dp">
38
- <div class="mdl-card__title mdl-card--expand">
39
- <h2 class="mdl-card__title-text">Relay Status</h2>
40
- </div>
41
- <div class="mdl-card__supporting-text">
42
- <table class="mdl-data-table mdl-js-data-table mdl-shadow--2dp" style="width: 100%;">
43
- <thead>
44
- <tr>
45
- <th class="mdl-data-table__cell--non-numeric">Relay Name</th>
46
- <th>Status</th>
47
- </tr>
48
- </thead>
49
- <tbody>
50
- <% @relays_status.each do |relay_name, status| %>
51
- <tr>
52
- <td class="mdl-data-table__cell--non-numeric"><strong><%= relay_name %></strong></td>
53
- <td><strong><%= status %></strong></td>
54
- </tr>
55
- <% end %>
56
- </tbody>
57
- </table>
58
- </div>
59
- </div>
60
- </div>
61
- <div class="col-md-6">
62
- <!-- Relay Configuration Card / Form -->
63
- <br>
64
- <div class="mdl-shadow--4dp card-wide mdl-card">
65
- <div class="mdl-card__title mdl-card--expand">
66
- <h2 class="mdl-card__title-text">Custom Relay Configuration</h2>
67
- </div>
68
- <div class="mdl-card__supporting-text">
69
- <form action="/apply-relay-config" enctype='application/json' method="post">
70
- <!-- HLT to option -->
71
-
72
- <div class="mdl-select mdl-select--floating-label">
73
- <label class="mdl-select__label" for="hlt_to">Divert HLT to: </label>
74
- <select class="mdl-select__input" id="hlt_to" name="hlt_to">
75
- <option value="mash" <%= @relays_status['spargeToMashRelay'].to_b ? nil : "selected" %>>Mash</option>
76
- <option value="boil" <%= @relays_status['spargeToMashRelay'].to_b ? "selected" : nil %>>Boil</option>
77
- </select>
78
- </div>
79
- <br>
80
- <!-- RIMS to option -->
81
- <div class="mdl-select mdl-select--floating-label">
82
- <label class="mdl-select__label" for="rims_to">Divert RIMS to: </label>
83
- <select class="mdl-select__input" id="rims_to" name="rims_to">
84
- <option value="mash" <%= @relays_status['rimsToMashRelay'].to_b ? nil : "selected" %>>Mash (Circulate)</option>
85
- <option value="boil" <%= @relays_status['rimsToMashRelay'].to_b ? "selected" : nil %>>Boil</option>
86
- </select>
87
- </div>
88
- <br>
89
- <!-- HLT on option -->
90
- <label class="mdl-switch mdl-js-switch mdl-js-ripple-effect" for="hlt">
91
- <input type="hidden" name="hlt" value="0">
92
- <input type="checkbox" id="hlt" name="hlt" value="1" class="mdl-switch__input" <%= @relays_status['spargeRelay'].to_b ? "checked" : nil %>>
93
- <span class="mdl-switch__label">HLT Flowing?</span>
94
- </label>
95
- <br><br><hr><br>
96
- <!-- Pump option -->
97
- <label class="mdl-switch mdl-js-switch mdl-js-ripple-effect" for="pump">
98
- <input type="hidden" name="pump" value="0">
99
- <input type="checkbox" id="pump" name="pump" value="1" class="mdl-switch__input" <%= @relays_status['pumpRelay'].to_b ? "checked" : nil %>>
100
- <span class="mdl-switch__label">Pump On?</span>
101
- </label>
102
- <br>
103
- </div>
104
- <div class="mdl-card__actions mdl-card--border">
105
- <button type="submit" class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--accent">
106
- Apply Configuration
107
- </button>
108
- </div>
109
- </form>
110
- </div>
111
- </div>
112
- </div>
113
- </section>
114
- <!-- Tab 2 -->
115
- <section class="mdl-layout__tab-panel" id="scroll-tab-2">
116
- <div class="col-md-12">
117
- <div class="mdl-card card-wide mdl-shadow--4dp">
118
- <div class="mdl-card__title mdl-card--expand">
119
- <h2 class="mdl-card__title-text">RIMS/PID Status</h2>
120
- </div>
121
- <div class="mdl-card__supporting-text">
122
- <div class="col-md-6">
123
- <h1><%= @pid_status['pv_temp'] %>° F</h1>
124
- <h3>Proccess Value Temp</h3>
125
- </div>
126
- <div class="col-md-6">
127
- <h1><%= @pid_status['sv_temp'] %>° F</h1>
128
- <h3>Set Value Temp</h3>
129
- </div>
130
- <br>
131
- <div class="container">
132
- <div class="row">
133
- <div class="col-md-12">
134
- <h3>RIMS Heater is <%= @pid_status['pid_running'].to_b ? "On" : "Off" %></h3>
135
- </div>
136
- </div>
137
- </div>
138
- </div>
139
- </div>
140
- </div>
141
- </section>
142
- <!-- Tab 3 -->
143
- <section class="mdl-layout__tab-panel" id="scroll-tab-3">
144
- <div class="col-md-12">
145
- <div class="mdl-card card-wide mdl-shadow--4dp">
146
- <div class="mdl-card__supporting-text">
147
- <h2>Choose a procedure: </h2>
148
- <form action="/start-procedure" method="post">
149
- <label class="mdl-radio mdl-js-radio mdl-js-ripple-effect" for="master">
150
- <input type="radio" id="master" class="mdl-radio__button" name="procedure" value="master">
151
- <span class="mdl-radio__label">Master</span>
152
- <br>
153
- <i>
154
- (Does all the following procedures)
155
- </i>
156
- </label>
157
- <hr>
158
- <label class="mdl-radio mdl-js-radio mdl-js-ripple-effect" for="boot">
159
- <input type="radio" id="boot" class="mdl-radio__button" name="procedure" value="boot">
160
- <span class="mdl-radio__label">Boot</span>
161
- </label>
162
- <br><br>
163
- <label class="mdl-radio mdl-js-radio mdl-js-ripple-effect" for="heat-strike-water">
164
- <input type="radio" id="heat-strike-water" class="mdl-radio__button" name="procedure" value="heat-strike-water">
165
- <span class="mdl-radio__label">Heat Strike Water</span>
166
- </label>
167
- <br><br>
168
- <label class="mdl-radio mdl-js-radio mdl-js-ripple-effect" for="dough-in">
169
- <input type="radio" id="dough-in" class="mdl-radio__button" name="procedure" value="dough-in">
170
- <span class="mdl-radio__label">Dough In</span>
171
- </label>
172
- <br><br>
173
- <label class="mdl-radio mdl-js-radio mdl-js-ripple-effect" for="mash">
174
- <input type="radio" id="mash" class="mdl-radio__button" name="procedure" value="mash">
175
- <span class="mdl-radio__label">Mash</span>
176
- </label>
177
- <br><br>
178
- <label class="mdl-radio mdl-js-radio mdl-js-ripple-effect" for="mashout">
179
- <input type="radio" id="mashout" class="mdl-radio__button" name="procedure" value="mashout">
180
- <span class="mdl-radio__label">Mashout</span>
181
- </label>
182
- <br><br>
183
- <label class="mdl-radio mdl-js-radio mdl-js-ripple-effect" for="sparge">
184
- <input type="radio" id="sparge" class="mdl-radio__button" name="procedure" value="sparge">
185
- <span class="mdl-radio__label">Sparge</span>
186
- </label>
187
- <br><br>
188
- <label class="mdl-radio mdl-js-radio mdl-js-ripple-effect" for="top-off">
189
- <input type="radio" id="top-off" class="mdl-radio__button" name="procedure" value="top-off">
190
- <span class="mdl-radio__label">Top Off</span>
191
- </label>
192
- <br><br>
193
- <label class="mdl-radio mdl-js-radio mdl-js-ripple-effect" for="boil">
194
- <input type="radio" id="boil" class="mdl-radio__button" name="procedure" value="boil">
195
- <span class="mdl-radio__label">Boil</span>
196
- </label>
197
- <br>
198
- <br>
199
- </div>
200
- <div class="mdl-card__actions mdl-card--border">
201
- <!-- Submit button -->
202
- <button type="submit" class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--accent">
203
- Start Procedure
204
- </button>
205
- </form>
206
- </div>
207
- </div>
208
- </div>
209
- </section>
210
- </div>
211
- </div>
212
- </div>
213
- </main>
214
- </div>
215
- </body>
216
- </html>
data/views/not_found.erb DELETED
@@ -1,24 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8">
5
- <title>Page Not Found</title>
6
- <link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
7
- <link rel="stylesheet" href="https://code.getmdl.io/1.2.1/material.blue_grey-indigo.min.css" />
8
- <script defer src="https://code.getmdl.io/1.2.1/material.min.js"></script>
9
- <link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Roboto:300,400,500,700" type="text/css">
10
- <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/css/bootstrap.min.css">
11
- </head>
12
- <body>
13
- <div class="row">
14
- <div class="col-md-4 col-md-offset-4">
15
- <br><br>
16
- <div class="mdl-card mdl-shadow--4dp">
17
- <div class="mdl-card__supporting-text">
18
- <h2>Error 404: Page Not Found</h2>
19
- </div>
20
- </div>
21
- </div>
22
- </div>
23
- </body>
24
- </html>