karlentwistle / ruby_home

Ruby HAP Server - HomeKit support for the Rubyist

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TV device

FWMatt opened this issue · comments

Hi,

I've noticed that HomeBridge has a "TV" device defined (via a plugin). Any plans to do that for RubyHome? Can I help to add it if not?

Thank you!
Matt

I'm not a maintainer here, but from what I can tell from the HomeKit docs, there aren't any services types or characteristics in the HomeKit platform that would explicitly support a TV device, so the best you could do would be to use a switch type (or similar) to control the basic on/off features, and maybe try to fake a channel selection with a thermostat or something like that.

Do you know how the TV device from HomeBridge appears in the Home app? How does it present itself?

I’ve also been doing some research - I’m not sure this device type is released yet. When it is you should be able to switch on / off as you say, but also control volume, inputs and channel.

https://www.imore.com/airplay-homekit-smart-tv
(No technical info here I’m afraid)

Hey @FWMatt

Firstly sorry for the belated response. I meant to respond to you sooner. Since I wrote this library, my daughter was born, so I've had slightly less free time outside of work for coding and open source. 😄

I had a look into this today. Unfortunately, Apple hasn't updated the Homekit Specification to document exactly how a TV service is supposed to work. As you say this is already a feature in HomeBridge and it seems like the TV accessory is defined within https://github.com/homebridge/HAP-NodeJS/blob/master/src/accessories/TV_accessory.ts

Having a quick look through their code, it seems that we'd need a few new services.yml and characteristics.yml to support television.

Firstly we'd need a new service defined in the services.yml file for the "television" itself. For example:

# lib/ruby_home/config/services.yml
- :name: :television
  :description: Television
  :uuid: '000000D8-0000-1000-8000-0026BB765291'
  :optional_characteristics_uuids:
  - 00000008-0000-1000-8000-0026BB765291
  - # etc
  :required_characteristics_uuids:
  - 000000B0-0000-1000-8000-0026BB765291
  - 000000E7-0000-1000-8000-0026BB765291
  - 000000E3-0000-1000-8000-0026BB765291
  - 000000E1-0000-1000-8000-0026BB765291
  - 000000E8-0000-1000-8000-0026BB765291

Now if we take one of these characteristic UUIDs as an example. 000000B0-0000-1000-8000-0026BB765291 this one refers to the "active" characteristic. This one already happens to be defined so should "just work".

Sadly not all the characteristics are ones that are imported with my automated script. So we'd need to define the missing ones manually. 😱 This would be a case of cross-referencing them against HAP-NodeJS.

The characteristics.yml would then end up having a bunch of these appended:

# lib/ruby_home/config/characteristics.yml
- :name: :active_Identifier
  :description: Active Identifier
  :uuid: 000000E7-0000-1000-8000-0026BB765291
  :format: uint32
  :unit: nil
  :permissions:
  - securedRead
  :properties:
  - read
  - write
  - cnotify
  :constraints:
- :name: :configured_name
  :description: Configured Name
  :uuid: 000000E3-0000-1000-8000-0026BB765291
  :format: string
  :unit: nil
  :permissions:
  - securedRead
  :properties:
  - read
  - write
  - cnotify
  :constraints:
# etc

After the service and characteristics are input into the YAML files, we'd be able to use them like this:

television = RubyHome::ServiceFactory.create(:television,
  active: 0, # required
  configured_name: "Living Room TV" #required
  # etc
)

Looking through https://github.com/homebridge/HAP-NodeJS/blob/master/src/accessories/TV_accessory.ts it seems like "television" isn't the only new service we'd require. I think we'd also need:

Those two services would also need to be added to the lib/ruby_home/config/services.yml file and then each of their characteristics would need to be added into lib/ruby_home/config/characteristics.yml.

Then to compose the entire accessory, I think it would end up looking something like this:

television = RubyHome::ServiceFactory.create(:television,
  active: 0, # required
  configured_name: "Living Room TV" #required
  # etc
)

hdmi1 = RubyHome::ServiceFactory.create(:input_source,
  configured_name: "HDMI 1", # required
  # etc
)

Can I help to add it if not?

If you're interested in making these changes within RubyHome I'd gladly set aside some time to answer questions/review/test and merge a PR.

If you have any more questions I will try and respond more quickly than 27 days 😅