home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
73.71k stars 30.84k forks source link

The Jellyfin integration doesn't delete old media players #105000

Closed rwjack closed 11 months ago

rwjack commented 11 months ago

The problem

We're left with a bunch of unused media players.

image

What version of Home Assistant Core has the issue?

core-2023.11.3

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

Jellyfin

Link to integration documentation on our website

https://www.home-assistant.io/integrations/jellyfin

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

No response

home-assistant[bot] commented 11 months ago

Hey there @j-stienstra, @ctalkington, mind taking a look at this issue as it has been labeled with an integration (jellyfin) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `jellyfin` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Renames the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign jellyfin` Removes the current integration label and assignees on the issue, add the integration domain after the command. - `@home-assistant add-label needs-more-information` Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue. - `@home-assistant remove-label needs-more-information` Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


jellyfin documentation jellyfin source (message by IssueLinks)

j-stienstra commented 11 months ago

Hi @rwjack, I'm not seeing this problem with my clients, but I've done some digging through the code (this piece of the integration wasn't written by me) and what I think is happening is that your device reports that it has a persistent identifier whilst in fact it has not. This causes the integration to keep adding the media player as a device (as oposed to a single entity).

I think I can have the application clean up old devices, but as I currently do not have a client that has a persistent id and thus shows up as a device, I first need to see if I can replicate the behavior somehow.

rwjack commented 11 months ago

The Apple TV app for Jellyfin is Swiftfin

The issue might lie there?

j-stienstra commented 11 months ago

Okay, so I tried to replicate the problem using Swiftfin from an iPhone. This works in a sense that I now see a Device being created for the iPhone. However, it does not create multiple devices like your screen shows. I am able to get a second device into HA when I use a different user to log into Jellyfin, but in that instance I also see two clients on the Jellyfin side, so that is expected I believe.

So I think we should focus on identifying why multiple devices get added in your situation. Have you identified when this happens, i.e. can you delete the existing entries manually and try to see in what situation they are added?

I have tested restarting HA, restarting my phone, reconnecting the Swiftfin client, but I do not get more Devices.

rwjack commented 11 months ago

To start off, I deleted the integration and re-added it. It immediately created 2 AppleTV entities.

image

image

image

For some odd reason, the second one is showing as paused, even though the TV is off and Jellyfin is closed.

Even the sensor shows as playing:

image

rwjack commented 11 months ago

Started watching again tonight, another AppleTV media player was added, while the first one remains in the Paused state. Now I have 2 on the jellyfin watching sensor. That's a first. Still cannot delete the unused media players.

Deleting and re-adding the integration yields no results, as I'm still stuck with the exact same media players and watching count (2), as prior to the deletion.

Deleting the integration, restarting the jellyfin server, and re-adding the integration seems to remove the excess media players, starting off with only the watching sensor. As soon as I open Swiftfin, a media player that is always idle (no media updates) is created, and when I start actually watching, another one is created with the correct media showing.

Also note that I cannot connect to the jellyfin instance over https via a reverse proxy, but instead I have to connect directly because the integration doesn't allow self signed certs. This is probably not related to the issue, but thought I should mention it.

j-stienstra commented 11 months ago

Thanks for the investigation. Can you share the diagnostic info that you can download from the integration page?

rwjack commented 11 months ago

Here it is:

config_entry-jellyfin-dda375e411d31dbc8c61424181a1689e.json.txt

j-stienstra commented 11 months ago

Thank you for sharing that. I would indeed conclude this is a client issue. Looking at your diagnostics we can see that the two devices that you report have different device_id, hence they are created as separate devices in Home Assistant by the integration.

From https://github.com/jellyfin/Swiftfin/blob/eb17300061315ff310749871f5b79032385ba55a/Shared/Services/NewSessionManager.swift#L115 we can see that the device ID is created from the platform and vendorUUIDString. These are defined here: https://github.com/jellyfin/Swiftfin/blob/main/Shared/Extensions/UIDevice.swift

The vendorUUIDString is based on a identifierForVendor constant defined by Apple here: https://developer.apple.com/documentation/uikit/uidevice/1620059-identifierforvendor Which states "The value of this property is the same for apps that come from the same vendor running on the same device. A different value is returned for apps on the same device that come from different vendors, and for apps on different devices regardless of vendor."

Somehow this does not hold true for the SwiftFin app.

I would suggest you report this issue to the SwiftFin devs.

rwjack commented 11 months ago

Now that is some good investigative work right there.

I'll head over there so we can get this sorted, thanks!

j-stienstra commented 11 months ago

I'm going to close out this issue. Feel free to create a new one should that be needed after working with the client team.

j-stienstra commented 11 months ago

@home-assistant close