lifx_toys 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5c038c4caa934ea7b44ef3025d046b5bc48168bc
4
- data.tar.gz: de8871517e7b634e09184e5e4b7324ffea3c6abf
3
+ metadata.gz: bb81a9c174f6d6500406ea22b2e5a54f5c3b173d
4
+ data.tar.gz: 9c280ab0442764a220f1eea8256cd0fd46c4b571
5
5
  SHA512:
6
- metadata.gz: baf5b2e3328cfd1393faf58fa551e1540a81a060b9dac131d16937b174645f4b4f47521e1519d21fab1fb0fa3fe5f8595bdcd1592543442b5cbb8ccd907151e6
7
- data.tar.gz: 2d7a6f82db6bb3faa7e03ae217a9feff1380c09e4d7d3ab36eec63ab0e3945d67dc98d6e41f57222cb1e46da7e9a41c175bf49ff6bf3fb0e8ccacc47a5539736
6
+ metadata.gz: c592852db5a890a919e55177d06c0074138be9394aaf0fdcde8b2ba88c38524fbc3ff82581447762c1caf88917a496d9a8480f01bfe8e15c7676bae8275f3fbc
7
+ data.tar.gz: 416d666cbfe235a748a6adabe7e0315fdb1d9ad8374920577fcf52c5ecb61c2ff3cef2b82df32b7177d5aef1bda639ed780a00a7ed0963264a78d1108047f440
data/Rakefile CHANGED
@@ -1,9 +1,5 @@
1
1
  require "bundler/gem_tasks"
2
2
  require "rake/testtask"
3
- require "lifx_toys"
4
- require "lifx_toys/clouds"
5
- require "lifx_toys/colors"
6
- require "lifx_toys/sunrise"
7
3
 
8
4
  Rake::TestTask.new(:test) do |t|
9
5
  t.libs << "test"
@@ -12,39 +8,3 @@ Rake::TestTask.new(:test) do |t|
12
8
  end
13
9
 
14
10
  task :default => :test
15
-
16
-
17
- desc 'Cloud lighting simulation on all lights'
18
- task :clouds do
19
- LifxToys::Clouds.new.run
20
- end
21
-
22
- desc 'Cycle random Hue, Saturation and brightness on all lights'
23
- task :colors do
24
- LifxToys::Colors.new.run
25
- end
26
-
27
- desc '30 minute sunrise, 0-15M brightness:0-100% kelvin:2500, 15-30M kelvin:2500-9000'
28
- task :sunrise do
29
- LifxToys::Sunrise.new.run
30
- end
31
-
32
- task :info do
33
- puts all_lights.get_info
34
- end
35
-
36
- task :off do
37
- puts all_lights.set_power_state 'off'
38
- end
39
-
40
- task :on do
41
- puts all_lights.set_power_state 'on'
42
- end
43
-
44
- task :toggle do
45
- puts all_lights.toggle
46
- end
47
-
48
- def all_lights
49
- LifxToys::HttpApi.with_default_selector('all')
50
- end
data/exe/lifx_clouds ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative "../lib/lifx_toys/clouds"
3
+
4
+ LifxToys::Clouds.new.run
data/exe/lifx_colors ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative "../lib/lifx_toys/colors"
3
+
4
+ LifxToys::Colors.new.run
data/exe/lifx_rainbow ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative "../lib/lifx_toys/rainbow"
3
+
4
+ LifxToys::Rainbow.new.run
data/exe/lifx_sunrise ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative "../lib/lifx_toys/sunrise"
3
+
4
+ LifxToys::Sunrise.new.run
data/lib/lifx_toys.rb CHANGED
@@ -1,6 +1,4 @@
1
1
  require "lifx_toys/version"
2
- require "lifx_toys/http_api"
3
- require "lifx_toys/lifx_light"
4
2
 
5
3
  module LifxToys
6
4
  # Your code goes here...
