Skip to content

Kodi integration broken since 2021.1.3 #45249

Closed

Description

@L-Henke

The problem

Kodi integration stopped working since version 2021.1.3. The state is always shown as "off". At the startup HA hangs a few minutes on setup of Kodi integration. If you remove and try to add the integration via the UI again there will be the message "Unknown error occurred" after about 30 seconds. If I switch the docker container back to 2021.1.2 the integration immediately is working again. The issue persists in 2021.1.4.

Environment

  • Home Assistant Core release with the issue: 2021.1.3
  • Last working Home Assistant Core release (if known): 2021.1.2
  • Operating environment (OS/Container/Supervised/Core): Docker
  • Integration causing this issue: Kodi
  • Link to integration documentation on our website: https://www.home-assistant.io/integrations/kodi/

Problem-relevant configuration.yaml

Integration is set up via UI so no yaml

Traceback/Error logs

WARNING (MainThread) [homeassistant.bootstrap] Waiting on integrations to complete setup: kodi
WARNING (MainThread) [homeassistant.bootstrap] Setup timed out for stage 2 - moving forward

Additional information

I tried reverting the the change to the integration introduced in 2fb3be5 but that didn't fix the issue. So my wild guess would be a relation to the XSS hardenings introduced in 2021.1.3.

Activity

  1. probot-home-assistant commented on Jan 16, 2021

    @probot-home-assistant

    kodi documentation
    kodi source
    (message by IssueLinks)

  2. probot-home-assistant commented on Jan 16, 2021

    @probot-home-assistant

    Hey there @OnFreund, @cgtobi, mind taking a look at this issue as its been labeled with an integration (kodi) you are listed as a codeowner for? Thanks!
    (message by CodeOwnersMention)

  3. OnFreund commented on Jan 18, 2021

    @OnFreund
    Contributor

    Upgraded to 2021.1.3 and all of my Kodi instances are still working. I am getting sporadic timeouts, but I can't really tell if this is related to the new changes in this version or to my environment, or were there before (I was generating way more traffic for this test than I do in my normal day to day).

    Are you communicating with kodi over websocket? Can you share your configuration (redact the username/password, but do note if you're using them)? Can you also increase the log level of the kodi integration to debug and attach the logs?

  4. L-Henke commented on Jan 18, 2021

    @L-Henke
    ContributorAuthor

    The integration is configured via the UI so there is no yaml to present. No username/password is required for the connection to the Kodi instance.

    I added the following logger and restarted HA:

    homeassistant.components.kodi.media_player: debug
    homeassistant.components.media_player: debug
    homeassistant.components.websocket_api.http.connection: debug
    

    The start was delayed by about 5 minutes with this message:

    2021-01-18 07:59:37 WARNING (MainThread) [homeassistant.bootstrap] Waiting on integrations to complete setup: kodi
    2021-01-18 08:00:37 WARNING (MainThread) [homeassistant.bootstrap] Waiting on integrations to complete setup: kodi
    2021-01-18 08:01:37 WARNING (MainThread) [homeassistant.bootstrap] Waiting on integrations to complete setup: kodi
    2021-01-18 08:02:37 WARNING (MainThread) [homeassistant.bootstrap] Waiting on integrations to complete setup: kodi
    2021-01-18 08:03:37 WARNING (MainThread) [homeassistant.bootstrap] Setup timed out for stage 2 - moving forward
    2021-01-18 08:03:37 WARNING (MainThread) [homeassistant.bootstrap] Waiting on integrations to complete setup: kodi
    
    2021-01-18 08:03:38 INFO (MainThread) [homeassistant.components.media_player] Setting up media_player.kodi
    2021-01-18 08:03:38 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection] [140411687749520] Sending {"id": 3, "type": "event", "event": {"event_type": "component_loaded", "data": {"component": "kodi"}, "origin": "LOCAL", "time_fired": "2021-01-18T08:03:38.769917+00:00", "context": {"id": "bde209bd1d64630316749f33cc40cacf", "parent_id": null, "user_id": null}}}
    2021-01-18 08:03:38 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection] [140411687749520] Sending {"id": 9, "type": "event", "event": {"event_type": "component_loaded", "data": {"component": "kodi"}, "origin": "LOCAL", "time_fired": "2021-01-18T08:03:38.769917+00:00", "context": {"id": "bde209bd1d64630316749f33cc40cacf", "parent_id": null, "user_id": null}}}
    2021-01-18 08:03:38 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection] [140411687749520] Sending {"id": 5, "type": "event", "event": {"event_type": "service_registered", "data": {"domain": "kodi", "service": "add_to_playlist"}, "origin": "LOCAL", "time_fired": "2021-01-18T08:03:38.773263+00:00", "context": {"id": "ecd1ff001bc92eba634dde41e2a8d807", "parent_id": null, "user_id": null}}}
    2021-01-18 08:03:38 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection] [140411687749520] Sending {"id": 5, "type": "event", "event": {"event_type": "service_registered", "data": {"domain": "kodi", "service": "call_method"}, "origin": "LOCAL", "time_fired": "2021-01-18T08:03:38.773327+00:00", "context": {"id": "560889b025be9cab8cd34c6df1d6b03c", "parent_id": null, "user_id": null}}}
    2021-01-18 08:03:38 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection] [140411687749520] Sending {"id": 2, "type": "event", "event": {"event_type": "state_changed", "data": {"entity_id": "media_player.kodi_9e31bafe5b963617f35a89dfdf6c136d", "old_state": null, "new_state": {"entity_id": "media_player.kodi_9e31bafe5b963617f35a89dfdf6c136d", "state": "off", "attributes": {"supported_features": 186303}, "last_changed": "2021-01-18T08:03:38.775177+00:00", "last_updated": "2021-01-18T08:03:38.775177+00:00", "context": {"id": "100a660e3f6b3e1cfe25ac0f4bfc9934", "parent_id": null, "user_id": null}}}, "origin": "LOCAL", "time_fired": "2021-01-18T08:03:38.775177+00:00", "context": {"id": "100a660e3f6b3e1cfe25ac0f4bfc9934", "parent_id": null, "user_id": null}}}
    

    If I try to interact with the media player, e.g. browse media, I get the following error:

    2021-01-18 08:06:56 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection] [140411687749520] Received {'type': 'media_player/browse_media', 'entity_id': 'media_player.kodi_9e31bafe5b963617f35a89dfdf6c136d', 'id': 59}
    2021-01-18 08:06:56 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection] [140411687749520] Sending {'id': 59, 'type': 'result', 'success': True, 'result': {'title': 'Media Library', 'media_class': 'directory', 'media_content_type': 'library', 'media_content_id': 'library', 'can_play': False, 'can_expand': True, 'children_media_class': 'directory', 'thumbnail': None, 'children': [{'title': 'Music', 'media_class': 'directory', 'media_content_type': 'library_music', 'media_content_id': '', 'can_play': False, 'can_expand': True, 'children_media_class': None, 'thumbnail': None}, {'title': 'Movies', 'media_class': 'directory', 'media_content_type': 'movie', 'media_content_id': '', 'can_play': False, 'can_expand': True, 'children_media_class': None, 'thumbnail': None}, {'title': 'TV shows', 'media_class': 'directory', 'media_content_type': 'tvshow', 'media_content_id': '', 'can_play': False, 'can_expand': True, 'children_media_class': None, 'thumbnail': None}, {'title': 'Channels', 'media_class': 'directory', 'media_content_type': 'channel', 'media_content_id': '', 'can_play': False, 'can_expand': True, 'children_media_class': None, 'thumbnail': None}]}}
    2021-01-18 08:06:57 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection] [140411687749520] Received {'type': 'media_player/browse_media', 'entity_id': 'media_player.kodi_9e31bafe5b963617f35a89dfdf6c136d', 'media_content_id': '', 'media_content_type': 'tvshow', 'id': 60}
    2021-01-18 08:06:57 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [140411687749520] Error handling message: Unknown error
    Traceback (most recent call last):
    File "/usr/src/homeassistant/homeassistant/components/websocket_api/decorators.py", line 18, in _handle_async_response
    await func(hass, connection, msg)
    File "/usr/src/homeassistant/homeassistant/components/media_player/__init__.py", line 1066, in websocket_browse_media
    payload = await player.async_browse_media(media_content_type, media_content_id)
    File "/usr/src/homeassistant/homeassistant/components/kodi/media_player.py", line 881, in async_browse_media
    response = await build_item_response(self._kodi, payload)
    File "/usr/src/homeassistant/homeassistant/components/kodi/browse_media.py", line 140, in build_item_response
    media = await media_library.get_tv_shows(properties)
    File "/usr/local/lib/python3.8/site-packages/pykodi/kodi.py", line 382, in get_tv_shows
    return await self._server.VideoLibrary.GetTVShows(
    File "/usr/local/lib/python3.8/site-packages/jsonrpc_websocket/jsonrpc.py", line 42, in send_message
    raise TransportError('Client is not connected.', message)
    jsonrpc_base.jsonrpc.TransportError: Error calling method 'VideoLibrary.GetTVShows': Client is not connected.
    2021-01-18 08:06:57 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection] [140411687749520] Sending {'id': 60, 'type': 'result', 'success': False, 'error': {'code': 'unknown_error', 'message': 'Unknown error'}}
    

    I am able to connect to the Kodi API from the HA docker image or my computer without any problem, so there is no network issue present.

    curl -v 192.168.1.2:8080
    *   Trying 192.168.1.2:8080...
    * Connected to 192.168.1.2 (192.168.1.2) port 8080 (#0)
    > GET / HTTP/1.1
    > Host: 192.168.1.2:8080
    > User-Agent: curl/7.69.1
    > Accept: */*
    >
    * Mark bundle as not supporting multiuse
    < HTTP/1.1 200 OK
    < Connection: Keep-Alive
    < Last-Modified: Thu, 19 Sep 2019 01:50:48 GMT
    < Content-Type: text/html
    < Content-Length: 5675
    < Cache-Control: private, max-age=0, no-cache
    < Accept-Ranges: bytes
    < Date: Mon, 18 Jan 2021 08:06:33 GMT
    <
    <!DOCTYPE html>
    [...]
    

    #45254 seems to have the same issue.

    I honestly doubt that this issue is in the Kodi integration, because there are literary no changed between 2012.1.3 and 2021.1.2 2021.1.2...2021.1.3. I still think that this might be a side effect from the newly integrated security filter, but I'm not firm enough with the home assistant core yet to confirm this claim.

    Edit:
    I reverted the docker container again to 2021.1.2 without changing anything else and the Kodi integration immediately starts working again.

    2021-01-18 09:00:02 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection] [139753306227376] Received {'type': 'call_service', 'domain': 'media_player', 'service': 'media_play_pause', 'service_data': {'entity_id': 'media_player.kodi_9e31bafe5b963617f35a89dfdf6c136d'}, 'id': 59}
    2021-01-18 09:00:02 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection] [139753306227376] Sending {'id': 59, 'type': 'result', 'success': True, 'result': {'context': Context(user_id='0a5af9cc7bcc4119ad31611212efb399', parent_id=None, id='729ce2a1dc7c78c86f4028e0ee51f21f')}}
    2021-01-18 09:00:02 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection] [139753306227376] Sending {"id": 2, "type": "event", "event": {"event_type": "state_changed", "data": {"entity_id": "media_player.kodi_9e31bafe5b963617f35a89dfdf6c136d", "old_state": {"entity_id": "media_player.kodi_9e31bafe5b963617f35a89dfdf6c136d", "state": "playing", "attributes": {"volume_level": 1.0, "is_volume_muted": false, "media_content_type": "video", "media_position": 751, "media_position_updated_at": "2021-01-18T08:57:38.482714+00:00", "media_title": "Man with a Plan", "supported_features": 186303}, "last_changed": "2021-01-18T08:57:38.606944+00:00", "last_updated": "2021-01-18T08:57:38.606944+00:00", "context": {"id": "3c9444ee616a8c347eab6102007eab6b", "parent_id": null, "user_id": null}}, "new_state": {"entity_id": "media_player.kodi_9e31bafe5b963617f35a89dfdf6c136d", "state": "playing", "attributes": {"volume_level": 1.0, "is_volume_muted": false, "media_content_type": "video", "media_position": 895, "media_position_updated_at": "2021-01-18T09:00:02.105497+00:00", "media_title": "Man with a Plan", "supported_features": 186303}, "last_changed": "2021-01-18T08:57:38.606944+00:00", "last_updated": "2021-01-18T09:00:02.106408+00:00", "context": {"id": "fa40cd6d631365dcc5fcffa0c20d8598", "parent_id": null, "user_id": "0a5af9cc7bcc4119ad31611212efb399"}}}, "origin": "LOCAL", "time_fired": "2021-01-18T09:00:02.106408+00:00", "context": {"id": "fa40cd6d631365dcc5fcffa0c20d8598", "parent_id": null, "user_id": "0a5af9cc7bcc4119ad31611212efb399"}}}
    

    I also manually removed the security filter, but that didn't fix the issue. So maybe the issue is related to one of the updated libraries?

  5. OnFreund commented on Jan 18, 2021

    @OnFreund
    Contributor

    The integration is configured via the UI so there is no yaml to present

    You can see the config entry in .storage/core.config_entries. Specifically, I'd like to know if you're connecting over websocket or not.

    I added the following logger and restarted HA:

    I need all the logs from the Kodi integration, not just the media_player platform. The fact that the platform isn't outputting any logs probably points to a failure in initialization of the integration, before the entity is created.

    I also manually removed the security filter, but that didn't fix the issue. So maybe the issue is related to one of the updated libraries?

    Definitely possible - specifically, aiohttp was upgraded. Can you try to downgrade that?

  6. L-Henke commented on Jan 18, 2021

    @L-Henke
    ContributorAuthor

    This issue is really related to aiohttp. I downgraded it to 3.7.1 and the Kodi integration is working again. (HA 2021.1.4 with aiohttp 3.7.1)

    Integration configuration:

    {
        "entry_id": "9e31bafe5b963617f35a89dfdf6c136d",
        "version": 1,
        "domain": "kodi",
        "title": "Title",
        "data": {
            "name": null,
            "host": "192.168.1.2",
            "port": 8080,
            "ws_port": 9090,
            "username": null,
            "password": null,
            "ssl": false,
            "timeout": 5
        },
        "options": {},
        "system_options": {
            "disable_new_entities": false
        },
        "source": "user",
        "connection_class": "local_poll",
        "unique_id": null
    },
    

    There aren't any information in the logs without the debug logger. With the debug logger, the logs are absolutely massive and I need to trim them down, which will take a while. I'll have a further look if I can get more output from aiohttp or see which change might cause this issue and will provide a reasonable trimmed log output.

    The new issue #45285 might be pointing in the same direction, because it seems that there are also some http calls which are hanging for 5 minutes - like I observed with the calls to the Kodi API.

  7. OnFreund commented on Jan 18, 2021

    @OnFreund
    Contributor

    OK, we're making progress. Also, you're communicating over websocket, so the 8080 test in docker doesn't mean much (and I'm also using websocket and have no problem with the latest aiohttp 🤷‍♂️ ).
    As for logging, use homeassistant.components.kodi: debug

  8. L-Henke commented on Jan 18, 2021

    @L-Henke
    ContributorAuthor

    @OnFreund the issue seems to be with your library, aiohttp, websockets and specific Kodi (or maybe not Kodi) versions.

    I have to add, that I tried to connect to a modified version of Kodi called MrMC. Contrary to Kodi, this version is provided via Apples AppStore for the Apple TV. It is possible to sideload the real Kodi to the Apple TV, but this was to bothersome for me which is why I bought MrMc. Till now it was completely compatible to the Kodi APIs for my use cases.

    I created this rather ugly test script using your library directly:

    import asyncio
    from pykodi import get_kodi_connection, Kodi
    
    async def test():
        kc = get_kodi_connection("192.168.1.2", 8080, None, None, None,)
        await kc.connect()
        kodi = Kodi(kc)
        properties = await kodi.get_application_properties(["name", "version"])
        print (properties)
    
    def main():
        loop = asyncio.get_event_loop()
        loop.run_until_complete(test())
        loop.close()
    
    if __name__ == '__main__':
        main()
    

    If I try to connect to MrMC with only http port set (8080, None), both versions of aiohttp are working fine:

    pip install aiohttp==3.7.1
        […]
        Successfully installed aiohttp-3.7.1
    python test.py
        {'name': 'MrMC', 'version': {'major': 3, 'minor': 9, 'revision': '2020-10-16-5cd7aa7', 'tag': 'prealpha'}}
        […]
    pip install aiohttp==3.7.3
        […]
        Successfully installed aiohttp-3.7.3
    python test.py
        {'name': 'MrMC', 'version': {'major': 3, 'minor': 9, 'revision': '2020-10-16-5cd7aa7', 'tag': 'prealpha'}}
        […]
    

    If I try to connect to MrMC with only ws_port set (None, 9090), aiohttp 3.7.1 is working, but 3.7.3 hangs:

    pip install aiohttp==3.7.1
        […]
        Successfully installed aiohttp-3.7.1
    python test.py
        {'name': 'MrMC', 'version': {'major': 3, 'minor': 9, 'revision': '2020-10-16-5cd7aa7', 'tag': 'prealpha'}}
        […]
    pip install aiohttp==3.7.3
        […]
        Successfully installed aiohttp-3.7.3
    python test.py
        [—Hangs—]
    

    If I try the same tests to a current version and older version of Kodi (18.9 and 18.6) everything works as expected:

    Connection to Kodi with only http port set (8080, None)

    pip install aiohttp==3.7.1
        […]
        Successfully installed aiohttp-3.7.1
    python test.py
        {'name': 'Kodi', 'version': {'major': 18, 'minor': 9, 'revision': '20201023-0655c2c718', 'tag': 'stable'}}
        […]
    pip install aiohttp==3.7.3
        […]
        Successfully installed aiohttp-3.7.3
    python test.py
        {'name': 'Kodi', 'version': {'major': 18, 'minor': 9, 'revision': '20201023-0655c2c718', 'tag': 'stable'}}
        […]
    

    Connection to Kodi with only ws_port set (None, 9090)

    pip install aiohttp==3.7.1
        […]
        Successfully installed aiohttp-3.7.1
    python test.py
        {'name': 'Kodi', 'version': {'major': 18, 'minor': 9, 'revision': '20201023-0655c2c718', 'tag': 'stable'}}
        […]
    pip install aiohttp==3.7.3
        […]
        Successfully installed aiohttp-3.7.3
    python test.py
        {'name': 'Kodi', 'version': {'major': 18, 'minor': 9, 'revision': '20201023-0655c2c718', 'tag': 'stable'}}
        […]
    

    This means, your library is working correctly against the supported versions of Kodi and the problem seems to only occurs with an unsupported, rebranded version of Kodi, although it seems that the user in #45254 is using the real Kodi 18.9). Nevertheless, feel free to close this issue.

    I'll try to force HA to only use a http-connection to Kodi or try to sideload the original Kodi version to my Apple TV. I also might be sending a PR to the library repo if I can locate the problem and fix it in a way that both the official and rebranded version of Kodi are working with it.

    I'm sorry if I caused you unnecessary efforts.

    Edit:
    I replaced the ws_port in .storage/core.config_entries with null, and now everything is working again with HA 2021.1.4 and the included aiohttp version 3.7.3.

  9. OnFreund commented on Jan 18, 2021

    @OnFreund
    Contributor

    Thanks for the detailed response.
    You can force the kodi integration to use the http connection by editing the config entry.
    Feel free to close the issue (I don't have these permission, but you as the person who opened it do).
    If you manage to get a PR, I'm more than happy to review it, although that PR will most likely be to lower level components (one of the json-rpc libraries, or to aiohttp itself).

  10. L-Henke commented on Jan 18, 2021

    @L-Henke
    ContributorAuthor

    @OnFreund in case you have to face this issue again. The problem was introduces in this commit in aiohttp. The parent commit is the last running version.

  11. OnFreund commented on Jan 18, 2021

    @OnFreund
    Contributor

    Thanks @L-Henke
    When looking through this, one thing that comes to mind is this:
    aio-libs/aiohttp@3c4ba8f#diff-f334e752b4894ef951105572ab8b195aeb8db90eb6e48b1dfbd9a01da4c854f5R733
    Can you try changing upgrade to Upgrade and see if it works?

  12. L-Henke commented on Jan 18, 2021

    @L-Henke
    ContributorAuthor

    Thats it! aiohttp 3.7.3 with the line changed to Upgrade is working.

    I'm not a web development expert, but the RFC section 2.1 states, that strings should be compared case insensitive. This means, that the changed string in aiohttp is compliant to the RFC and the problem is in the called jsonrpc API of MrMC. But maybe a widely used library shouldn't change headers without a reason. I'll open an issue in aiohttp, maybe they will change it back or have a good reason to use the lowercase variable.

    Edit: aio-libs/aiohttp#5417

  13. OnFreund commented on Jan 18, 2021

    @OnFreund
    Contributor

    Great. I would also suggest opening an issue with MrMC, as it seems it's their implementation that is broken.

  14. dperfect commented on Jan 18, 2021

    @dperfect

    I'm seeing this same issue with a stock version of Kodi (18.9) and the latest homeassistant/home-assistant:stable docker image, trying to configure the integration via the UI (as recommended here: https://www.home-assistant.io/integrations/kodi/).

    If this has been resolved (either through fixes to dependencies and updated in HA or via a workaround in HA) but just hasn't made it to the stable image, then ignore this and keep the issue closed. If not, however, (just my opinion) I'd like to see this issue remain open until it is actually resolved.

  15. L-Henke commented on Jan 18, 2021

    @L-Henke
    ContributorAuthor

    @dperfect you might want to try to also force the integration to use simple http connection instead of a websocket connection like I did in #45249 (comment). (replace "ws_port": "9090"with "ws_port": null in .storage/core.config_entries

    If that also solves the issue for you, I guess we ran into the same problem and this should be reopened.

  16. dperfect commented on Jan 18, 2021

    @dperfect

    @L-Henke Thanks for the suggestion. My .storage/core.config_entries doesn't contain ws_port anywhere in the file, presumably because I haven't been able to configure the Kodi integration to begin with (it just shows the "Unknown error occurred" when trying to set it up).

  17. L-Henke commented on Jan 18, 2021

    @L-Henke
    ContributorAuthor

    Another quick and dirty workaround would be:

    Spawn a shell into your home assistant docker container: docker exec -it <container-id> bash and change line 733 in /usr/local/lib/python3.8/site-packages/aiohttp/client.py from hdrs.CONNECTION: "upgrade" to hdrs.CONNECTION: "Upgrade" and restart the container. Of course this line applies only to the current image (2021.1.4).

    --- client.py.old
    +++ client.py
    @@ -730,7 +730,7 @@
    
             default_headers = {
                 hdrs.UPGRADE: "websocket",
    -            hdrs.CONNECTION: "upgrade",
    +            hdrs.CONNECTION: "Upgrade",
                 hdrs.SEC_WEBSOCKET_VERSION: "13",
             }
    

    If you have the same problem as me, you should be able to add the integration afterwards via the UI and can then change the ws_port in the config, since the fix in the docker image won't (and shouldn't) persist.

  18. OnFreund commented on Jan 18, 2021

    @OnFreund
    Contributor

    @dperfect I don't think it's the same problem. If websocket communication fails when adding the integration UI, you can simply remove the port and add it.
    Please open a new issue, describe the exact flow, and add the relevant logs (with Kodi set to debug).

  19. dperfect commented on Jan 18, 2021

    @dperfect

    @OnFreund - Thank you. After further investigation, I got it to work (without any of the aiohttp changes). Apparently the issue was on the Kodi configuration side. The HA UI says this when configuring the Kodi integration:

    Please make sure to enable "Allow control of Kodi via HTTP" in System/Settings/Network/Services.
    

    I had that enabled, but "Allow remote control from applications on other systems" was disabled (default). I noticed that the integration UI does mention enabling that also, but only after the first step completes and it asks to optionally enable websocket communication. Since I never got to that step, I never saw that, and apparently (from what I'm experiencing) it needs that setting enabled in Kodi, even for the first step to complete.

    So yes, different issue. Possibly a UI/documentation issue, or maybe it's trying the websocket connection prematurely in the configuration flow.

  20. OnFreund commented on Jan 19, 2021

    @OnFreund
    Contributor

    If websocket isn't enabled, you're supposed to go to the second step. Not sure why you didn't get past the first. Can you explain exactly what happened?

  21. dperfect commented on Jan 19, 2021

    @dperfect

    @OnFreund This is easily reproducible for me, but appears to be at least somewhat related to the Windows 10 firewall.

    With Kodi configured with Allow remote control from applications on other systems disabled, it never gets past the first step.
    kodi-1
    ha

    But when that option is enabled (no changes on the HA side), it all works:
    kodi-2

    With the Windows firewall completely disabled, it works as intended (passes the first step but prompts for the websocket port when Allow remote control from applications on other systems is disabled).

    So to summarize:

    • Windows 10 Firewall enabled (default settings)
      • Allow... other systems disabled: can't pass first step (but can access the web UI on port 8080 from other computers on network)
      • Allow... other systems enabled: works, no prompt for ws port (since ws works also)
    • Windows 10 Firewall disabled
      • Allow... other systems disabled: passes first step, prompts for websocket port
      • Allow... other systems enabled: works, no prompt for ws port (since ws works also)

    I completely cleared the Kodi entries from the firewall and re-launched Kodi, and the behavior is the same, but I haven't found any differences in the firewall configuration whether Allow... other systems is enabled or disabled. So... maybe a Kodi bug? The only thing that makes me think otherwise is that port 8080 is accessible from other computers on the LAN in all of the cases mentioned.

    My theory is that in the first scenario (firewall on, but Allow... other systems disabled), maybe the integration is succeeding in connecting to port 8080, but then when trying a ws connection (to determine whether or not to prompt in the 2nd step), the firewall is causing the connection attempt to be rejected (rather than just dropped), and for some reason, the integration is seeing that as a complete failure to connect (even though 8080 was fine). With the firewall disabled, the ws connection is just dropped, prompting the 2nd step in the UI as intended.

    Edit: On second thought, it could be the reverse of what I described since the first scenario failure is slow (more likely a dropped connection timing out), whereas with the firewall completely off, the ws failure (and prompt) is fast, suggesting a rejected connection. All just speculation though 😄

  22. OnFreund commented on Jan 19, 2021

    @OnFreund
    Contributor

    Thanks @dperfect, this is really helpful. You're most likely right with the edit - the firewall is probably dropping the connection rather than rejecting it.
    Are you proficient in Python? If so, can you try to change the code in https://github.com/OnFreund/PyKodi/blob/master/pykodi/kodi.py#L136 to understand which Exception is raised?
    In any case, this seems like a problem in my package, not in the integration, so please open an issue there with your findings and I'll change it accordingly. (I don't have access to a Windows computer to do it myself...)

  23. dperfect commented on Jan 19, 2021

    @dperfect

    @OnFreund Ok, looks like it's raising asyncio.exceptions.CancelledError. I opened an issue in OnFreund/PyKodi:

    xbmc/PyKodi#7

  24. dperfect commented on Jan 22, 2021

    @dperfect

    In case anyone else comes across this thread experiencing "Unknown error occurred" while trying to connect Kodi (with Allow remote control via HTTP enabled and Allow remote control from applications on other systems disabled in Kodi), you might want to check to see if you have:

    • A firewall (like Windows Firewall / Microsoft Defender Firewall) that is dropping - rather than rejecting - the websocket connection attempt from the Kodi component
    • A reverse proxy on your HA instance that is prematurely closing the browser's HTTP request to HA while waiting for the delayed result of the websocket connection attempt

    If that describes your environment, you can either enable Allow ... other systems in Kodi (if security policy allows), or configure your reverse proxy to use a longer timeout period.

  25. locked and limited conversation to collaborators on Feb 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Fields

Priority

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions