hunterjm / hassio-addons

Control your Xbox One from your Home Assistant device.
MIT License
56 stars 50 forks source link

Homekit improvements #6

Closed unknownskl closed 6 years ago

unknownskl commented 6 years ago

I've made some improvements regarding the xboxone custom component. These modifications will expose the following switches in Homekit:

It also fixed to set the state of the xbox to on instead of unknown

hunterjm commented 6 years ago

The state is set to unknown because the “on” state doesn’t show media controls, and the Xbox doesn’t always report media as playing until you do a hard restart. In that case, HA 0.76 will show a “play/pause” button if the state is unknown.

unknownskl commented 6 years ago

Thanks for the feedback. I will dive deeper into the home assistant component to see if we can fix it on the long term. I will update the PR next weekend.

dshokouhi commented 6 years ago

@hunterjm I think we can make the states better. Right now I think the usage of STATE_UNKNOWN is not helpful to the user. This is what makes sense to me:

Unknown - device available but connection fails so user knows something is not working properly On - if device is connected Idle - when an app is loaded but nothing plays (stopped is a good example) Play/Pause - works as intended except blu-ray menu should really be considered Idle instead of playing but thats ok

These changes will bring things in line with Kodi and Plex media players. Idle is an important status to go off if you ask me because how do you know the media stopped?

So line 454-456 should be STATE_IDLE which indicates a media ready app is loaded but nothing is playing or actively being paused.

Line 464 should be STATE_ON so user knows the xbox is on and connected.

hunterjm commented 6 years ago

I agree that those states make sense. The only problem is with the front-end code here.

If you look at my front-end PR that was released in Home Assistant 0.76 (https://github.com/home-assistant/home-assistant-polymer/pull/1571) you will see that the Xbox does not always communicate media state over the smartglass protocol, and not all apps support the media state APIs, but still support play/pause.

Because of that, I defined the states as follows: Off: No console available Playing: Xbox returns playing in media_status Paused: Xbox returns paused in media_status Unknown: all other states

I then filter the available features based on the type of app that is loaded here.

This allows the UI to still display a Play/Pause button (as of HA 0.76) when an app is loaded and attempt to send the play_pause_toggle command even if the app is not reporting a media status (which sometimes the console won't do until a hard restart).

The only other way to achieve this is to add an additional PR to the frontend to support your suggested states.

@tuxuser - What are your thoughts?

hunterjm commented 6 years ago

We might be able to keep the state "ON" if no Application is loaded (i.e. you are playing a game), but even settings is considered an "Application".

tuxuser commented 6 years ago

Diplomatic answer: I am fine with everything that works good for everybody... Didn't have the time to test different states intensively yet, just took a brief look so far.

dshokouhi commented 6 years ago

I like to look at it this way. The xbox itself is a device. So whether it is on or off it should reflect that status alone, just like a chromecast or kodi that have their own apps. If certain apps do not support the full features then maybe support should be added specifically for them to cater that need. Netflix and the blu-ray player both seem to give the proper media status. If the media status gets out of sync then users need to restart their device and it should be noted as a troubleshooting step, otherwise your automations will not work. The blu-ray player in specific is one app that does not work on other platforms so I think it should get a bit more focus as a result. Netflix, youtube, plex and kodi all have their own platforms and other components that show proper status.

unknownskl commented 6 years ago

I've processed the feedback. For now i tried to find a good solution for the media state. Using STATE_ON when playing a game and STATE_PLAYING when using an app seems to be a reasonable way to do it.

The states will allow the media controls to show up on all apps. Also background can be controlled via that, unsless you use netflix or another video app. When there is a game launched the media player will show only the next en prev media buttons which can be used to control background music.

What do you think?

hunterjm commented 6 years ago

I have been moving to a new house and haven’t had time to review. I’ll try to get to this ASAP.

hunterjm commented 6 years ago

I took a stab at this recently and think I found something that may work as a compromise. It still uses the "Unknown" state for when there is no media state and the Xbox is in an "Application" because that is the true state of the "Media Player"... We don't know if media is playing or not, but the controls still work, so show a Play/Pause button (which only happens with UNKNOWN).

Look at the below example. I was watching Netflix all day, and initially it was reporting the playing status back, but after a couple reboots it suddenly stopped reporting whether or not media was playing (it was).

image

img_2548

So here's what I'm going to go with:

1) Any media status other than Playing/Paused: STATE_IDLE 2) Media status of Playing: STATE_PLAYING 3) Media status of Paused: STATE_PAUSED 4) Console connected & available, but not in an Application: STATE_ON 5) Inside an Application with no media status: STATE_UNKNOWN 6) Console not available or connected: STATE_OFF