YAML problem with example from "cookbook"

i’m trying to implement this kodi app on my system, the appdaemon script gives me a YAML syntax error ((mapping values are not allowed), even when i test that with yamlint

can anyone explain whats the problem? https://home-assistant.io/cookbook/automation_kodi_dynamic_input_select/

import appdaemon.appapi as appapi
from homeassistant.components.media_player.kodi import (
    EVENT_KODI_CALL_METHOD_RESULT)

ENTITY = 'input_select.kodi_results'
MEDIA_PLAYER = 'media_player.kodi'
DEFAULT_ACTION = "Nothing to do"
MAX_RESULTS = 20

class DynamicKodiInputSelect(appapi.AppDaemon):
    """AppDaemon app to dynamically populate an `input_select`."""
    _ids_options = None

    def initialize(self):
        """Set up appdaemon app."""
        self.listen_event(self._receive_kodi_result,
                          EVENT_KODI_CALL_METHOD_RESULT)
        self.listen_state(self._change_selected_option, ENTITY)
        # Input select:
        self._ids_options = {DEFAULT_ACTION: None}

    def _receive_kodi_result(self, event_id, payload_event, *args):
        result = payload_event['result']
        method = payload_event['input']['method']

        assert event_id == EVENT_KODI_CALL_METHOD_RESULT
        if method == 'VideoLibrary.GetRecentlyAddedMovies':
            values = result['movies'][:MAX_RESULTS]
            data = [('{} ({})'.format(r['label'], r['year']),
                     ('MOVIE', r['file'])) for r in values]
            self._ids_options.update(dict(zip(*zip(*data))))
            labels = list(list(zip(*data))[0])
            self.call_service('input_select/set_options',
                              entity_id=ENTITY,
                              options=[DEFAULT_ACTION] + labels)
            self.set_state(ENTITY,
                           attributes={"friendly_name": 'Recent Movies',
                                       "icon": 'mdi:movie'})
        elif method == 'VideoLibrary.GetRecentlyAddedEpisodes':
            values = list(filter(lambda r: not r['lastplayed'],
                                 result['episodes']))[:MAX_RESULTS]
            data = [('{} - {}'.format(r['showtitle'], r['label']),
                     ('TVSHOW', r['file'])) for r in values]
            self._ids_options.update(dict(zip(*zip(*data))))
            labels = list(list(zip(*data))[0])
            self.call_service('input_select/set_options',
                              entity_id=ENTITY,
                              options=[DEFAULT_ACTION] + labels)
            self.set_state(ENTITY,
                           attributes={"friendly_name": 'Recent TvShows',
                                       "icon": 'mdi:play-circle'})
        elif method == 'PVR.GetChannels':
            values = result['channels']
            data = [(r['label'], ('CHANNEL', r['channelid']))
                    for r in values]
            self._ids_options.update(dict(zip(*zip(*data))))
            labels = list(list(zip(*data))[0])
            self.call_service('input_select/set_options',
                              entity_id=ENTITY,
                              options=[DEFAULT_ACTION] + labels)
            self.set_state(ENTITY,
                           attributes={"friendly_name": 'TV channels',
                                       "icon": 'mdi:play-box-outline'})

    def _change_selected_option(self, entity, attribute, old, new, kwargs):
        selected = self._ids_options[new]
        if selected:
            mediatype, file = selected
            self.call_service('media_player/play_media',
                              entity_id=MEDIA_PLAYER,
                              media_content_type=mediatype,
                              media_content_id=file)

Where are you entering this code?

If you are entreeing it into a config file it will error out. That is python code, not meant to be entered in to a config file.

im entering it to apps.yaml under appdaemon

that needs to be a separate file.

apps.yaml should only contain your yaml for your apps. Your app itself will be in a separate py file, in which this code will be pasted.

thanks, didnt know that…
now…

1.i paste the code into kodi_input_select.py under apps directory (which i point to in appdaemon.yaml).
2. in the apps.yaml i entered :

kodi_input_select:
  module: homeassistant
  class: DynamicKodiInputSelect 

im not really sure what the module should be…im getting :

> line 2, in <module>
>     from homeassistant.components.media_player.kodi import (EVENT_KODI_CALL_METHOD_RESULT)
> ImportError: No module named 'homeassistant'

what did i do wrong now?

Is this in the correct directory for appdaemon? homeassistant is the module that all of home assistant works from. If that’s not importing correctly, then something isn’t correct.

I also suggest you brush up on python. Using this will be near impossible if you do not know python syntax or errors.

i add this to be sure where the app dir is : app_dir: /home/hasamba/.homeassistant/conf/apps

im not a coder, thats why i tried using already maid examples from the “cookbook”.

never mind, thanks anyway

That’s the thing, the item you are trying to implement isn’t ‘already made’. Its an example to use to build your own. A few changes are needed to make that work for your setup.

ok, thanks anyway

line 2, in
from homeassistant.components.media_player.kodi import (EVENT_KODI_CALL_METHOD_RESULT)
ImportError: No module named ‘homeassistant’

Whats the problem?

I’m not sure what his problem was. The guy didn’t know python and was using other people as a debugger instead of learning the language.