light_me_up 0.2.4 → 0.2.7
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 +4 -4
- data/Gemfile.lock +13 -13
- data/bin/light-me-up +4 -3
- data/lib/light_me_up/api_client.rb +24 -8
- data/lib/light_me_up/light.rb +1 -1
- data/lib/light_me_up/light_serializer.rb +19 -2
- data/lib/light_me_up/settings_update.rb +6 -11
- 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
@@ -1,8 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
light_me_up (0.2.
|
5
|
-
optimist
|
4
|
+
light_me_up (0.2.6)
|
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
|
|
@@ -42,7 +42,8 @@ begin
|
|
42
42
|
LightMeUp::SettingsUpdate.new(api_client, options).perform
|
43
43
|
rescue LightMeUp::SettingsUpdate::ToggleIncompatible => e
|
44
44
|
Optimist.die :toggle, e.message
|
45
|
-
rescue LightMeUp::SettingsUpdate::
|
45
|
+
rescue LightMeUp::SettingsUpdate::InvalidOptions => e
|
46
|
+
warn e.message
|
46
47
|
Optimist.educate
|
47
48
|
rescue LightMeUp::Error => e
|
48
49
|
warn e.message
|
@@ -9,12 +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
|
15
|
+
|
16
|
+
def initialize(ip_address:, retries: MAX_RETRIES, port: DEFAULT_PORT)
|
14
17
|
raise Error, "No ip_address specified." unless ip_address && ip_address != ""
|
15
18
|
|
16
19
|
@ip_address = ip_address
|
17
20
|
@port = port
|
21
|
+
@max_retries = retries
|
18
22
|
end
|
19
23
|
|
20
24
|
def status
|
@@ -22,14 +26,14 @@ module LightMeUp
|
|
22
26
|
LightSerializer.deserialize(response).first
|
23
27
|
end
|
24
28
|
|
25
|
-
def toggle
|
29
|
+
def toggle(brightness: nil, temperature: nil)
|
26
30
|
with_connection do |_http|
|
27
31
|
current_status = status
|
28
32
|
|
29
33
|
if current_status.on
|
30
|
-
|
34
|
+
update(on: false, brightness: brightness, temperature: temperature)
|
31
35
|
else
|
32
|
-
|
36
|
+
update(on: true, brightness: brightness, temperature: temperature)
|
33
37
|
end
|
34
38
|
end
|
35
39
|
end
|
@@ -56,7 +60,7 @@ module LightMeUp
|
|
56
60
|
|
57
61
|
private
|
58
62
|
|
59
|
-
attr_reader :ip_address, :port, :connection
|
63
|
+
attr_reader :ip_address, :port, :connection, :max_retries
|
60
64
|
|
61
65
|
def lights_uri
|
62
66
|
URI::HTTP.build(host: ip_address, port: port, path: LIGHTS_PATH)
|
@@ -88,13 +92,25 @@ module LightMeUp
|
|
88
92
|
!!@connection
|
89
93
|
end
|
90
94
|
|
91
|
-
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
|
92
110
|
Net::HTTP.start(ip_address, port, open_timeout: OPEN_TIMEOUT, read_timeout: READ_TIMEOUT) do |connection|
|
93
111
|
@connection = connection
|
94
112
|
yield
|
95
113
|
end
|
96
|
-
rescue Errno::EHOSTDOWN, Net::OpenTimeout
|
97
|
-
raise Error, "Couldn't connect to lights."
|
98
114
|
ensure
|
99
115
|
@connection = nil
|
100
116
|
end
|
data/lib/light_me_up/light.rb
CHANGED
@@ -13,7 +13,7 @@ module LightMeUp
|
|
13
13
|
{
|
14
14
|
on: on_as_int,
|
15
15
|
brightness: light.brightness,
|
16
|
-
temperature: light.temperature,
|
16
|
+
temperature: to_api_temperature(light.temperature),
|
17
17
|
}.compact
|
18
18
|
end
|
19
19
|
|
@@ -22,10 +22,27 @@ module LightMeUp
|
|
22
22
|
Light.new(
|
23
23
|
on: light["on"] == 1,
|
24
24
|
brightness: light["brightness"],
|
25
|
-
temperature: light["temperature"]
|
25
|
+
temperature: to_readable_temperature(light["temperature"])
|
26
26
|
)
|
27
27
|
end
|
28
28
|
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def to_readable_temperature(api_temperature)
|
33
|
+
scale_value(api_temperature, ApiClient::TEMPERATURE_RANGE, Light::TEMPERATURE_RANGE)
|
34
|
+
end
|
35
|
+
|
36
|
+
def to_api_temperature(readable_temperature)
|
37
|
+
scale_value(readable_temperature, Light::TEMPERATURE_RANGE, ApiClient::TEMPERATURE_RANGE)
|
38
|
+
end
|
39
|
+
|
40
|
+
def scale_value(value, src_range, dest_range)
|
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
|
45
|
+
end
|
29
46
|
end
|
30
47
|
end
|
31
48
|
end
|
@@ -5,7 +5,7 @@ module LightMeUp
|
|
5
5
|
attr_reader :api_client, :options
|
6
6
|
|
7
7
|
class ToggleIncompatible < Error; end
|
8
|
-
class
|
8
|
+
class InvalidOptions < Error; end
|
9
9
|
|
10
10
|
def initialize(api_client, options)
|
11
11
|
@api_client = api_client
|
@@ -13,21 +13,16 @@ module LightMeUp
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def perform
|
16
|
-
|
17
|
-
|
16
|
+
settings_options = options.slice(:toggle, :on, :brightness, :temperature)
|
17
|
+
if settings_options.delete(:toggle)
|
18
|
+
raise ToggleIncompatible, "is not compatible with on or off" if settings_options.key?(:on)
|
18
19
|
|
19
|
-
api_client.toggle
|
20
|
+
api_client.toggle(**settings_options)
|
20
21
|
elsif settings_options.any?
|
21
22
|
api_client.update(**settings_options)
|
22
23
|
else
|
23
|
-
raise
|
24
|
+
raise InvalidOptions, "At least one option must be provided"
|
24
25
|
end
|
25
26
|
end
|
26
|
-
|
27
|
-
private
|
28
|
-
|
29
|
-
def settings_options
|
30
|
-
@settings_options ||= options.slice(:on, :brightness, :temperature)
|
31
|
-
end
|
32
27
|
end
|
33
28
|
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.
|