Hell broke loose upon upgrading

Just ran an upgrade process for appdaemon (not sure which version i was running before) and everything broke down. First an error about a missing apps.yaml. Figured out i had to move all my apps to it? So it looks like this

kodi select:
  module: kodi
  class: DynamicKodiInputSelect

KodiYoutube: 
  module: youtube_search
  class: YoutubeSearch
  input_select: input_select.kitchen_youtube_videos
  input_text: input_text.kitchen_youtube
  media_player: media_player.kodi_kitchen
  youtube_key: HereWasTheKey

And nothing works. Was trying the KodiYoutube (code from here Rule for searching youtube (KODI)) When i try the youtube search i get the following error now

2018-01-27 17:48:22.563512 WARNING ------------------------------------------------------------
2018-01-27 17:48:22.564532 WARNING Unexpected error in worker for App KodiYoutube:
2018-01-27 17:48:22.565335 WARNING Worker Ags: {'entity': 'input_text.kitchen_youtube', 'id': UUID('HEREWASKEY'), 'function': <bound method YoutubeSearch.new_youtube_query of <youtube_search.YoutubeSearch object at 0x75a4eeb0>>, 'attribute': 'state', 'kwargs': {}, 'type': 'attr', 'name': 'KodiYoutube', 'old_state': '', 'new_state': 'АН-24'}
2018-01-27 17:48:22.565987 WARNING ------------------------------------------------------------
2018-01-27 17:48:22.569731 WARNING Traceback (most recent call last):
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/appdaemon/appdaemon.py", line 512, in worker
    utils.sanitize_state_kwargs(args["kwargs"]))
  File "/home/homeassistant/.homeassistant/appdaemon/apps/youtube_search.py", line 83, in new_youtube_query
    options=[DEFAULT_ACTION] + labels)
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/appdaemon/appapi.py", line 20, in func_wrapper
    return(func(*args, **kwargs))
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/appdaemon/appapi.py", line 513, in call_service
    return utils.call_service(service, **kwargs)
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/appdaemon/utils.py", line 425, in call_service
    r.raise_for_status()
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/requests/models.py", line 935, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 500 Server Error: Internal Server Error for url: https://www.MYURL:8123/api/services/input_select/set_options
2018-01-27 17:48:22.570597 WARNING ------------------------------------------------------------

Although in the appdaemon.log i can clearly see the youtube was queried and results returned

2018-01-27 18:53:26.986162 INFO youtube_search: New youtube query with “test”
2018-01-27 18:53:27.399491 INFO youtube_search: YOUTUBE QUERY FOUND:
[(‘tpLLst4-3fw’, ‘7 Riddles That Will Test Your Brain Power’)
and many lines more’]
2018-01-27 18:53:27.641943 WARNING Logged an error to /var/log/appdaemon_error.log

Hope here it’s a typo http://appdaemon.readthedocs.io/en/latest/HISTORY.html
For version 2.1.10

The input_select widget has been renamed to input_number to support the change in HASS

All i could find is since 2.1

If you are using the new API intriduced in 2.1.0, you need to make a change to your code. In this release for addiitonal flexibility, rather than giving avery App a default endpoint, Apps must now register their endpoints with the register_endpoint() call. This adds flexibility - Apps can decide on the name of the callback rather than being forced to use the default, also, Apps can now register multiple endpoints.

To retain the old behavior, you will need to add a line in your initialize() function to register the default endpoint explicity:

def initialize(():
self.register_endpoint(self.api_call)

So i’m not sure if this code needs to be corrected. Checking the examples under conf dir there are non register_endpoint calls Any ideas?

import appdaemon.appapi as appapi
import requests


URL_BASE = 'https://www.googleapis.com/youtube/v3/search'
KODI_YOUTUBE_PLUGIN_MASK = "plugin://plugin.video.youtube/play/?video_id={}"
DEFAULT_ACTION = 'No video'

def initialize(():
    self.register_endpoint(self.api_call)

def query_youtube_videos(str_query, max_results=20, is_normal_query=True,
                         order_by_date=False, youtube_key=None):
    params = dict(order='date' if order_by_date else 'relevance',
                  part='snippet', key=youtube_key, maxResults=max_results)
    if is_normal_query:
        params.update({'q': str_query})
    else:
        params.update({str_query.split('=')[0].strip():
                       str_query.split('=')[1].strip()})

    data = requests.get(URL_BASE, params=params).json()
    found = []
    for item in data['items']:
        if item['id']['kind'] == 'youtube#video':
            found.append((item['id']['videoId'], item['snippet']['title']))
    return found


# noinspection PyClassHasNoInit
class YoutubeSearch(appapi.AppDaemon):
    """App that listens to the input text and select."""

    _ids_options = None
    _youtube_key = None

    _input_select = None
    _input_text = None
    _media_player = None

    def initialize(self):
        """Set up App."""
        self._input_select = self.args.get('input_select')
        self._input_text = self.args.get('input_text')
        self._media_player = self.args.get('media_player', 'media_player.kodi')
        self._youtube_key = self.args.get('youtube_key')
        self.listen_state(self.new_youtube_query, self._input_text)
        self.listen_state(self.video_selection, self._input_select)
        self._ids_options = {DEFAULT_ACTION: None}

    # noinspection PyUnusedLocal
    def new_youtube_query(self, entity, attribute, old, new, kwargs):
        """Query videos with input_text."""
        self.log('New youtube query with "{}"'.format(new))
        found = query_youtube_videos(new,
                                     max_results=20,
                                     is_normal_query=True,
                                     order_by_date=False,
                                     youtube_key=self._youtube_key)
        self.log('YOUTUBE QUERY FOUND:\n{}'.format(found))

        # Update input_select values:
        self._ids_options.update({name: v_id for v_id, name in found})
        labels = [f[1] for f in found]
        self.log('NEW OPTIONS:\n{}'.format(labels))
        self.call_service('input_select/set_options',
                          entity_id=self._input_select,
                          options=[DEFAULT_ACTION] + labels)

    # noinspection PyUnusedLocal
    def video_selection(self, entity, attribute, old, new, kwargs):
        """Play the selected video from a previous query."""
        self.log('SELECTED OPTION: {} (from {})'.format(new, old))
        try:
            selected = self._ids_options[new]
        except KeyError:
            self.error('Selection "{}" not in memory (doing nothing)'
                       .format(new), 'WARNING')
            return

        if selected:
            self.log('PLAY MEDIA: {} [id={}]'.format(new, selected))
            self.call_service(
                'media_player/play_media', entity_id=self._media_player,
                media_content_type="video",
                media_content_id=KODI_YOUTUBE_PLUGIN_MASK.format(selected))

The error you posted look like just something with the options you were passing to it

I’m not sure i installed appdaemon correctly in the first place as i’ve put it into VE of hass.
So when I’ve upgraded appdaemon it also upgraded the libs.
After half an hour struggle with above errors - i went ahead and semi reinstalled hass running pip3 upgrade install homeassistant.
That downgraded only the aiohttp library - but now the errors are gone and everything works again. And hadashboard also started fine (before was throwing an internal server 500 error)

Ah, yeah there were some big changes in aiohttp I have seen as well. Glad you figured it out

that already got mentioned in the appdaemon 3.0 topic.
HA breaks on higher versions from aiohttp.

In my case it was 2.1 appdaemon install via pip3

the problem is the same :wink:
HA cant handle a higher version from aiohttp for some reason.