maykar / plex_assistant

❱ Plex Assistant is a Home Assistant integration for casting Plex media to Google devices, Sonos devices, and Plex clients with Google Assistant, HA's conversation integration, and more.
MIT License
281 stars 60 forks source link

Fails to load on server restart #138

Closed muddro1 closed 3 years ago

muddro1 commented 3 years ago

Consitently get the following error:

Error setting up entry http://IPADDRESS:32400 for plex_assistant

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 293, in async_setup
    result = await component.async_setup_entry(hass, self)  # type: ignore
  File "/config/custom_components/plex_assistant/__init__.py", line 79, in async_setup_entry
    pa = await hass.async_add_executor_job(pa_executor, server, list(start_script.keys()))
  File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 52, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/plex_assistant/__init__.py", line 75, in pa_executor
    get_devices(hass, _pa)
  File "/config/custom_components/plex_assistant/helpers.py", line 50, in get_devices
    for entity in list(hass.data["media_player"].entities):
KeyError: 'media_player'
github-actions[bot] commented 3 years ago

Important:

Issues that don't provide the information requested in the troubleshooting docs may not get a reply and may be closed until the info is provided. Please, include as much of the requested info as possible so that I can replicate and investigate your issue.

When pasting in your config/code/errors always place 3 backticks ``` above the first line and after the last line. Doing this will format it correctly.

pergolafabio commented 3 years ago

Hi

seeing the same error :

2021-08-26 13:33:29 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry None for plex_assistant
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 293, in async_setup
    result = await component.async_setup_entry(hass, self)  # type: ignore
  File "/config/custom_components/plex_assistant/__init__.py", line 79, in async_setup_entry
    pa = await hass.async_add_executor_job(pa_executor, server, list(start_script.keys()))
  File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 52, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/plex_assistant/__init__.py", line 75, in pa_executor
    get_devices(hass, _pa)
  File "/config/custom_components/plex_assistant/helpers.py", line 50, in get_devices
    for entity in list(hass.data["media_player"].entities):
KeyError: 'media_player'
pergolafabio commented 3 years ago

i may have found the culprit, but no idea to solve it i yesterday installed a new media_player in config, if i comment it out, then plex assistant works if i add the config back, plex assistant throws an error

media_player:
    - platform: linkplay
      host: !secret arylica50
      name: Luidspeker_Buiten
      volume_step: 5
      sources: 
        {} 
pergolafabio commented 3 years ago

hey @muddro1 what other media_players do you have in your config? this plex assistant seems to fail because its in conflict with a media_player

muddro1 commented 3 years ago

Looks like this would be the culprit

media_player:
  - platform: androidtv
    name: Shield TV
    host: 192.168.40.50
pergolafabio commented 3 years ago

yeah, something wrong , not sure what, i fixed it with excluding that media player in the function

in helpers.py

line 49 and forward, added this line : if not entity == media_player.luidspeker_buiten: so i exclude that specific media player from that function

so it looks like :

def get_devices(hass, pa):
    for entity in list(hass.data["media_player"].entities):
        if not entity == media_player.luidspeker_buiten:
            info = str(entity.device_info.get("identifiers", "")) if entity.device_info else ""
            dev_type = [x for x in ["cast", "sonos", "plex", ""] if x in info][0]
            if not dev_type:
                continue
            try:
                name = hass.states.get(entity.entity_id).attributes.get("friendly_name")
            except AttributeError:
                continue
            pa.devices[name] = {"entity_id": entity.entity_id, "device_type": dev_type}
muddro1 commented 3 years ago

Probelm is thats the mediaplayer I would use plex assistant with.

pergolafabio commented 3 years ago

ah ok :-)

pergolafabio commented 3 years ago

i have no idea why its failing :-( we need some assiance from @maykar

yeahme49 commented 3 years ago

I just submitted a PR (https://github.com/maykar/plex_assistant/pull/143) that I think fixes the issue (it fixed it for me). I think the problem is sometimes plex_assistant starts before the media_player component. The PR makes it wait for media_player to start. You can try editing your manifest.json file and restart HA and see if it works for you.

pergolafabio commented 3 years ago

That could be it indeed, thnx

muddro1 commented 3 years ago

I just submitted a PR (#143) that I think fixes the issue (it fixed it for me). I think the problem is sometimes plex_assistant starts before the media_player component. The PR makes it wait for media_player to start. You can try editing your manifest.json file and restart HA and see if it works for you.

Seems to have fixed it for me and solution makes sense. Thanks!

pergolafabio commented 3 years ago

Can be closed now :-)