@@ -1,4 +1,4 @@
1
- require_relative "lifx_light"
1
+ require 'lifx_http'
2
2
  module LifxToys
3
3
  class Clouds
4
4
 
@@ -11,7 +11,7 @@ module LifxToys
11
11
  CYCLE_TIME = 5.0
12
12
 
13
13
  def initialize
14
- @lights = LifxLight.get_lights.select{|x| x.connected }
14
+ @lights = LifxHttp::LifxLight.get_lights.select{|x| x.connected }
15
15
  end
16
16
 
17
17
  def run
@@ -1,4 +1,4 @@
1
- require_relative "lifx_light"
1
+ require "lifx_http"
2
2
 
3
3
  module LifxToys
4
4
  class Colors
@@ -10,7 +10,7 @@ module LifxToys
10
10
  CYCLE_TIME = 10.0
11
11
 
12
12
  def initialize
13
- @lights = LifxLight.get_lights.select{|x| x.connected }
13
+ @lights = LifxHttp::LifxLight.get_lights.select{|x| x.connected }
14
14
  end
15
15
 
16
16
  def run
@@ -0,0 +1,34 @@
1
+ require "lifx_http"
2
+ module LifxToys
3
+ class Rainbow
4
+
5
+ CYCLE_TIME = 1
6
+
7
+ def initialize
8
+ @lights = LifxHttp::LifxLight.get_lights.select{|x| x.connected }
9
+ puts "Running with #{light_count} lights..."
10
+ end
11
+
12
+ def light_count
13
+ @lights.count
14
+ end
15
+
16
+ def run
17
+ @lights.each{|x| x.set_color("saturation:1 brightness:1", duration: 0)}
18
+ while (true)
19
+ (0...36).each do |color|
20
+ @lights.each_with_index do |light, light_number|
21
+ light.set_color(color_for_light(color * 10, light_number), duration: CYCLE_TIME)
22
+ end
23
+ sleep(CYCLE_TIME)
24
+ end
25
+ end
26
+ end
27
+
28
+ def color_for_light(base_color, index)
29
+ offset = (360/light_count) * index
30
+ "hue:#{((base_color) + offset) % 360}"
31
+ end
32
+
33
+ end
34
+ end
@@ -1,4 +1,4 @@
1
- require_relative "lifx_light"
1
+ require "lifx_http"
2
2
  module LifxToys
3
3
  class Sunrise
4
4
 
@@ -30,7 +30,7 @@ module LifxToys
30
30
  @end_brightness = end_brightness
31
31
  @end_temperature = end_temperature
32
32
 
33
- @lights = HttpApi.with_default_selector(selector)
33
+ @lights = LifxHttp::Api.with_default_selector(selector)
34
34
  end
35
35
 
36
36
  # warning: this method takes half the sunrise time to execute
@@ -1,3 +1,3 @@
1
1
  module LifxToys
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
data/lifx_toys.gemspec CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["lparry@gmail.com"]
11
11
 
