PlexDevices - Custom Media Player Component

States and controls are 2 different things. Can you go to the HA states view, find your client, and see what state is listed when playing? I bet it says playing. If so and the control button looks like a stop button, I think that’s an HA thing (and its the behavior I expected).

1 Like

Will check now. Thanks for taking the time to explain this for me.

Update: OK, confirmed that the states are reading properly. Weird thing is when I first started playing, nothing at all showed up. Anywhere. Waited for a while but no update in media player OR states/dev.

Stopped. Went back and played the same video. Still nothing. Checked to see what server I was connected to and started playing again. Went back to check HA and it showed up. Stopped and played another video, everything updated and showed the new thumbnail. Not sure why the first two times nothing was showing up but thought I’d mention it.

Later on, I will disable plexdevices and go back to original plex client and see what the differences are and report back. I appreciate your patience and hope my input has been of some help and not just an annoyance as I don’t see anyone else really using the Shield here. :flushed:

1 Like

Will try it out!

Thanks!

And I think it can’t be said enough about the great work you’re doing! Thanks for that!

1 Like

Seems to work as expected! Will keep an eye on it a bit more.

1 Like

Good news - I’ve been doing some more research into the client/server playback controls issue and maybe, maybe I have a hack. It looks like the local plex server assigns the local client an ip address in the attribute “baseurl”. That IP is non-routable similar to the player IP (127.0.0.1). However, if I force the baseurl to be the same as the server url, it appears to control the client. I need to do more testing but it appears to be working.

1 Like

FIX POSTED - controls now work as expected on 1) casted sessions and 2) client sessions when client and PMS reside on the same sever

1 Like

Awesome!!! Got home late so I’ll have to try this tomorrow and report back. Thanks for all your hard work on this issue.

The state of play/pause control does not change when I tap in pause to pause the movie, wait a few seconds for “pause” to change to “play,” and then tap in “play” to play the video, which then will take about a couple of seconds for the control to change back to “pause” from “play.”

Looks “normal” to me - there will always be a delay between pressing a button, having that do something, and then having HA update the control. Right now that can take up to 10 seconds depending on when you pressed. Anything longer than that is not normal.

The Kodi component does not wait for the state to be changed to “paused” as the component should know that it originated from a user. When I press pause in Kodi card, the media player component changes from “pause” to “play” immediately. I do not know if there are other media player components that have the same behavior as the PlexDevices component.

Yeah, they are using listeners and not polling. I don’t know if theres something better than can be done here.

Since it is polling and I like a fast reaction on state changes I have changed the polling interval for flex. If web hooks would be implemented this would not be necessary.

media_player plex:
platform: plex
scan_interval: 1

Was thinking about adding the scan interval as an option - I’ll do that today

Is anyone working on replacing the original Plex component with this one (which looks much better!)

@JesseWebDotCom do you mind updating the first post with installation instructions?

I have this component in code review now as the replacement, so yes.

Scroll up to the first post for links to the latest Code and Documentation

1 Like

@JesseWebDotCom - You, sir, are a steely-eyed missile man!

Controls now not only show up, they actually work and reflect proper states!!! You totally nailed it with your hack; awesome work, brother. I kinda feel like I was the only one with this issue, so I feel even more gratitude that you went the extra mile to get this worked out. Congrats man - you solved it.

1 Like

Just for the record, I am still getting errors in the logs despite this actually working perfectly well. I was able to pause, play and turn off the video from HA and in each case the action worked and the state changed in a perfectly appropriate amount of time. But I’m going to post the errors so you know what’s going on.

Traceback (most recent call last):
  File "/usr/lib/python3.4/asyncio/tasks.py", line 233, in _step
    result = coro.throw(exc)
  File "/srv/hass/hass_venv/lib/python3.4/site-packages/homeassistant/core.py", line 1018, in _event_to_service_call
    yield from service_handler.func(service_call)
  File "/srv/hass/hass_venv/lib/python3.4/site-packages/homeassistant/components/media_player/__init__.py", line 364, in async_service_handler
    yield from getattr(player, method['method'])(**params)
  File "/usr/lib/python3.4/asyncio/futures.py", line 388, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/usr/lib/python3.4/asyncio/tasks.py", line 286, in _wakeup
    value = future.result()
  File "/usr/lib/python3.4/asyncio/futures.py", line 277, in result
    raise self._exception
  File "/usr/lib/python3.4/concurrent/futures/thread.py", line 54, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/home/hass/custom_components/media_player/plexdevices.py", line 657, in media_pause
    self.device.pause(self._active_media_plexapi_type)
  File "/home/hass/deps/plexapi/client.py", line 126, in pause
    def pause(self, mtype): self.sendCommand('playback/pause', type=mtype)
  File "/home/hass/deps/plexapi/client.py", line 85, in sendCommand
    return self.query(path, headers=headers)
  File "/home/hass/deps/plexapi/client.py", line 71, in query
    return ElementTree.fromstring(data) if data else None
  File "/usr/lib/python3.4/xml/etree/ElementTree.py", line 1325, in XML
    parser.feed(text)
  File "<string>", line None
