Permalink
Browse files

add color queries

only tested with individual lights so far
hsv seems to have more luck than transforming rgb to cie
note that the hue bulbs are bad at producing certain colors
*cough* like blue
  • Loading branch information...
1 parent 34be072 commit 77de932b52d6328fafd86c86cd005e0d4af503ef @interstateone committed Nov 24, 2012
Showing with 13 additions and 9 deletions.
  1. +13 −9 lib/siriproxy-hue.rb
View
@@ -3,6 +3,7 @@
require "pp"
require "rest_client" # HTTP requests
require "json" # Parse Hue responses
+require "matrix"
################################################################################
#
@@ -62,8 +63,9 @@ def brightness (*args)
end
end
- def color (value)
-
+ def color (hue)
+ url = "#{@@hueIP}/api/#{@@hueKey}/lights/#{@number}/state"
+ RestClient.put(url, {hue: 182*hue, sat: 254}.to_json, content_type: :json)
end
end
@@ -139,14 +141,16 @@ def is_numeric?(obj)
request_completed
end
- value = parseNumbers(value)
- if (is_numeric? value)
- log value
- matchedEntity.brightness(value.to_i)
+ numericValue = parseNumbers(value)
+ if (is_numeric? numericValue)
+ log numericValue
+ matchedEntity.brightness(numericValue.to_i)
else
- # query color for hsl value
- query = "http://www.colourlovers.com/api/colors?keywords=#{query}&numResults=1&format=json"
- # set entity to color value
+ # query colourlovers for first rgb value from the given string
+ url = "http://www.colourlovers.com/api/colors?keywords=#{value}&numResults=1&format=json"
+ response = RestClient.get(url)
+ data = JSON.parse(response)[0]["hsv"]
+ matchedEntity.color(data["hue"])
end
say "There you go."

0 comments on commit 77de932

Please sign in to comment.