hueshift 0.3.1 → 0.3.3

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: 6096b52b63596c72088581e714eab8f7b8b9779f
4
- data.tar.gz: 86ce9e4f8de24f3634d4b182ac8f6c328539b717
3
+ metadata.gz: 9ab7b3bd2f06c8c25f8f77194a05a6e24719c2bc
4
+ data.tar.gz: c2a14f439563fac888dff3ca6324c2d20c156708
5
5
  SHA512:
6
- metadata.gz: f0732f971af7cae0a4f74760350dfa3304430c7013f711bed99cbc5a71cc7770aa3956835b5b8623aded6ed5101a7d6cf53a786d9016effea9da24a9d7392ad1
7
- data.tar.gz: 7785a54fe3c9a4b2325d90c5933e03c64e567efb1220918efd8077e0d297b5837f718bffc45a3e95eef3c5924315386285a46eca24bb8bbc9bb96ba4934dd28e
6
+ metadata.gz: c47265ae42b37a9f1a0c35b30d3d22c0d6b6faaa4b953812940b0d6b2b28a20e766fb6da04f9c6d052f66fd195557bb24671925d574b5b91b352f350fca7fbb5
7
+ data.tar.gz: d48c3236243ff1ebadfa12eeefbd971c18fcf78fdd8c93d1e3fdadfd0db80aead42219aa25af40efe9cf220bedbc6f6f7704daeff309170a31ff38239c99fb20
@@ -2,10 +2,11 @@
2
2
 
3
3
  require_relative "../lib/hueshift"
4
4
  require "slop"
5
+ require "filewatcher"
5
6
 
6
7
  include Hueshift
7
8
 
8
- load_user_settings
9
+ is_user_settings_file = load_user_settings
9
10
 
10
11
  opts = Slop.parse do |o|
11
12
  o.on "-s", "--server", "continually update color temperature" do
@@ -16,7 +17,21 @@ opts = Slop.parse do |o|
16
17
  exit
17
18
  end
18
19
 
19
- redshift_server
20
+ server = Server.new
21
+
22
+ if is_user_settings_file
23
+ server.start
24
+ filewatcher = FileWatcher.new USER_SETTINGS_PATH
25
+ fw_thread = Thread.new(filewatcher) do |fw|
26
+ fw.watch do |file|
27
+ puts "Detected change to #{file}. Restarting with updated settings."
28
+ load_user_settings
29
+ server.restart
30
+ end
31
+ end.join
32
+ else
33
+ server.start.join
34
+ end
20
35
  end
21
36
  o.on "-v", "--version", "print the version" do
22
37
  puts Hueshift::VERSION
@@ -24,5 +24,6 @@ Gem::Specification.new do |spec|
24
24
 
25
25
  spec.add_dependency "hue", "~> 0.1"
26
26
  spec.add_dependency "slop", "~> 4.2"
27
- spec.add_dependency "dotenv", "~> 2.0.0"
27
+ spec.add_dependency "dotenv", "~> 2.0"
28
+ spec.add_dependency "filewatcher", "~> 0.5"
28
29
  end
@@ -1,5 +1,6 @@
1
1
  require_relative "hueshift/version"
2
2
  require_relative "hueshift/user_settings"
3
+ require_relative "hueshift/server"
3
4
  require "hue"
4
5
 
5
6
  class Numeric
@@ -0,0 +1,36 @@
1
+ module Hueshift
2
+ class Server
3
+ DEFAULT_POLLING_INTERVAL = 30 # seconds
4
+
5
+ def start
6
+ polling_interval = (ENV.fetch "POLLING_INTERVAL", DEFAULT_POLLING_INTERVAL).to_i
7
+ @thread = Thread.new do
8
+ loop do
9
+ redshift_safe
10
+ sleep polling_interval
11
+ end
12
+ end
13
+ end
14
+
15
+ def stop
16
+ @thread.exit
17
+ end
18
+
19
+ def restart
20
+ stop
21
+ start
22
+ end
23
+
24
+ private ####################################################################
25
+
26
+ def redshift_safe
27
+ begin
28
+ redshift
29
+ rescue Exception => e
30
+ puts "#{Time.now}: Received #{e.class}: #{e.message}"
31
+ e.backtrace.each { |line| puts "\t#{line}" }
32
+ end
33
+ end
34
+
35
+ end
36
+ end
@@ -1,11 +1,16 @@
1
1
  module Hueshift
2
2
  USER_SETTINGS_FILE = ".hueshift"
3
+ USER_SETTINGS_PATH = File.expand_path USER_SETTINGS_FILE, Dir.home
3
4
 
5
+ ##
6
+ # Load the settings in USER_SETTINGS_PATH, if it exists.
7
+ #
8
+ # @return whether USER_SETTINGS_PATH exists
4
9
  def load_user_settings
5
- settings_file = File.expand_path USER_SETTINGS_FILE, Dir.home
6
- if File.exist? settings_file
10
+ if (exists = File.exist? USER_SETTINGS_PATH)
7
11
  require "dotenv"
8
- Dotenv.load settings_file
12
+ Dotenv.overload USER_SETTINGS_PATH
9
13
  end
14
+ exists
10
15
  end
11
16
  end
@@ -1,3 +1,3 @@
1
1
  module Hueshift
2
- VERSION = "0.3.1"
2
+ VERSION = "0.3.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hueshift
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Toniazzo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-23 00:00:00.000000000 Z
11
+ date: 2015-10-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -86,14 +86,28 @@ dependencies:
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: 2.0.0
89
+ version: '2.0'
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: 2.0.0
96
+ version: '2.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: filewatcher
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.5'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.5'
97
111
  description:
98
112
  email:
99
113
  - jutonz42@gmail.com
@@ -114,6 +128,7 @@ files:
114
128
  - bin/setup
115
129
  - hueshift.gemspec
116
130
  - lib/hueshift.rb
131
+ - lib/hueshift/server.rb
117
132
  - lib/hueshift/user_settings.rb
118
133
  - lib/hueshift/version.rb
119
134
  homepage: http://www.github.com/jutonz/hueshift