KoljaWindeler / ytube_music_player

YouTube music player for homeassistant
325 stars 51 forks source link

Error executing script. Unexpected error for call_service at pos 2: can only concatenate str (not "NoneType") to str #351

Open teo-luc opened 4 days ago

teo-luc commented 4 days ago

I got an exception here after upgrading the HA. Please help me to verify this exception. Thanks a lot

HA Info:

Core 2024.7.0
Supervisor 2024.06.2
Operating System 12.4
Frontend 20240703.0

Here is the log:

Logger: homeassistant.components.script.kitplaybolero
Source: helpers/script.py:527
integration: Script ([documentation](https://www.home-assistant.io/integrations/script), [issues](https://github.com/home-assistant/core/issues?q=is%3Aissue+is%3Aopen+label%3A%22integration%3A+script%22))
First occurred: 7:22:25 PM (1 occurrences)
Last logged: 7:22:25 PM
kit.play.bolero: Error executing script. Unexpected error for call_service at pos 2: can only concatenate str (not "NoneType") to str

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 527, in _async_step
    await getattr(self, handler)()
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 764, in _async_call_service_step
    response_data = await self._async_run_long_action(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 727, in _async_run_long_action
    return await long_task
           ^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2731, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2774, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/script/__init__.py", line 663, in _service_handler
    response = await self._async_start_run(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/script/__init__.py", line 621, in _async_start_run
    script_result = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/script/__init__.py", line 652, in _async_run
    return await self.script.async_run(script_vars, context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1770, in async_run
    return await asyncio.shield(create_eager_task(run.async_run()))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 465, in async_run
    await self._async_step(log_exceptions=False)
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 529, in _async_step
    self._handle_exception(
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 559, in _handle_exception
    raise exception
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 527, in _async_step
    await getattr(self, handler)()
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 764, in _async_call_service_step
    response_data = await self._async_run_long_action(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 727, in _async_run_long_action
    return await long_task
           ^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2731, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2774, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 999, in entity_service_call
    single_response = await _handle_entity_call(
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 1071, in _handle_entity_call
    result = await task
             ^^^^^^^^^^
  File "/config/custom_components/ytube_music_player/media_player.py", line 1747, in async_play_media
    await self._tracks_to_attribute()
  File "/config/custom_components/ytube_music_player/media_player.py", line 1211, in _tracks_to_attribute
    track_attributes.append(info['track_artist'] + " - " + info['track_name'])
                            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
TypeError: can only concatenate str (not "NoneType") to str
teo-luc commented 4 days ago

I just fixed it by myself by safely accessing the HashMap Please help me update your code if it's needed. Thanks

    async def _tracks_to_attribute(self):
        self.log_debug_later("[S] _tracks_to_attribute")
        await self.async_update_extra_sensor('total_tracks', len(self._tracks))
        track_attributes = []
        for track in self._tracks:
            info = self.extract_info(track)
            artistInfo = info['track_artist']
            # safely checking the artistInfo
            if artistInfo is None:
                artistInfo = ""
            # safely checking the trackNameInfo
            trackNameInfo = info['track_name']
            if trackNameInfo is None:
                trackNameInfo = ""
            track_attributes.append(artistInfo + " - " + artistInfo)
        await self.async_update_extra_sensor('tracks', track_attributes)  # update extra sensor

        # fire event to let media card know to update
        event_data = {
            "device_id": self._attr_unique_id,
            "entity_id": self.entity_id,
            "type": "reload_playlist",
        }
        self.hass.bus.async_fire(DOMAIN+"_event", event_data)
        self.log_me('debug', "[E] _tracks_to_attribute")
XalaTheShepard commented 3 days ago

I was about to report the same issue. Will it be solved with an update or do we manually repair it?

KoljaWindeler commented 3 days ago

@teo-luc you are most welcome to submit a pull request. But I can copy you fix as well .. let me know

teo-luc commented 3 days ago

Hi @KoljaWindeler I get an issue while pushing the change.

Pushing to github.com:KoljaWindeler/ytube_music_player.git
ERROR: Permission to KoljaWindeler/ytube_music_player.git denied to teo-luc.

so please help me to update the change by following my fix here.

Thanks a lot 🙌

XalaTheShepard commented 2 days ago

Dear KoljaWindeler,

Could you please push this solved issue as a new update to the custom component? This would prevent the users from downgrading to the May update again.

Many thanks in advance.

Kind regards,

Robin

KoljaWindeler commented 8 hours ago

hey guys, can you help me to reproduce this bug? what have you done to trigger it?

Your fix might solve it, but it is strange that it is needed in the first place. We're running extract_info to get the data here https://github.com/KoljaWindeler/ytube_music_player/blob/07268c46db24156257c47cb007a5c80bf9c32b35/custom_components/ytube_music_player/media_player.py#L1210 which is setting all the attributes in the first lines https://github.com/KoljaWindeler/ytube_music_player/blob/07268c46db24156257c47cb007a5c80bf9c32b35/custom_components/ytube_music_player/media_player.py#L919

so why is this happening?