xml.etree.ElementTree.ParseError: syntax error: line 1, column 0
17-02-19 11:56:44 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/lib/python3.4/asyncio/tasks.py", line 233, in _step
    result = coro.throw(exc)
  File "/srv/hass/hass_venv/lib/python3.4/site-packages/homeassistant/core.py", line 1018, in _event_to_service_call
    yield from service_handler.func(service_call)
  File "/srv/hass/hass_venv/lib/python3.4/site-packages/homeassistant/components/media_player/__init__.py", line 364, in async_service_handler
    yield from getattr(player, method['method'])(**params)
  File "/usr/lib/python3.4/asyncio/futures.py", line 388, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/usr/lib/python3.4/asyncio/tasks.py", line 286, in _wakeup
    value = future.result()
  File "/usr/lib/python3.4/asyncio/futures.py", line 277, in result
    raise self._exception
  File "/usr/lib/python3.4/concurrent/futures/thread.py", line 54, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/home/hass/custom_components/media_player/plexdevices.py", line 657, in media_pause
    self.device.pause(self._active_media_plexapi_type)
  File "/home/hass/deps/plexapi/client.py", line 126, in pause
    def pause(self, mtype): self.sendCommand('playback/pause', type=mtype)
  File "/home/hass/deps/plexapi/client.py", line 85, in sendCommand
    return self.query(path, headers=headers)
  File "/home/hass/deps/plexapi/client.py", line 71, in query
    return ElementTree.fromstring(data) if data else None
  File "/usr/lib/python3.4/xml/etree/ElementTree.py", line 1325, in XML
    parser.feed(text)
  File "<string>", line None
xml.etree.ElementTree.ParseError: syntax error: line 1, column 0
17-02-19 11:57:02 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/lib/python3.4/asyncio/tasks.py", line 233, in _step
    result = coro.throw(exc)
  File "/srv/hass/hass_venv/lib/python3.4/site-packages/homeassistant/core.py", line 1018, in _event_to_service_call
    yield from service_handler.func(service_call)
  File "/srv/hass/hass_venv/lib/python3.4/site-packages/homeassistant/components/media_player/__init__.py", line 364, in async_service_handler
    yield from getattr(player, method['method'])(**params)
  File "/usr/lib/python3.4/asyncio/futures.py", line 388, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/usr/lib/python3.4/asyncio/tasks.py", line 286, in _wakeup
    value = future.result()
  File "/usr/lib/python3.4/asyncio/futures.py", line 277, in result
    raise self._exception
  File "/usr/lib/python3.4/concurrent/futures/thread.py", line 54, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/home/hass/custom_components/media_player/plexdevices.py", line 651, in media_play
    self.device.play(self._active_media_plexapi_type)
  File "/home/hass/deps/plexapi/client.py", line 127, in play
    def play(self, mtype): self.sendCommand('playback/play', type=mtype)
  File "/home/hass/deps/plexapi/client.py", line 85, in sendCommand
    return self.query(path, headers=headers)
  File "/home/hass/deps/plexapi/client.py", line 71, in query
    return ElementTree.fromstring(data) if data else None
  File "/usr/lib/python3.4/xml/etree/ElementTree.py", line 1325, in XML
    parser.feed(text)
  File "<string>", line None
xml.etree.ElementTree.ParseError: syntax error: line 1, column 0
17-02-19 11:57:16 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/lib/python3.4/asyncio/tasks.py", line 233, in _step
    result = coro.throw(exc)
  File "/srv/hass/hass_venv/lib/python3.4/site-packages/homeassistant/core.py", line 1018, in _event_to_service_call
    yield from service_handler.func(service_call)
  File "/srv/hass/hass_venv/lib/python3.4/site-packages/homeassistant/components/media_player/__init__.py", line 364, in async_service_handler
    yield from getattr(player, method['method'])(**params)
  File "/usr/lib/python3.4/asyncio/futures.py", line 388, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/usr/lib/python3.4/asyncio/tasks.py", line 286, in _wakeup
    value = future.result()
  File "/usr/lib/python3.4/asyncio/futures.py", line 277, in result
    raise self._exception
  File "/usr/lib/python3.4/concurrent/futures/thread.py", line 54, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/home/hass/custom_components/media_player/plexdevices.py", line 668, in turn_off
    self.media_stop()
  File "/home/hass/custom_components/media_player/plexdevices.py", line 663, in media_stop
    self.device.stop(self._active_media_plexapi_type)
  File "/home/hass/deps/plexapi/client.py", line 135, in stop
    def stop(self, mtype): self.sendCommand('playback/stop', type=mtype)
  File "/home/hass/deps/plexapi/client.py", line 85, in sendCommand
    return self.query(path, headers=headers)
  File "/home/hass/deps/plexapi/client.py", line 71, in query
    return ElementTree.fromstring(data) if data else None
  File "/usr/lib/python3.4/xml/etree/ElementTree.py", line 1325, in XML
    parser.feed(text)
  File "<string>", line None
xml.etree.ElementTree.ParseError: syntax error: line 1, column 0

Like I said, despite the error log, everything worked so not sure what the issue is. Let me know how I can help.

I saw that too. Likely a hack side-effect and nothing I can do.

Can you share how you did that? No matter what I do it still seems to take 10 seconds, even after setting this: MIN_TIME_BETWEEN_SCANS = timedelta(seconds=1)

Eh, I’ll filter it out when it’s deployed. In the meantime I want to leave the logger alone until we’re all done testing.

I’ll continue to play with it during the day to see if anything shakes out. Let me know if there is anything specific you need me to check, OK.

And thanks again!