karlentwistle / ruby_home

Ruby HAP Server - HomeKit support for the Rubyist

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Example for color temperature

flolau2k opened this issue · comments

Hi there!
I am trying to read color temperature from a light bulb in Ruby Home. I tried doing it the same way as accessing hue and brightness in the example - am I doing something wrong?

accessory_information = RubyHome::ServiceFactory.create(:accessory_information)
lightbulb = RubyHome::ServiceFactory.create(:lightbulb,
  on: true,
  name: "lightbulb",
  brightness: 100,
  color_temperature: 100,
)

lightbulb.color_temperature.after_update do |c|
  puts "lightbulb color temp is at #{c}"
end

RubyHome.run

But lightbulb.color_temperature does not exist (undefined method). Any ideas? Or does this only support reading it as color (hue, saturation and brightness)?

Thanks so much!

Thanks for reporting this as an issue @flolaud.

I have fixed this problem in #80 and released a new version of the gem 0.2.2 which contains the fix.

The snippet you provided:

accessory_information = RubyHome::ServiceFactory.create(:accessory_information)
lightbulb = RubyHome::ServiceFactory.create(:lightbulb,
  on: true,
  name: "lightbulb",
  brightness: 100,
  color_temperature: 100,
)

lightbulb.color_temperature.after_update do |c|
  puts "lightbulb color temp is at #{c}"
end

RubyHome.run

Should now work and I've tested it locally.

I guess you're already aware but I thought I'd mention it anyway. The HAP-Specification-Non-Commercial-Version documentation says:

If this characteristic is included in the Lightbulb (page 217), Hue (page 151) and Saturation (page 159) must not be included as optional characteristics in Lightbulb (page 217). This characteristic must not be used for lamps which support color.

So it won't be possible to include hue or saturation in conjunction with color_temperature.

I hope the new version of the gem works for you. Let me know how you get on.

Thanks very much

Works very nice. Thank you for adding this feature so quickly!