light_me_up 0.2.1 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/bin/light-me-up +4 -3
- data/lib/light_me_up/api_client.rb +5 -3
- data/lib/light_me_up/light.rb +1 -1
- data/lib/light_me_up/light_serializer.rb +17 -2
- data/lib/light_me_up/settings_update.rb +8 -15
- data/lib/light_me_up/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a8d795fa88a021f974ba2ef80b74326b1222f1f41a20ba71dbd4ea3be643f468
|
4
|
+
data.tar.gz: 92aec84e39354826ec8bc195e8286bd073b414f96bfe4c51ad437f3406f0972f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2f7a7b3c45989710a289136eb7ef2f2bc6b2999bfa8951679bad760b7c7d3bae01e713ac57e57a365b113439f7cf783c201283c4f210e4917710b9b024518dda
|
7
|
+
data.tar.gz: 956f1e24553299defa116ff3107eab99d285ce02c44378d0f1ed436fefd334d4a39cec8e7c34da0c0846a5a36f7b039f55c3de8dcea6b5fdb4c7150da1487c19
|
data/Gemfile.lock
CHANGED
data/bin/light-me-up
CHANGED
@@ -30,10 +30,10 @@ end
|
|
30
30
|
options = options.select { |_k, v| v }
|
31
31
|
options[:on] = false if options.delete(:off)
|
32
32
|
if options.delete(:defaults)
|
33
|
-
options
|
33
|
+
options = {
|
34
34
|
brightness: ENV["ELGATO_DEFAULT_BRIGHTNESS"].to_i,
|
35
35
|
temperature: ENV["ELGATO_DEFAULT_TEMPERATURE"].to_i
|
36
|
-
)
|
36
|
+
}.merge(options)
|
37
37
|
end
|
38
38
|
|
39
39
|
api_client = LightMeUp::ApiClient.new(ip_address: options[:ip_address])
|
@@ -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::
|
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
|
@@ -10,6 +10,8 @@ module LightMeUp
|
|
10
10
|
OPEN_TIMEOUT = 2 # seconds
|
11
11
|
READ_TIMEOUT = 2 # seconds
|
12
12
|
|
13
|
+
TEMPERATURE_RANGE = (143..344).freeze
|
14
|
+
|
13
15
|
def initialize(ip_address:, port: DEFAULT_PORT)
|
14
16
|
raise Error, "No ip_address specified." unless ip_address && ip_address != ""
|
15
17
|
|
@@ -22,14 +24,14 @@ module LightMeUp
|
|
22
24
|
LightSerializer.deserialize(response).first
|
23
25
|
end
|
24
26
|
|
25
|
-
def toggle
|
27
|
+
def toggle(brightness: nil, temperature: nil)
|
26
28
|
with_connection do |_http|
|
27
29
|
current_status = status
|
28
30
|
|
29
31
|
if current_status.on
|
30
|
-
|
32
|
+
update(on: false, brightness: brightness, temperature: temperature)
|
31
33
|
else
|
32
|
-
|
34
|
+
update(on: true, brightness: brightness, temperature: temperature)
|
33
35
|
end
|
34
36
|
end
|
35
37
|
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,25 @@ 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
|
+
scale_ratio = dest_range.size.to_f / src_range.size.to_f
|
42
|
+
(dest_range.min + scale_ratio * (value - src_range.min)).round
|
43
|
+
end
|
29
44
|
end
|
30
45
|
end
|
31
46
|
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,23 +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
|
-
|
21
|
-
|
22
|
-
if settings_options.any?
|
23
|
-
api_client.set(**settings_options)
|
20
|
+
api_client.toggle(**settings_options)
|
21
|
+
elsif settings_options.any?
|
22
|
+
api_client.update(**settings_options)
|
24
23
|
else
|
25
|
-
raise
|
24
|
+
raise InvalidOptions, "At least one option must be provided"
|
26
25
|
end
|
27
26
|
end
|
28
|
-
|
29
|
-
private
|
30
|
-
|
31
|
-
def settings_options
|
32
|
-
@settings_options ||= options.slice(:on, :brightness, :temperature)
|
33
|
-
end
|
34
27
|
end
|
35
28
|
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.5
|
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-01-
|
11
|
+
date: 2022-01-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: optimist
|