rubyhue 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/lib/rubyhue/huebulb.rb +40 -0
- data/lib/rubyhue/huegroup.rb +11 -0
- data/lib/rubyhue.rb +90 -0
- metadata +46 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
YTAzMmQ0Y2I4ZDdjM2IxZmI5ODY3Y2ZmMGZkYWE1Nzg4ZmE1NTJkMA==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
OWQ5OWI1ZjU2NTg1OGM2NGY4MGE0OTU5NmNmMGUxNWNlZTYzOGExOA==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
NjI4YzhlZTg5ZjhiZGY3NDllODcwMmY4NjJiZmFiMDU0YTA3Yjk1OWVhMDAy
|
10
|
+
ZjE1MGQyN2FlMTNhNmJjYmFhNGQ3MGRkMjI1NTYyN2VmYWEyZjM2NDdmNTlm
|
11
|
+
OTMwYTc1NDc3ZDYzNDc2ZmY5YTc2MjMzYzdhYzM0MzUwZDg3MTY=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
NDY5MDViNGNlNDU1NTk4YTkyZjQwOWViOTFiNmIyZGMxYWE0YTdlZWFkZjZh
|
14
|
+
YmEyYWEyMmY0ZTk4YTY2YzZmMzNmNDQ3MWEzYjJhMTQ3NGRiOGQzMGVkOTRk
|
15
|
+
MTEyYjdiYzUyOWYwYTllYTdiMmE2NGQ5NmIyYjg4OTliODZkMDQ=
|
@@ -0,0 +1,40 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
class HueBulb
|
4
|
+
|
5
|
+
attr_reader :id, :name, :type, :swversion,
|
6
|
+
:state, :data
|
7
|
+
|
8
|
+
def initialize(id,data = {})
|
9
|
+
@data = data
|
10
|
+
@id = id
|
11
|
+
@name = data["name"]
|
12
|
+
@type = data["type"]
|
13
|
+
@swversion = data["type"]
|
14
|
+
@state = HueBulbState.new data["state"]
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
class HueBulbState
|
21
|
+
|
22
|
+
attr_reader :on, :bri, :hue, :sat, :xy, :ct,
|
23
|
+
:alert, :effect, :colormode,
|
24
|
+
:reachable, :data
|
25
|
+
|
26
|
+
def initialize( data = {} )
|
27
|
+
@data = data
|
28
|
+
@on = data["on"]
|
29
|
+
@bri = data["bri"]
|
30
|
+
@hue = data["hue"]
|
31
|
+
@sat = data["sat"]
|
32
|
+
@xy = data["xy"]
|
33
|
+
@ct = data["ct"]
|
34
|
+
@alert = data["alert"]
|
35
|
+
@effect = data["effect"]
|
36
|
+
@colormode = data["colormode"]
|
37
|
+
@reachable = data["reachable"]
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
data/lib/rubyhue.rb
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'net/http'
|
4
|
+
require 'uri'
|
5
|
+
require 'json'
|
6
|
+
|
7
|
+
if __FILE__==$0
|
8
|
+
require './rubyhue/huebulb.rb'
|
9
|
+
require './rubyhue/huegroup.rb'
|
10
|
+
else
|
11
|
+
require 'rubyhue/huebulb.rb'
|
12
|
+
require 'rubyhue/huegroup.rb'
|
13
|
+
end
|
14
|
+
|
15
|
+
def jp( s )
|
16
|
+
puts JSON.pretty_generate( s )
|
17
|
+
end
|
18
|
+
|
19
|
+
class Hue
|
20
|
+
|
21
|
+
attr_reader :bulbs
|
22
|
+
def initialize(ip,username)
|
23
|
+
@ip = ip
|
24
|
+
@username = username
|
25
|
+
@http = Net::HTTP.new(ip,80)
|
26
|
+
@bulbs = []
|
27
|
+
@groups = []
|
28
|
+
end
|
29
|
+
|
30
|
+
def register_username
|
31
|
+
data = { "devicetype"=>"rubyhue",
|
32
|
+
"username"=>@username }
|
33
|
+
response = @http.post "/api", data.to_json
|
34
|
+
JSON.parse response.body
|
35
|
+
end
|
36
|
+
|
37
|
+
def request_config
|
38
|
+
hue_get "config"
|
39
|
+
end
|
40
|
+
|
41
|
+
def add_bulb(id,bulb_data)
|
42
|
+
@bulbs << HueBulb.new( id, bulb_data )
|
43
|
+
end
|
44
|
+
|
45
|
+
def request_bulb_list
|
46
|
+
hue_get "lights"
|
47
|
+
end
|
48
|
+
|
49
|
+
def request_bulb_info( id )
|
50
|
+
hue_get "lights/#{id}"
|
51
|
+
end
|
52
|
+
|
53
|
+
def request_group_list
|
54
|
+
hue_get "groups"
|
55
|
+
end
|
56
|
+
|
57
|
+
def set_bulb_state( id, state )
|
58
|
+
hue_put "lights/#{id}/state", state.data
|
59
|
+
end
|
60
|
+
|
61
|
+
private
|
62
|
+
def hue_get( path )
|
63
|
+
request = Net::HTTP::Get.new( "/api/#{@username}/#{path}" )
|
64
|
+
response = @http.request request
|
65
|
+
JSON.parse response.body
|
66
|
+
end
|
67
|
+
|
68
|
+
def hue_put( path, data )
|
69
|
+
response = @http.put( "/api/#{@username}/#{path}", data.to_json )
|
70
|
+
JSON.parse response.body
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
if __FILE__==$0
|
76
|
+
if ARGV.length < 2
|
77
|
+
STDERR.puts "Invaid args."
|
78
|
+
STDERR.puts "Usage: #{__FILE__} ip username"
|
79
|
+
exit
|
80
|
+
end
|
81
|
+
|
82
|
+
client = Hue.new(ARGV[0],ARGV[1])
|
83
|
+
|
84
|
+
bulbs_response = client.request_bulb_list
|
85
|
+
bulbs_response.each do |id,value|
|
86
|
+
info = client.request_bulb_info( id )
|
87
|
+
client.add_bulb(id,info)
|
88
|
+
puts client.bulbs.last.name
|
89
|
+
end
|
90
|
+
end
|
metadata
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rubyhue
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Brady Turner
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-08-03 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Client library for controlling Phillips Hue lights.
|
14
|
+
email: bradyaturner@gmail.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/rubyhue.rb
|
20
|
+
- lib/rubyhue/huebulb.rb
|
21
|
+
- lib/rubyhue/huegroup.rb
|
22
|
+
homepage: http://rubygems.org/gems/rubyhue
|
23
|
+
licenses:
|
24
|
+
- BAT
|
25
|
+
metadata: {}
|
26
|
+
post_install_message:
|
27
|
+
rdoc_options: []
|
28
|
+
require_paths:
|
29
|
+
- lib
|
30
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ! '>='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ! '>='
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
requirements: []
|
41
|
+
rubyforge_project:
|
42
|
+
rubygems_version: 2.0.6
|
43
|
+
signing_key:
|
44
|
+
specification_version: 4
|
45
|
+
summary: rubyhue
|
46
|
+
test_files: []
|