light_me_up 0.2.6 → 0.2.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +12 -12
- data/bin/light-me-up +2 -2
- data/lib/light_me_up/api_client.rb +19 -5
- data/lib/light_me_up/light_serializer.rb +2 -2
- data/lib/light_me_up/version.rb +1 -1
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e961aef3afa051d666e6d6058ebd148d78195424ee3651c61a415193dd792dc3
|
4
|
+
data.tar.gz: 26d18eea5934f3c9dfdfc2e2be189dc67d2ab63b60c2aaa73bba1d74a8b8fc6e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9dfdd4bde34dd55362e68f8c7f7b4399d0142040a47667c72e68b79396c1d3125e451fa06329b1e4aed01fc6ab182b647c13ef636fce79caa78e27e61eb70a08
|
7
|
+
data.tar.gz: cbe15d94b545f50e41d72abd443e161472586a5f712db1ff338d03b9ca4bcc60ead4141b72702b904b67980d0bc35ded658f7301310145fb2d2e21d123f92750
|
data/Gemfile.lock
CHANGED
@@ -2,7 +2,7 @@ PATH
|
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
4
|
light_me_up (0.2.6)
|
5
|
-
optimist
|
5
|
+
optimist
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
@@ -10,25 +10,25 @@ GEM
|
|
10
10
|
ast (2.4.2)
|
11
11
|
minitest (5.15.0)
|
12
12
|
optimist (3.0.1)
|
13
|
-
parallel (1.
|
14
|
-
parser (3.
|
13
|
+
parallel (1.22.1)
|
14
|
+
parser (3.1.2.0)
|
15
15
|
ast (~> 2.4.1)
|
16
|
-
rainbow (3.
|
16
|
+
rainbow (3.1.1)
|
17
17
|
rake (13.0.6)
|
18
|
-
regexp_parser (2.
|
18
|
+
regexp_parser (2.4.0)
|
19
19
|
rexml (3.2.5)
|
20
|
-
rubocop (1.
|
20
|
+
rubocop (1.29.0)
|
21
21
|
parallel (~> 1.10)
|
22
|
-
parser (>= 3.
|
22
|
+
parser (>= 3.1.0.0)
|
23
23
|
rainbow (>= 2.2.2, < 4.0)
|
24
24
|
regexp_parser (>= 1.8, < 3.0)
|
25
|
-
rexml
|
26
|
-
rubocop-ast (>= 1.
|
25
|
+
rexml (>= 3.2.5, < 4.0)
|
26
|
+
rubocop-ast (>= 1.17.0, < 2.0)
|
27
27
|
ruby-progressbar (~> 1.7)
|
28
28
|
unicode-display_width (>= 1.4.0, < 3.0)
|
29
|
-
rubocop-ast (1.
|
30
|
-
parser (>= 3.
|
31
|
-
rubocop-minitest (0.
|
29
|
+
rubocop-ast (1.17.0)
|
30
|
+
parser (>= 3.1.1.0)
|
31
|
+
rubocop-minitest (0.19.1)
|
32
32
|
rubocop (>= 0.90, < 2.0)
|
33
33
|
rubocop-rake (0.6.0)
|
34
34
|
rubocop (~> 1.0)
|
data/bin/light-me-up
CHANGED
@@ -21,7 +21,7 @@ options = Optimist.options do
|
|
21
21
|
opt :toggle, "Toggle whether the lights are on or off", short: "T"
|
22
22
|
opt :on, "Turn the light on"
|
23
23
|
opt :off, "Turn the light off", short: "O"
|
24
|
-
opt :ip_address, "Specify the IP address", type: :string, default: ENV
|
24
|
+
opt :ip_address, "Specify the IP address", type: :string, default: ENV.fetch("ELGATO_IP_ADDRESS", nil)
|
25
25
|
opt :defaults, "Set to default values"
|
26
26
|
opt :brightness, brightness_help, type: :integer
|
27
27
|
opt :temperature, temperature_help, type: :integer
|
@@ -32,7 +32,7 @@ options[:on] = false if options.delete(:off)
|
|
32
32
|
if options.delete(:defaults)
|
33
33
|
options = {
|
34
34
|
brightness: ENV["ELGATO_DEFAULT_BRIGHTNESS"].to_i,
|
35
|
-
temperature: ENV["ELGATO_DEFAULT_TEMPERATURE"].to_i
|
35
|
+
temperature: ENV["ELGATO_DEFAULT_TEMPERATURE"].to_i,
|
36
36
|
}.merge(options)
|
37
37
|
end
|
38
38
|
|
@@ -9,14 +9,16 @@ module LightMeUp
|
|
9
9
|
LIGHTS_PATH = "/elgato/lights"
|
10
10
|
OPEN_TIMEOUT = 2 # seconds
|
11
11
|
READ_TIMEOUT = 2 # seconds
|
12
|
+
MAX_RETRIES = 2
|
12
13
|
|
13
14
|
TEMPERATURE_RANGE = (143..344).freeze
|
14
15
|
|
15
|
-
def initialize(ip_address:, port: DEFAULT_PORT)
|
16
|
+
def initialize(ip_address:, retries: MAX_RETRIES, port: DEFAULT_PORT)
|
16
17
|
raise Error, "No ip_address specified." unless ip_address && ip_address != ""
|
17
18
|
|
18
19
|
@ip_address = ip_address
|
19
20
|
@port = port
|
21
|
+
@max_retries = retries
|
20
22
|
end
|
21
23
|
|
22
24
|
def status
|
@@ -58,7 +60,7 @@ module LightMeUp
|
|
58
60
|
|
59
61
|
private
|
60
62
|
|
61
|
-
attr_reader :ip_address, :port, :connection
|
63
|
+
attr_reader :ip_address, :port, :connection, :max_retries
|
62
64
|
|
63
65
|
def lights_uri
|
64
66
|
URI::HTTP.build(host: ip_address, port: port, path: LIGHTS_PATH)
|
@@ -90,13 +92,25 @@ module LightMeUp
|
|
90
92
|
!!@connection
|
91
93
|
end
|
92
94
|
|
93
|
-
def with_connection
|
95
|
+
def with_connection(&block)
|
96
|
+
retries = 0
|
97
|
+
begin
|
98
|
+
start_connection(&block)
|
99
|
+
rescue Errno::EHOSTDOWN
|
100
|
+
raise Error, "Couldn't connect to lights."
|
101
|
+
rescue Net::OpenTimeout
|
102
|
+
raise Error, "Timeout connecting to lights." if retries >= max_retries
|
103
|
+
|
104
|
+
retries += 1
|
105
|
+
retry
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def start_connection
|
94
110
|
Net::HTTP.start(ip_address, port, open_timeout: OPEN_TIMEOUT, read_timeout: READ_TIMEOUT) do |connection|
|
95
111
|
@connection = connection
|
96
112
|
yield
|
97
113
|
end
|
98
|
-
rescue Errno::EHOSTDOWN, Net::OpenTimeout
|
99
|
-
raise Error, "Couldn't connect to lights."
|
100
114
|
ensure
|
101
115
|
@connection = nil
|
102
116
|
end
|
@@ -40,8 +40,8 @@ module LightMeUp
|
|
40
40
|
def scale_value(value, src_range, dest_range)
|
41
41
|
return nil unless value
|
42
42
|
|
43
|
-
scale_ratio = dest_range.size.to_f / src_range.size
|
44
|
-
(dest_range.min + scale_ratio * (value - src_range.min)).round
|
43
|
+
scale_ratio = dest_range.size.to_f / src_range.size
|
44
|
+
(dest_range.min + (scale_ratio * (value - src_range.min))).round
|
45
45
|
end
|
46
46
|
end
|
47
47
|
end
|
data/lib/light_me_up/version.rb
CHANGED
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: light_me_up
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter McCracken
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-05-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: optimist
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '0'
|
27
27
|
description: Provides the ability to turn on and off, and adjust brightness and temperature,
|
28
28
|
on a key light.
|
29
29
|
email:
|
@@ -74,7 +74,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '0'
|
76
76
|
requirements: []
|
77
|
-
rubygems_version: 3.
|
77
|
+
rubygems_version: 3.3.7
|
78
78
|
signing_key:
|
79
79
|
specification_version: 4
|
80
80
|
summary: Command line control for a brand name key light.
|