darklite 0.2.0
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 +7 -0
- data/.gitignore +18 -0
- data/.rspec +1 -0
- data/.travis.yml +5 -0
- data/CONTRIBUTING.md +9 -0
- data/Gemfile +3 -0
- data/LICENSE +19 -0
- data/README.md +26 -0
- data/Rakefile +8 -0
- data/darklite.gemspec +25 -0
- data/lib/darklite.rb +4 -0
- data/lib/darklite/utils.rb +58 -0
- data/spec/darklite/utils_spec.rb +58 -0
- data/spec/spec_helper.rb +34 -0
- metadata +171 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 79c9dffb9918ed4727d03930d54516778d7c509f
|
4
|
+
data.tar.gz: a8a058d3323f511d9da21ce16dddef5be0f77cef
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 64db58cc78d66892d443a8d97e68ba03dc35523522ade9d0f8b367ea74ad8bb703c6f11b6b986a9e2b84e2f88dce5aed75802cdf233c2be557149d18d4fb5a05
|
7
|
+
data.tar.gz: 9c0e39d2be6d514a669b33b508114f0772fc097a456c7f51a3b7f9f458bb8a481d930d172fa28e0036f6b8dde2503863fadb7d35875bbd10e360632b2bbae3f5
|
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--require spec_helper
|
data/.travis.yml
ADDED
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
Pull requests are awesome! Pull requests with tests are even more awesome!
|
2
|
+
|
3
|
+
## Quick steps
|
4
|
+
|
5
|
+
1. Fork the repo.
|
6
|
+
2. Run the tests: `bundle && rake`
|
7
|
+
3. Add a test for your change. Only refactoring and documentation changes require no new tests. If you are adding functionality or fixing a bug, it needs a test!
|
8
|
+
4. Make the test pass.
|
9
|
+
5. Push to your fork and submit a pull request.
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2015 Eric Sigler
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# Darklite
|
2
|
+
|
3
|
+
[](https://travis-ci.org/esigler/darklite)
|
4
|
+
[](https://tldrlegal.com/license/mit- license)
|
5
|
+
[](https://rubygems.org/gems/darklite)
|
6
|
+
[](https://coveralls.io/r/ esigler/darklite)
|
7
|
+
[](https://codeclimate.com/github/ esigler/darklite)
|
8
|
+
[](https://gemnasium.com/esigler/darklite)
|
9
|
+
|
10
|
+
A small daemon to manage Internet-connected lights.
|
11
|
+
|
12
|
+
## Installation
|
13
|
+
|
14
|
+
`` ruby
|
15
|
+
gem install darklite
|
16
|
+
``
|
17
|
+
|
18
|
+
## Configuration
|
19
|
+
|
20
|
+
WORK-IN-PROGRESS
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
`` ruby
|
25
|
+
bundle exec darklite
|
26
|
+
``
|
data/Rakefile
ADDED
data/darklite.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
Gem::Specification.new do |spec|
|
2
|
+
spec.name = 'darklite'
|
3
|
+
spec.version = '0.2.0'
|
4
|
+
spec.authors = ['Eric Sigler']
|
5
|
+
spec.email = ['me@esigler.com']
|
6
|
+
spec.description = 'A small daemon to manage Internet-connected lights.'
|
7
|
+
spec.summary = spec.description
|
8
|
+
spec.homepage = 'https://github.com/esigler/darklite'
|
9
|
+
spec.license = 'MIT'
|
10
|
+
|
11
|
+
spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
12
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
13
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
14
|
+
spec.require_paths = ['lib']
|
15
|
+
|
16
|
+
spec.add_runtime_dependency 'huey'
|
17
|
+
spec.add_runtime_dependency 'ruby-sun-times'
|
18
|
+
|
19
|
+
spec.add_development_dependency 'bundler'
|
20
|
+
spec.add_development_dependency 'coveralls'
|
21
|
+
spec.add_development_dependency 'rake'
|
22
|
+
spec.add_development_dependency 'rspec'
|
23
|
+
spec.add_development_dependency 'rubocop'
|
24
|
+
spec.add_development_dependency 'simplecov'
|
25
|
+
end
|
data/lib/darklite.rb
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
# Code's gotta go somewhere
|
2
|
+
module Darklite
|
3
|
+
# Utilities for common use
|
4
|
+
class Utils
|
5
|
+
# TODO: Convert to runtime config
|
6
|
+
NIGHTTIME_CT = 500
|
7
|
+
EVENING_CT = 294
|
8
|
+
DAYTIME_CT = 153
|
9
|
+
|
10
|
+
def self.change_lights(brightness, temperature)
|
11
|
+
Huey::Bulb.all.update(bri: brightness, ct: temperature, on: true)
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.turn_off_lights
|
15
|
+
Huey::Bulb.all.update(on: false)
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.convert_to_seconds(time)
|
19
|
+
(time.hour * 3600) + (time.min * 60) + time.sec
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.interpolate(start, stop, step, resolution)
|
23
|
+
ratio = step.to_f / resolution.to_f
|
24
|
+
|
25
|
+
if start < stop
|
26
|
+
(((stop - start) * ratio) + start).round
|
27
|
+
else
|
28
|
+
(((start - stop) * (1 - ratio)) + stop).round
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# TODO: Convert from fixed windows to proper twilight/dusk calculations
|
33
|
+
# rubocop:disable AbcSize, MethodLength
|
34
|
+
def self.estimate_color_temperature(current_time, sunrise_time, sunset_time)
|
35
|
+
current = convert_to_seconds(current_time)
|
36
|
+
sunrise = convert_to_seconds(sunrise_time)
|
37
|
+
sunset = convert_to_seconds(sunset_time)
|
38
|
+
|
39
|
+
case current
|
40
|
+
# Morning Transition -> Daytime
|
41
|
+
when sunrise + 1..sunrise + 600
|
42
|
+
interpolate(NIGHTTIME_CT, DAYTIME_CT, (current - sunrise), 600)
|
43
|
+
# Daytime -> Evening Transition
|
44
|
+
when sunrise + 601..sunset - 1800
|
45
|
+
DAYTIME_CT
|
46
|
+
# Evening Transition -> Evening
|
47
|
+
when sunset - 1799..sunset + 2400
|
48
|
+
interpolate(DAYTIME_CT, EVENING_CT, current - (sunset - 1799), 4200)
|
49
|
+
# Evening -> Night Transition
|
50
|
+
when sunset + 2401..sunset + 7199
|
51
|
+
interpolate(EVENING_CT, NIGHTTIME_CT, current - (sunset + 2401), 4800)
|
52
|
+
else
|
53
|
+
NIGHTTIME_CT
|
54
|
+
end
|
55
|
+
end
|
56
|
+
# rubocop:enable AbcSize, MethodLength
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
describe Darklite::Utils do
|
2
|
+
let(:first_second) do
|
3
|
+
Time.local(2015, 9, 1, 0, 0, 1)
|
4
|
+
end
|
5
|
+
|
6
|
+
let(:last_second) do
|
7
|
+
Time.local(2015, 9, 1, 23, 59, 59)
|
8
|
+
end
|
9
|
+
|
10
|
+
let(:sunrise) do
|
11
|
+
Time.local(2015, 9, 1, 6, 40, 0)
|
12
|
+
end
|
13
|
+
|
14
|
+
let(:sunset) do
|
15
|
+
Time.local(2015, 9, 1, 19, 39, 0)
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '#convert_to_seconds' do
|
19
|
+
it 'returns time in seconds' do
|
20
|
+
expect(described_class.convert_to_seconds(first_second)).to eq(1)
|
21
|
+
expect(described_class.convert_to_seconds(last_second)).to eq(86_399)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe '#estimate_color_temperature' do
|
26
|
+
it 'is NIGHTTIME_CT from midnight until sunrise' do
|
27
|
+
expect_color_estimate(first_second, sunrise, sunset, 500)
|
28
|
+
expect_color_estimate(sunrise, sunrise, sunset, 500)
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'moves to DAYTIME_CT at sunrise' do
|
32
|
+
expect_color_estimate(sunrise + 1, sunrise, sunset, 499)
|
33
|
+
expect_color_estimate(sunrise + 600, sunrise, sunset, 153)
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'stays at DAYTIME_CT from after sunrise to before sunset' do
|
37
|
+
expect_color_estimate(sunrise + 601, sunrise, sunset, 153)
|
38
|
+
expect_color_estimate(sunset - 1800, sunrise, sunset, 153)
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'moves to EVENING_CT around sunset' do
|
42
|
+
expect_color_estimate(sunset - 1799, sunrise, sunset, 153)
|
43
|
+
expect_color_estimate(sunset - 1000, sunrise, sunset, 180)
|
44
|
+
expect_color_estimate(sunset + 2400, sunrise, sunset, 294)
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'moves to NIGHTTIME_CT after sunset' do
|
48
|
+
expect_color_estimate(sunset + 2401, sunrise, sunset, 294)
|
49
|
+
expect_color_estimate(sunset + 5000, sunrise, sunset, 406)
|
50
|
+
expect_color_estimate(sunset + 7199, sunrise, sunset, 500)
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'is NIGHTTIME_CT after sunset until midnight' do
|
54
|
+
expect_color_estimate(sunset + 7200, sunrise, sunset, 500)
|
55
|
+
expect_color_estimate(last_second, sunrise, sunset, 500)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
require 'coveralls'
|
3
|
+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
4
|
+
SimpleCov::Formatter::HTMLFormatter,
|
5
|
+
Coveralls::SimpleCov::Formatter
|
6
|
+
]
|
7
|
+
SimpleCov.start { add_filter '/spec/' }
|
8
|
+
|
9
|
+
require 'darklite'
|
10
|
+
|
11
|
+
RSpec.configure do |config|
|
12
|
+
config.expect_with :rspec do |expectations|
|
13
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
14
|
+
end
|
15
|
+
|
16
|
+
config.mock_with :rspec do |mocks|
|
17
|
+
mocks.verify_partial_doubles = true
|
18
|
+
end
|
19
|
+
|
20
|
+
config.filter_run :focus
|
21
|
+
config.run_all_when_everything_filtered = true
|
22
|
+
config.default_formatter = 'doc' if config.files_to_run.one?
|
23
|
+
config.order = :random
|
24
|
+
config.color = true
|
25
|
+
config.profile_examples = true
|
26
|
+
|
27
|
+
Kernel.srand config.seed
|
28
|
+
end
|
29
|
+
|
30
|
+
def expect_color_estimate(time, sunrise, sunset, value)
|
31
|
+
expect(Darklite::Utils.estimate_color_temperature(time,
|
32
|
+
sunrise,
|
33
|
+
sunset)).to eq(value)
|
34
|
+
end
|
metadata
ADDED
@@ -0,0 +1,171 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: darklite
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Eric Sigler
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-09-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: huey
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: ruby-sun-times
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: coveralls
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rubocop
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: simplecov
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
description: A small daemon to manage Internet-connected lights.
|
126
|
+
email:
|
127
|
+
- me@esigler.com
|
128
|
+
executables: []
|
129
|
+
extensions: []
|
130
|
+
extra_rdoc_files: []
|
131
|
+
files:
|
132
|
+
- ".gitignore"
|
133
|
+
- ".rspec"
|
134
|
+
- ".travis.yml"
|
135
|
+
- CONTRIBUTING.md
|
136
|
+
- Gemfile
|
137
|
+
- LICENSE
|
138
|
+
- README.md
|
139
|
+
- Rakefile
|
140
|
+
- darklite.gemspec
|
141
|
+
- lib/darklite.rb
|
142
|
+
- lib/darklite/utils.rb
|
143
|
+
- spec/darklite/utils_spec.rb
|
144
|
+
- spec/spec_helper.rb
|
145
|
+
homepage: https://github.com/esigler/darklite
|
146
|
+
licenses:
|
147
|
+
- MIT
|
148
|
+
metadata: {}
|
149
|
+
post_install_message:
|
150
|
+
rdoc_options: []
|
151
|
+
require_paths:
|
152
|
+
- lib
|
153
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
154
|
+
requirements:
|
155
|
+
- - ">="
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: '0'
|
158
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
159
|
+
requirements:
|
160
|
+
- - ">="
|
161
|
+
- !ruby/object:Gem::Version
|
162
|
+
version: '0'
|
163
|
+
requirements: []
|
164
|
+
rubyforge_project:
|
165
|
+
rubygems_version: 2.4.5
|
166
|
+
signing_key:
|
167
|
+
specification_version: 4
|
168
|
+
summary: A small daemon to manage Internet-connected lights.
|
169
|
+
test_files:
|
170
|
+
- spec/darklite/utils_spec.rb
|
171
|
+
- spec/spec_helper.rb
|