light_me_up 0.2.5 → 0.2.8
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 +4 -2
- data/lib/light_me_up/api_client.rb +19 -5
- data/lib/light_me_up/light_serializer.rb +4 -2
- data/lib/light_me_up/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4706c4eb47c5cb6f0745812c3d71fa6705eb0b89983f81ff5920e1ae8278ea3c
|
4
|
+
data.tar.gz: ea36d55e8640514bfced3e4cb19ec15c262c9947cd24c7ebbce638295136e22a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8a850ec31386fb7c9b08b25c0f7ccaf483303d03080fabfa63a5b33da7b472f6743b1a03b7817d0da4e0d1a3379f122e3218fe796260234e6812a2b824f3577f
|
7
|
+
data.tar.gz: 929a547cf62f6865e02b4de1b865739f8d42bdb95f19a12930b5135feb39bdec9ca59d4ad24dd1eb1ebe022fe20d554bd27eed3d1df95dd996a71b4f732f2a28
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
light_me_up (0.2.
|
4
|
+
light_me_up (0.2.8)
|
5
5
|
optimist (~> 3.0)
|
6
6
|
|
7
7
|
GEM
|
@@ -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
@@ -17,14 +17,16 @@ temperature_help = format(
|
|
17
17
|
|
18
18
|
options = Optimist.options do
|
19
19
|
banner "Usage: #{$PROGRAM_NAME} [options]"
|
20
|
+
version "light-me-up #{LightMeUp::VERSION}"
|
20
21
|
|
21
22
|
opt :toggle, "Toggle whether the lights are on or off", short: "T"
|
22
23
|
opt :on, "Turn the light on"
|
23
24
|
opt :off, "Turn the light off", short: "O"
|
24
|
-
opt :ip_address, "Specify the IP address", type: :string, default: ENV
|
25
|
+
opt :ip_address, "Specify the IP address", type: :string, default: ENV.fetch("ELGATO_IP_ADDRESS", nil)
|
25
26
|
opt :defaults, "Set to default values"
|
26
27
|
opt :brightness, brightness_help, type: :integer
|
27
28
|
opt :temperature, temperature_help, type: :integer
|
29
|
+
opt :version, "Print version number and exit"
|
28
30
|
end
|
29
31
|
|
30
32
|
options = options.select { |_k, v| v }
|
@@ -32,7 +34,7 @@ options[:on] = false if options.delete(:off)
|
|
32
34
|
if options.delete(:defaults)
|
33
35
|
options = {
|
34
36
|
brightness: ENV["ELGATO_DEFAULT_BRIGHTNESS"].to_i,
|
35
|
-
temperature: ENV["ELGATO_DEFAULT_TEMPERATURE"].to_i
|
37
|
+
temperature: ENV["ELGATO_DEFAULT_TEMPERATURE"].to_i,
|
36
38
|
}.merge(options)
|
37
39
|
end
|
38
40
|
|
@@ -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
|
@@ -38,8 +38,10 @@ module LightMeUp
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def scale_value(value, src_range, dest_range)
|
41
|
-
|
42
|
-
|
41
|
+
return nil unless value
|
42
|
+
|
43
|
+
scale_ratio = dest_range.size.to_f / src_range.size
|
44
|
+
(dest_range.min + (scale_ratio * (value - src_range.min))).round
|
43
45
|
end
|
44
46
|
end
|
45
47
|
end
|
data/lib/light_me_up/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.8
|
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
|
@@ -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.
|