seydx / homebridge-bravia-tvos

Homebridge plugin for Sony Bravia Android TVs
MIT License
345 stars 32 forks source link

[ENHANCEMENT] Map HDMI to corresponding CEC input. #116

Closed lukasmalkmus closed 3 years ago

lukasmalkmus commented 3 years ago

I have an Apple TV and a Playstation 4 attached to my Sony TV via HDMI. By utilizing CEC, the TV can control those devices. In the plugin config UI, there are two separate inputs listed: HDMI and CEC inputs separately. However, "under the hood", they are the same physical device. There is a major difference when configuring them for use in HomeKit: If I configure HDMI inputs, the TV will switch to them, but not start the attached devices. If I configure CEC inputs, this will actually work, which is kind of a nice feature IMHO. But there is one catch:

[12/5/2020, 10:31:20 PM] [BraviaTVOS] TV: Changing input source to Player 1 (extInput:cec?type=player&port=1)
[12/5/2020, 10:31:29 PM] [BraviaTVOS] TV: Polling tv state
[12/5/2020, 10:31:30 PM] [BraviaTVOS] TV: {"source":"extInput:hdmi","title":"HDMI 3","uri":"extInput:hdmi?port=3"}
[12/5/2020, 10:31:32 PM] [BraviaTVOS] TV: Changing input source to Player 2 (extInput:cec?type=player&port=2)
[12/5/2020, 10:31:40 PM] [BraviaTVOS] TV: Polling tv state
[12/5/2020, 10:31:40 PM] [BraviaTVOS] TV: {"source":"extInput:hdmi","title":"HDMI 4","uri":"extInput:hdmi?port=4"}

While the correct input is set, the polling reports the "wrong" one. While this could in theory be a bug, I don't think it is: The actual input returned is correct. But since HomeKit just knows about the configured CEC inputs, it doesn't know what to do with the response and doesn't show the selected input source.

seydx commented 3 years ago

@lukasmalkmus

The polling only shows what the TV thinks it is displaying. The problem with CEC is that the TV only displays it correctly when the connection is established. Otherwise it is only e.g. HDMI 3.

Also during the installation the TV is switched on when configuring or reading the inputs because the CEC devices are not readable when switched off.

The plugin does NOT manipulate the output of the TV, but queries the endpoint getPlayingContent and the TV responds. For example, if you have Apple TV turned on but the TV says HDMI 3, this is because the underlying API has not yet updated the state because CEC devices needs some time.