Class: Lights
- Inherits:
-
Object
- Object
- Lights
- Defined in:
- lib/lights.rb
Instance Attribute Summary collapse
-
#bulbs ⇒ Object
readonly
Returns the value of attribute bulbs.
Instance Method Summary collapse
- #add_bulb(id, bulb_data) ⇒ Object
- #discover_hubs ⇒ Object
-
#initialize(ip, username) ⇒ Lights
constructor
A new instance of Lights.
- #register_username ⇒ Object
- #request_bulb_info(id) ⇒ Object
- #request_bulb_list ⇒ Object
- #request_config ⇒ Object
- #request_group_info(id) ⇒ Object
- #request_group_list ⇒ Object
- #request_schedule_list ⇒ Object
- #request_sensor_info(id) ⇒ Object
- #request_sensor_list ⇒ Object
- #set_bulb_state(id, state) ⇒ Object
- #set_group_state(id, state) ⇒ Object
Constructor Details
#initialize(ip, username) ⇒ Lights
Returns a new instance of Lights.
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/lights.rb', line 21 def initialize(ip,username) @ip = ip @username = username @http = Net::HTTP.new(ip,80) @bulbs = [] @groups = [] @bridges = [] @logger = Logger.new(STDERR) @logger.level = LoggerConfig::LIGHTS_LEVEL end |
Instance Attribute Details
#bulbs ⇒ Object (readonly)
Returns the value of attribute bulbs.
20 21 22 |
# File 'lib/lights.rb', line 20 def bulbs @bulbs end |
Instance Method Details
#add_bulb(id, bulb_data) ⇒ Object
62 63 64 |
# File 'lib/lights.rb', line 62 def add_bulb(id,bulb_data) @bulbs << Bulb.new( id, bulb_data ) end |
#discover_hubs ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/lights.rb', line 32 def discover_hubs http = Net::HTTP.new("www.meethue.com",443) http.use_ssl = tlights request = Net::HTTP::Get.new( "/api/nupnp" ) response = http.request request case response.code.to_i when 200 result = JSON.parse( response.body ) result.each { |b| @bridges << Bridge.new(b) } else raise "Unknown error" end @bridges end |
#register_username ⇒ Object
48 49 50 51 52 53 54 55 56 |
# File 'lib/lights.rb', line 48 def register_username data = { "devicetype"=>"lights", "username"=>@username } response = @http.post "/api", data.to_json result = JSON.parse(response.body).first if result.has_key? "error" process_error result end end |
#request_bulb_info(id) ⇒ Object
70 71 72 73 |
# File 'lib/lights.rb', line 70 def request_bulb_info( id ) response = get "lights/#{id}" Bulb.new(id,response) end |
#request_bulb_list ⇒ Object
66 67 68 |
# File 'lib/lights.rb', line 66 def request_bulb_list get "lights" end |
#request_config ⇒ Object
58 59 60 |
# File 'lib/lights.rb', line 58 def request_config get "config" end |
#request_group_info(id) ⇒ Object
75 76 77 78 |
# File 'lib/lights.rb', line 75 def request_group_info( id ) response = get "groups/#{id}" Group.new(id,response) end |
#request_group_list ⇒ Object
89 90 91 |
# File 'lib/lights.rb', line 89 def request_group_list get "groups" end |
#request_schedule_list ⇒ Object
93 94 95 |
# File 'lib/lights.rb', line 93 def request_schedule_list get "schedules" end |
#request_sensor_info(id) ⇒ Object
80 81 82 83 |
# File 'lib/lights.rb', line 80 def request_sensor_info( id ) response = get("sensors/#{id}") Sensor.new(id,response) end |
#request_sensor_list ⇒ Object
85 86 87 |
# File 'lib/lights.rb', line 85 def request_sensor_list get "sensors" end |
#set_bulb_state(id, state) ⇒ Object
97 98 99 |
# File 'lib/lights.rb', line 97 def set_bulb_state( id, state ) put "lights/#{id}/state", state end |
#set_group_state(id, state) ⇒ Object
101 102 103 |
# File 'lib/lights.rb', line 101 def set_group_state( id, state ) put "groups/#{id}/action", state end |