12
12
  spec.summary = %q{Lucas's LIFX toys}
13
- spec.description = %q{ruby wrapper and toys for the LIFX cloud api}
13
+ spec.description = %q{Toys for the LIFX bulbs}
14
14
  spec.homepage = "https://github.com/lparry/lifx_toys"
15
15
  spec.license = "MIT"
16
16
 
@@ -19,10 +19,20 @@ Gem::Specification.new do |spec|
19
19
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
20
  spec.require_paths = ["lib"]
21
21
 
22
+ spec.post_install_message = <<-DOC
23
+ ==============================================================================
24
+ This gem no longer contains the Http Api code. Sorry!
25
+
26
+ On the freak chance you were already using it, that stuff is now in the \'lifx_http\' gem.
27
+ ==============================================================================
28
+ DOC
29
+
22
30
  spec.add_development_dependency "bundler", "~> 1.10"
23
31
  spec.add_development_dependency "rake", "~> 10.0"
24
32
  spec.add_development_dependency "minitest", "~> 5.7"
25
33
  spec.add_development_dependency "pry", "~> 0.10"
26
34
  spec.add_dependency "json", "~> 1.8"
27
35
  spec.add_dependency "httparty", "~> 0.13"
36
+ spec.add_dependency "lifx", "~> 0.4"
37
+ spec.add_dependency "lifx_http", "~> 0.2"
28
38
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lifx_toys
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lucas Parry
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-08-03 00:00:00.000000000 Z
11
+ date: 2015-08-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -94,10 +94,42 @@ dependencies:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0.13'
97
- description: ruby wrapper and toys for the LIFX cloud api
97
+ - !ruby/object:Gem::Dependency
98
+ name: lifx
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.4'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.4'
111
+ - !ruby/object:Gem::Dependency
112
+ name: lifx_http
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '0.2'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '0.2'
125
+ description: Toys for the LIFX bulbs
98
126
  email:
99
127
  - lparry@gmail.com
100
- executables: []
128
+ executables:
129
+ - lifx_clouds
130
+ - lifx_colors
131
+ - lifx_rainbow
132
+ - lifx_sunrise
101
133
  extensions: []
102
134
  extra_rdoc_files: []
103
135
  files:
@@ -109,12 +141,14 @@ files:
109
141
  - Rakefile
110
142
  - bin/console
111
143
  - bin/setup
144
+ - exe/lifx_clouds
145
+ - exe/lifx_colors
146
+ - exe/lifx_rainbow
147
+ - exe/lifx_sunrise
112
148
  - lib/lifx_toys.rb
113
149
  - lib/lifx_toys/clouds.rb
114
150
  - lib/lifx_toys/colors.rb
115
- - lib/lifx_toys/http_api.rb
116
- - lib/lifx_toys/http_api/with_default_selector.rb
117
- - lib/lifx_toys/lifx_light.rb
151
+ - lib/lifx_toys/rainbow.rb
118
152
  - lib/lifx_toys/sunrise.rb
119
153
  - lib/lifx_toys/version.rb
120
154
  - lifx_toys.gemspec
@@ -122,7 +156,12 @@ homepage: https://github.com/lparry/lifx_toys
122
156
  licenses:
123
157
  - MIT
124
158
  metadata: {}
125
- post_install_message:
159
+ post_install_message: |
160
+ ==============================================================================
161
+ This gem no longer contains the Http Api code. Sorry!
162
+
163
+ On the freak chance you were already using it, that stuff is now in the 'lifx_http' gem.
164
+ ==============================================================================
126
165
  rdoc_options: []
127
166
  require_paths:
128
167
  - lib
@@ -1,105 +0,0 @@
1
- require 'httparty'
2
- require_relative 'http_api/with_default_selector'
3
-
4
- module LifxToys
5
- module HttpApi
6
- class << self
7
-
8
- def with_default_selector(selector)
9
- WithDefaultSelector.new(selector)
10
- end
11
-
12
- def set_color(selector, color, options = { duration: 2.0,
13
- power_on: true})
14
- HTTParty.put(color_url(selector),
15
- headers: authorization_headers,
16
- query: options.merge({
17
- color: color
18
- })).tap do |response|
19
- if response.success?
20
- puts "info: set #{selector} to #{color}" if ENV["DEBUG"]
21
- nil
22
- else
23
- puts "warning: light status - #{response}"
24
- -1
25
- end
26
- end
27
- end
28
-
29
- def get_info(selector)
30
- HTTParty.get(info_url(selector),
31
- headers: authorization_headers)
32
- end
33
-
34
- def set_power_state(selector, state, options = {duration: 2})
35
- HTTParty.put(power_url(selector),
36
- headers: authorization_headers,
37
- query: options.merge({
38
- state: state
39
- }))
40
- end
41
-
42
- def toggle_power_state(selector)
43
- HTTParty.post(toggle_power_url(selector),
44
- headers: authorization_headers)
45
- end
46
-
47
- def breathe(selector, color, options = {
48
- period: 1.0,
49
- cycles: 1.0,
50
- persist: false,
51
- power_on: true,
52
- peak: 0.5 })
53
- HTTParty.post(breathe_url(selector),
54
- headers: authorization_headers,
55
- query: options.merge({
56
- color: color
57
- }))
58
- end
59
-
60
- def pulse(selector, color, options = {
61
- # from_color: current_bulb_color,
62
- period: 1.0,
63
- cycles: 1.0,
64
- persist: false,
65
- power_on: true,
66
- peak: 1.0 })
67
- HTTParty.post(pulse_url(selector),
68
- headers: authorization_headers,
69
- query: options.merge({
70
- color: color
71
- }))
72
- end
73
-
74
- private
75
-
76
- def info_url(selector)
77
- "https://api.lifx.com/v1beta1/lights/#{selector}"
78
- end
79
-
80
- def color_url(selector)
81
- "#{info_url(selector)}/color"
82
- end
83
-
84
- def power_url(selector)
85
- "#{info_url(selector)}/power"
86
- end
87
-
88
- def toggle_power_url(selector)
89
- "#{info_url(selector)}/toggle"
90
- end
91
-
92
- def breathe_url(selector)
93
- "#{info_url(selector)}/effects/breathe"
94
- end
95
-
96
- def pulse_url(selector)
97
- "#{info_url(selector)}/effects/pulse"
98
- end
99
-
100
- def authorization_headers
101
- {"Authorization" => "Bearer #{ENV["LIFX_TOKEN"]}"}
102
- end
103
- end
104
- end
105
- end
@@ -1,30 +0,0 @@
1
- require_relative '../http_api'
2
-
3
- module LifxToys
4
- module HttpApi
5
-
6
- class WithDefaultSelector
7
-
8
- attr_reader :selector
9
-
10
- def initialize(selector)
11
- @selector = selector
12
- end
13
-
14
- private
15
-
16
- def method_missing(method_name, *args)
17
- if ::LifxToys::HttpApi.respond_to? method_name
18
- ::LifxToys::HttpApi.public_send(method_name, selector, *args)
19
- else
20
- raise
21
- end
22
- end
23
-
24
- def make_request(method_name, *args)
25
- HttpApi.public_send(method_name, selector, *args)
26
- end
27
- end
28
-
29
- end
30
- end
@@ -1,42 +0,0 @@
1
- require 'forwardable'
2
- require_relative 'http_api'
3
-
4
- module LifxToys
5
- class LifxLight
6
-
7
- extend Forwardable
8
- def_delegators :@data, :label, :connected, :power, :color, :brightness, :product_name, :last_seen, :seconds_since_seen
9
- def_delegators :@http_api, :set_color
10
-
11
- attr_reader :light_id
12
-
13
- def self.get_lights
14
- @lights ||= HttpApi.with_default_selector("all").get_info.map do |data|
15
- LifxLight.new(data)
16
- end
17
- end
18
-
19
- def initialize(data)
20
- @light_id = data["id"]
21
- @data = OpenStruct.new(data)
22
- @updated_at = Time.now
23
- @http_api = HttpApi.with_default_selector(selector)
24
- end
25
-
26
- def update_info
27
- @data ||= OpenStruct.new(@http_api.get_info)
28
- @updated_at = Time.now
29
- end
30
-
31
- def inspect
32
- "#<#{self.class.name} light_id=#{light_id.inspect} label=#{label.inspect} connected=#{connected.inspect} power=#{power.inspect} color=#{color.inspect} brightness=#{brightness.inspect} product_name=#{product_name.inspect} last_seen=#{last_seen.inspect} seconds_since_seen=#{seconds_since_seen.inspect} @updated_at=#{@updated_at}>"
33
- end
34
-
35
- private
36
-
37
- def selector
38
- "id:#{light_id}"
39
- end
40
-
41
- end
42
- end