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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 609b03ad9438c34f412625c145e3ea542aa1ba24
4
- data.tar.gz: c8c87ac2200e23851190b84c6a6d6cf243c46c53
3
+ metadata.gz: d8bb3d0d515993f778a4aeac172e3eafef9402c8
4
+ data.tar.gz: 0e7c1aa4c511b6a441c575afaed60e43fb594dbe
5
5
  SHA512:
6
- metadata.gz: 361547ccce8b1cb02ea49364554d5c03101d6c922bd1672dbc63a90fce2e2a48ba2b90a473b3520c74dd61f6228e36ef180810b47d6159f123064441e82c43ea
7
- data.tar.gz: 3a60d9739afa32e0a89166b8c693e9fb539f177a69956e1ed7bcff9c519da66ac23037b0e323f113460238c5d2fb7eb92271841c9cc6603f68c68fb939b8a652
6
+ metadata.gz: 8ca12ae113bcf9d5eb5b16e07c4af5a18f147fb8ac3b11fb4e6923c7f578bafd4416b4d592ad2b85162f07c696635da0d9a7f19072b3d9b609c13e0e93b0fcc9
7
+ data.tar.gz: 40658e53decd3f843ee1eb33c7b7d3cfa87fb848686a8b870219745d0c504881a81b95f1b3a945d931dd692d2fc1f1f9a9ecf5be670a479dcc57e63c43e22dea
data/Gemfile.lock CHANGED
@@ -1,12 +1,14 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- brewer (0.0.74)
4
+ brewer (0.0.88)
5
5
  git (~> 1.3, >= 1.3.0)
6
6
  net-ping (~> 1.7)
7
+ rack-flash3
7
8
  rainbow
8
9
  require_all
9
10
  ripl (~> 0.7.0)
11
+ sinatra
10
12
  slack-notifier
11
13
  terminal-table
12
14
  wannabe_bool
@@ -25,6 +27,11 @@ GEM
25
27
  addressable (~> 2.3)
26
28
  net-ping (1.7.8)
27
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
28
35
  rainbow (2.2.1)
29
36
  rake (12.0.0)
30
37
  rdoc (5.1.0)
@@ -49,9 +56,14 @@ GEM
49
56
  json (>= 1.8, < 3)
50
57
  simplecov-html (~> 0.10.0)
51
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)
52
63
  slack-notifier (2.1.0)
53
64
  terminal-table (1.7.3)
54
65
  unicode-display_width (~> 1.1.1)
66
+ tilt (2.0.7)
55
67
  unicode-display_width (1.1.3)
56
68
  wannabe_bool (0.6.0)
57
69
 
data/README.md CHANGED
@@ -2,31 +2,84 @@
2
2
  ### A Ruby gem for [adaptiman/adaptibrew](http://github.com/adaptiman/adaptibrew)
3
3
 
4
4
  # Disclaimer
5
- This is just a gem to make adaptibrew more user friendly. It will provide a clean shell and easy to understand methods for all the actions you need to control your brew rig with continuity.
5
+ This is a gem that will provide a command line interface for [adaptiman/adaptibrew](http://github.com/adaptiman/adaptibrew). It will provide pre-made procedures (see Brewer::Procedures) and an easy interface to control a brewing rig.
6
6
 
7
7
  This will require an actual brew rig and all the equipment listed in [adaptiman/adaptibrew](https://github.com/adaptiman/adaptibrew)'s readme. If you are looking to build an automated brew rig, **this is not the place to start**. Head over to [adaptiman/adaptibrew](https://github.com/adaptiman/adaptibrew), or hit up [adaptiman](https://github.com/adaptiman).
8
8
 
9
+ # Quick Start
10
+
11
+ You should have ruby installed. Install this gem with:
12
+
13
+ ```shell
14
+ gem install brewer
15
+ ```
16
+
17
+ Start the brewer shell with
18
+
19
+ ```shell
20
+ brewer
21
+ ```
22
+
23
+
24
+ You can now run the master procedure (the entire standard brewing process) with:
25
+
26
+ ```ruby
27
+ >> procedures.master
28
+ ```
29
+
30
+
31
+ You will be prompted to enter a slack `webhook_url`, which you can get from the `incoming-webhooks` integration on your slack channel.
32
+
33
+
34
+ The shell will ask you for recipe variables in the beginning, and will warn you when you need to intervene.
35
+
36
+ # Web Interface (in development)
37
+ Run the `brewer-server` binary the same way you would run the `brewer` binary. This will start a `sinatra` server on your pi's ip address. The default port is `8080`, but you can specify a custom port with:
38
+
39
+ ```shell
40
+ sudo brewer-server -p YOUR_PORT
41
+ ```
42
+
43
+ Keep in mind that any port below 1024 will need root access. I like to specify port `80` (http default) so that I can leave the port off and it will default to 80.
44
+
45
+ You can add a line to `/etc/hosts` on your workstation and redirect a url to your pi's ip. For instance, the relevant line in my `/etc/hosts` looks like this:
46
+
47
+ ```shell
48
+ 192.168.0.224 navasota.brew
49
+ ```
50
+
51
+ so I can visit `navasota.brew` and see the brewing homepage when `brewer-server` is running.
52
+
53
+ # Starting the server on system startup
54
+
55
+ You may want to start the `brewer-server` an system boot so that a workstation is not required to connect (ssh) to your pi.
56
+
57
+ [See here for a StackOverflow solution](https://raspberrypi.stackexchange.com/a/8735) or read on below.
58
+
9
59
  # Installation
10
60
  This is a gem, published on [rubygems.org](http://rubygems.org). Install it the recommended way with:
11
61
  ```shell
12
62
  gem install brewer
13
63
  ```
14
64
  This will be the latest stable release.
15
- **Or** you can put the following line in a `Gemfile`;
65
+ **Or** you can put the following line in a `Gemfile`:
16
66
  ```ruby
17
67
  gem 'brewer'
18
68
  ```
19
- and run `bundle install`.
69
+ or `.gemspec` file:
70
+ ```ruby
71
+ s.add_runtime_dependency 'brewer'
72
+ ```
20
73
 
21
- You may also download a .gem file from the releases section and install it that way, or further still build a new .gem file from the `brewer.gemspec` if you want the latest possible release. Keep in mind this may not be stable.
74
+ You may also download a .gem file from the [releases section on github](https://github.com/llamicron/brewer/releases) and install it that way, or further still build a new .gem file from the `brewer.gemspec` if you want the latest possible release. This is not recommended, as I do not regularly make releases on Github, just rubygems
22
75
 
23
76
  After installation, run
24
77
  ```shell
25
78
  brewer
26
79
  ```
27
- to open an interactive shell to control your brew rig in realtime.Just like any other gem, you can `require 'brewer'` from another ruby project.
80
+ to open an interactive shell to control your brew rig in realtime. Just like any other gem, you can `require 'brewer'` from another ruby project.
28
81
 
29
- # Documentation
82
+ # Note
30
83
  **Warning: RDoc may have a seizure when encountering Gemfiles, Rakefiles, etc. Basically files that don't end in `.rb` but have ruby syntax. Docs will be a bit weird on those files. I suggest just reading the comments in source.**
31
84
  Documentation is in `doc/` or on rubygems.org
32
85
 
data/Rakefile CHANGED
@@ -8,8 +8,14 @@ task default: %w[spec]
8
8
  # Unit testing
9
9
  # You can specify a specific test case to use
10
10
  # rake spec SPEC=spec/adaptibrew_spec.rb SPEC_OPTS="-e \"#new\""
11
- task :spec, [:tc] do |t, tc|
12
- RSpec::Core::RakeTask.new(:spec)
11
+ #
12
+ # task :spec, [:tc] do |t, tc|
13
+ # RSpec::Core::RakeTask.new(:spec)
14
+ # end
15
+
16
+ RSpec::Core::RakeTask.new do |t|
17
+ t.pattern = "spec/*_spec.rb"
18
+ t.verbose = false
13
19
  end
14
20
 
15
21
  # Opens code coverage in your browser
@@ -23,8 +29,10 @@ end
23
29
  # Generate or update documentation
24
30
  # Generates in `doc/`
25
31
  RDoc::Task.new do |rdoc|
32
+ rm_rf "doc/"
26
33
  rdoc.rdoc_dir = 'doc/'
27
- rdoc.rdoc_files.include("**/*.rb")
34
+ rdoc.main = "README.md"
35
+ # rdoc.rdoc_files.include("**/*.rb")
28
36
  end
29
37
 
30
38
  # Opens documentation.
data/bin/brewer CHANGED
@@ -1,12 +1,10 @@
1
1
  #!/usr/bin/env ruby
2
2
  require_relative "../lib/brewer"
3
3
 
4
- adaptibrew = Adaptibrew.new.refresh
5
- com = Communicator.new
6
- brewer = Brewer.new
7
- settings = Settings.new
8
- procedures = Procedures.new
9
-
4
+ adaptibrew = Brewer::Adaptibrew.new
5
+ com = Brewer::Communicator.new
6
+ brewer = Brewer::Brewer.new
7
+ procedures = Brewer::Procedures.new
10
8
  puts "🍺 have fun 🍺"
11
- Ripl.start :binding => binding
9
+ binding.pry
12
10
  # 🍺🍺🍺
data/bin/brewer-server ADDED
@@ -0,0 +1,61 @@
1
+ #!/usr/bin/env ruby
2
+ require 'sinatra/base'
3
+ require "rainbow"
4
+ require 'rack-flash'
5
+
6
+ require_relative "../lib/gems"
7
+ require_relative "../lib/brewer"
8
+
9
+ include Brewer
10
+
11
+ module Brewer
12
+ class Server < Sinatra::Base
13
+
14
+ configure do
15
+
16
+ use Rack::Flash
17
+
18
+ if ARGV.include? "-p"
19
+ port = ARGV[ARGV.index("-p") + 1].to_i
20
+ if port < 1024
21
+ print Rainbow("Warning: ").yellow
22
+ puts "The port you selected is less than 1024. This will require sudo."
23
+ puts "Either use sudo or choose a different port. Sinatra default is 4567."
24
+ puts ""
25
+ end
26
+ else
27
+ port = 4567
28
+ end
29
+
30
+ # Configuration
31
+ set :bind, '0.0.0.0'
32
+ set :port, port
33
+ set :views, Proc.new { File.join(File.expand_path("..", __dir__), "views") }
34
+ enable :run
35
+ enable :sessions
36
+
37
+ $brewer = Brewer.new
38
+ end
39
+
40
+ # Routes
41
+ not_found do
42
+ erb :not_found
43
+ end
44
+
45
+
46
+ get '/' do
47
+ @relays_status = $brewer.relays_status
48
+ @pid_status = $brewer.pid
49
+
50
+ erb :index
51
+ end
52
+
53
+ post '/apply-relay-config' do
54
+ $brewer.relay_config(params)
55
+ flash[:config_done] = "Relay Configuration Applied"
56
+ redirect '/'
57
+ end
58
+
59
+ run!
60
+ end
61
+ end
data/lib/brewer.rb CHANGED
@@ -1,14 +1,4 @@
1
- require "require_all"
2
- require 'git'
3
- require 'fileutils'
4
- require 'slack-notifier'
5
- require 'yaml'
6
- require 'yaml/store'
7
- require 'net/ping'
8
- require 'ripl'
9
- require 'wannabe_bool'
10
- require 'terminal-table'
11
- require "rainbow"
1
+ require_relative "gems"
12
2
 
13
3
  require_rel 'brewer/'
14
4
 
@@ -1,45 +1,44 @@
1
- require_relative "../brewer"
1
+ require_relative "helpers.rb"
2
2
 
3
- # This is the 'manager' for the adaptibrew repo. It handles cloning and such.
4
- class Adaptibrew
3
+ include Helpers
5
4
 
6
- def initialize
7
- refresh
8
- end
5
+ module Brewer
6
+ class Adaptibrew
9
7
 
10
- # This will clone adaptibrew into ~/.brewer/adaptibrew/
11
- def clone
12
- raise "🛑 Cannot clone, no network connection" unless network?
13
- if !Dir.exists?(adaptibrew_dir)
14
- Git.clone('https://github.com/llamicron/adaptibrew.git', 'adaptibrew', :path => brewer_dir)
8
+ # This will clone adaptibrew into ~/.brewer/adaptibrew/
9
+ def clone
10
+ raise "🛑 Cannot clone, no network connection" unless network?
11
+ if !Dir.exists?(adaptibrew_dir)
12
+ Git.clone('https://github.com/llamicron/adaptibrew.git', 'adaptibrew', :path => brewer_dir)
13
+ end
14
+ self
15
15
  end
16
- self
17
- end
18
16
 
19
- # Danger zone...
20
- def clear
21
- # :nocov: since this requires network to be off
22
- if !network?
23
- print "Warning: you have no network connection. If you clear, you will not be able to clone again, and you'll be stuck without the adaptibrew source. Are you sure? "
24
- confirm ? nil : abort
17
+ # Danger zone...
18
+ def clear
19
+ # :nocov: since this requires network to be off
20
+ if !network?
21
+ print "Warning: you have no network connection. If you clear, you will not be able to clone again, and you'll be stuck without the adaptibrew source. Are you sure? "
22
+ confirm ? nil : abort
23
+ end
24
+ # :nocov:
25
+ FileUtils.rm_rf(adaptibrew_dir)
26
+ self
25
27
  end
26
- # :nocov:
27
- FileUtils.rm_rf(adaptibrew_dir)
28
- self
29
- end
30
28
 
31
- # This is a good catch-all method
32
- # If it's not there, it will clone.
33
- # If it is, it will delete and re-clone
34
- def refresh
35
- raise "🛑 Cannot refresh, no network connection" unless network?
36
- clear
37
- clone
38
- self
39
- end
29
+ # This is a good catch-all method
30
+ # If it's not there, it will clone.
31
+ # If it is, it will delete and re-clone
32
+ def refresh
33
+ raise "🛑 Cannot refresh, no network connection" unless network?
34
+ clear
35
+ clone
36
+ self
37
+ end
40
38
 
41
- def present?
42
- return Dir.exists?(adaptibrew_dir) ? true : false
43
- end
39
+ def present?
40
+ return Dir.exists?(adaptibrew_dir) ? true : false
41
+ end
44
42
 
43
+ end
45
44
  end
data/lib/brewer/brewer.rb CHANGED
@@ -1,141 +1,160 @@
1
1
  require_relative "../brewer"
2
2
 
3
- class Brewer
3
+ module Brewer
4
+ class Brewer
4
5
 
5
- attr_reader :base_path
6
- attr_accessor :temps
6
+ attr_reader :base_path
7
+ attr_accessor :temps, :relays
7
8
 
8
- def initialize
9
- @base_path = Dir.home + '/.brewer'
10
- Settings.new
11
- @temps = {}
12
- end
9
+ def initialize
10
+ @base_path = Dir.home + '/.brewer'
11
+ Settings.new
12
+ @temps = {}
13
+ end
13
14
 
14
- public
15
+ public
15
16
 
16
- # Brewer methods ------------------------------------------------------
17
- # general utilities for the brewer class
17
+ # Brewer methods ------------------------------------------------------
18
+ # general utilities for the brewer class
18
19
 
19
- def wait(time=30)
20
- sleep(time.to_f)
21
- true
22
- end
20
+ def wait(time=30)
21
+ sleep(time.to_f)
22
+ true
23
+ end
23
24
 
24
- # Runs an adaptibrew script
25
- # Output will be stored in @out
26
- # you may see `echo` quite a bit. This will almost always be directly after calling a script
27
- # It will be set to the output of the last script. I can't just return the output because i need to return self
28
- def script(script, params=nil)
29
- `python #{@base_path}/adaptibrew/#{script}.py #{params}`.chomp
30
- end
25
+ # Runs an adaptibrew script
26
+ # Output will be stored in @out
27
+ # you may see `echo` quite a bit. This will almost always be directly after calling a script
28
+ # It will be set to the output of the last script. I can't just return the output because i need to return self
29
+ def script(script, params=nil)
30
+ `python #{@base_path}/adaptibrew/#{script}.py #{params}`.chomp
31
+ end
31
32
 
32
- # Adaptibrew methods ----------------------------------------------
33
- # for working with the rig
34
33
 
35
- def pump(state="status")
36
- if state == "status"
37
- return relay_status($settings['pumpRelay'])
38
- end
34
+ # Adaptibrew methods ----------------------------------------------
35
+ # for working with the rig
36
+
37
+ def pump(state="status")
38
+ if state == "status"
39
+ return relay_status($settings['pumpRelay'])
40
+ end
39
41
 
40
- if state == 1
41
- return script("set_pump_on")
42
- else
43
- if pid['pid_running'].to_b
44
- pid(0)
42
+ if state == 1
43
+ return script("set_pump_on")
44
+ else
45
+ if pid['pid_running'].to_b
46
+ pid(0)
47
+ end
48
+ return script("set_pump_off")
45
49
  end
46
- return script("set_pump_off")
47
50
  end
48
- end
49
51
 
50
- # Turns PID on or off, or gets state if no arg is provided
51
- def pid(state="status")
52
- if state == "status"
53
- return {
54
- 'pid_running' => script("is_pid_running"),
55
- 'sv_temp' => sv,
56
- 'pv_temp' => pv
57
- }
52
+ # Turns PID on or off, or gets state if no arg is provided
53
+ def pid(state="status")
54
+ if state == "status"
55
+ return {
56
+ 'pid_running' => script("is_pid_running"),
57
+ 'sv_temp' => sv,
58
+ 'pv_temp' => pv
59
+ }
60
+ end
61
+
62
+ if state == 1
63
+ script('set_pid_on')
64
+ pump(1)
65
+ return "Pump and PID are now on"
66
+ else
67
+ return script("set_pid_off")
68
+ end
58
69
  end
59
70
 
60
- if state == 1
61
- script('set_pid_on')
62
- pump(1)
63
- return "Pump and PID are now on"
64
- else
65
- return script("set_pid_off")
71
+ def sv(temp=nil)
72
+ if temp
73
+ return script('set_sv', temp).to_f
74
+ end
75
+ script('get_sv').to_f
66
76
  end
67
- end
68
77
 
69
- def sv(temp=nil)
70
- if temp
71
- return script('set_sv', temp).to_f
78
+ def pv
79
+ script('get_pv').to_f
72
80
  end
73
- script('get_sv').to_f
74
- end
75
81
 
76
- def pv
77
- script('get_pv').to_f
78
- end
82
+ def relay(relay, state)
83
+ # If you try to turn the relay to a state that it is already in, this skips the wait
84
+ if relay_status(relay).to_b == state.to_b
85
+ return true
86
+ end
87
+ script("set_relay", "#{relay} #{state}")
88
+ true
89
+ end
79
90
 
80
- def relay(relay, state)
81
- # If you try to turn the relay to a state that it is already in, this skips the wait
82
- if relay_status(relay).to_b == state.to_b
83
- return true
91
+ def all_relays_status
92
+ output = script("get_relay_status_test").split("\n")
93
+ output.shift(3)
94
+ return output
84
95
  end
85
- script("set_relay", "#{relay} #{state}")
86
- wait(10)
87
- true
88
- end
89
96
 
90
- def all_relays_status
91
- output = script("get_relay_status_test")
92
- puts output.split('\n')
93
- true
94
- end
97
+ def relays_status
98
+ statuses = {}
99
+ all_relays_status.shift(4).each do |status|
100
+ relay_num, status = status.match(/relay [0-9+]([0-9]+): (on|off)/).captures
101
+ relay_names = $settings.select { |key, value| key.to_s.match(/Relay/) }
102
+ statuses[relay_names.key(relay_num.to_i)] = status
103
+ end
104
+ return statuses
105
+ end
95
106
 
96
- def relay_status(relay)
97
- if script("get_relay_status", "#{relay}").include? "on"
98
- return "on"
99
- else
100
- return "off"
107
+ def relay_config(params)
108
+ raise "Params must be a hash" unless params.is_a? Hash
109
+ params.each do |method, setting|
110
+ if method == "pump"
111
+ setting = setting.to_i
112
+ end
113
+ send(method, setting)
114
+ end
101
115
  end
102
- end
103
116
 
104
- # :nocov:
105
- def watch
106
- until pv >= sv do
107
- wait(2)
117
+ def relay_status(relay)
118
+ if script("get_relay_status", "#{relay}").include? "on"
119
+ return "on"
120
+ else
121
+ return "off"
122
+ end
108
123
  end
109
- self
110
- end
111
- # :nocov:
112
124
 
113
- def rims_to(location)
114
- if location == "mash"
115
- # we ended up swapping this relay, so the name is backwards
116
- relay($settings['rimsToMashRelay'], 0)
117
- elsif location == "boil"
118
- relay($settings['rimsToMashRelay'], 1)
125
+ # :nocov:
126
+ def watch
127
+ until pv >= sv do
128
+ wait(2)
129
+ end
130
+ Communicator.new.ping("Temperature is now at #{pv.to_f} F")
131
+ self
132
+ end
133
+ # :nocov:
134
+
135
+ def rims_to(location)
136
+ if location == "mash"
137
+ # we ended up swapping this relay, so the name is backwards
138
+ relay($settings['rimsToMashRelay'], 0)
139
+ elsif location == "boil"
140
+ relay($settings['rimsToMashRelay'], 1)
141
+ end
142
+ self
119
143
  end
120
- self
121
- end
122
144
 
123
- def hlt_to(location)
124
- if location == "mash"
125
- relay($settings['spargeToMashRelay'], 0)
126
- elsif location == "boil"
127
- relay($settings['spargeToMashRelay'], 1)
145
+ def hlt_to(location)
146
+ if location == "mash"
147
+ relay($settings['spargeToMashRelay'], 0)
148
+ elsif location == "boil"
149
+ relay($settings['spargeToMashRelay'], 1)
150
+ end
151
+ self
128
152
  end
129
- self
130
- end
131
153
 
132
- def hlt(state)
133
- if state.to_b
134
- relay($settings['spargeRelay'], 1)
135
- elsif !state.to_b
136
- relay($settings['spargeRelay'], 0)
154
+ def hlt(state)
155
+ relay($settings['spargeRelay'], state)
156
+ self
137
157
  end
138
- self
139
- end
140
158
 
159
+ end
141
160
  end