-
-
Notifications
You must be signed in to change notification settings - Fork 37.8k
Add Plex library count sensors #48339
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
0f9c8e6
Add Plex library count sensors
jjlawren 7172b34
Fix lint, add tests
jjlawren 412ef6b
Reuse existing trigger method
jjlawren 9f2150d
Disable library sensors by default
jjlawren 54cdfb3
Fix tests to handle sensor disabled by default
jjlawren 5794c70
Use async_on_remove during dispatcher setup
jjlawren 18a5d30
Don't recreate method repeatedly
jjlawren File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| """Tests for Plex sensors.""" | ||
| from homeassistant.const import STATE_UNAVAILABLE | ||
|
|
||
| from .helpers import trigger_plex_update, wait_for_debouncer | ||
|
|
||
| LIBRARY_UPDATE_PAYLOAD = {"StatusNotification": [{"title": "Library scan complete"}]} | ||
|
|
||
|
|
||
| async def test_library_sensor_values( | ||
| hass, | ||
| setup_plex_server, | ||
| mock_websocket, | ||
| requests_mock, | ||
| library_tvshows_size, | ||
| library_tvshows_size_episodes, | ||
| library_tvshows_size_seasons, | ||
| ): | ||
| """Test the library sensors.""" | ||
| requests_mock.get( | ||
| "/library/sections/2/all?includeCollections=0&type=2", | ||
| text=library_tvshows_size, | ||
| ) | ||
| requests_mock.get( | ||
| "/library/sections/2/all?includeCollections=0&type=3", | ||
| text=library_tvshows_size_seasons, | ||
| ) | ||
| requests_mock.get( | ||
| "/library/sections/2/all?includeCollections=0&type=4", | ||
| text=library_tvshows_size_episodes, | ||
| ) | ||
|
|
||
| await setup_plex_server() | ||
| await wait_for_debouncer(hass) | ||
|
|
||
| activity_sensor = hass.states.get("sensor.plex_plex_server_1") | ||
| assert activity_sensor.state == "1" | ||
|
|
||
| library_tv_sensor = hass.states.get("sensor.plex_server_1_library_tv_shows") | ||
| assert library_tv_sensor.state == "10" | ||
| assert library_tv_sensor.attributes["seasons"] == 1 | ||
| assert library_tv_sensor.attributes["shows"] == 1 | ||
|
|
||
| # Handle library deletion | ||
| requests_mock.get( | ||
| "/library/sections/2/all?includeCollections=0&type=2", status_code=404 | ||
| ) | ||
| trigger_plex_update( | ||
| mock_websocket, msgtype="status", payload=LIBRARY_UPDATE_PAYLOAD | ||
| ) | ||
| await hass.async_block_till_done() | ||
|
|
||
| library_tv_sensor = hass.states.get("sensor.plex_server_1_library_tv_shows") | ||
| assert library_tv_sensor.state == STATE_UNAVAILABLE |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <MediaContainer size="0" totalSize="1" allowSync="1" art="/:/resources/show-fanart.jpg" identifier="com.plexapp.plugins.library" librarySectionID="2" librarySectionTitle="TV Shows" librarySectionUUID="905308ec-5019-43d4-a449-75d2b9e42f93" mediaTagPrefix="/system/bundle/media/flags/" mediaTagVersion="1614092584" nocache="1" offset="0" sortAsc="1" thumb="/:/resources/show.png" title1="TV Shows" title2="All Shows" viewGroup="show" viewMode="131122"> | ||
| </MediaContainer> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <MediaContainer size="0" totalSize="10" allowSync="1" art="/:/resources/show-fanart.jpg" identifier="com.plexapp.plugins.library" librarySectionID="2" librarySectionTitle="TV Shows" librarySectionUUID="905308ec-5019-43d4-a449-75d2b9e42f93" mediaTagPrefix="/system/bundle/media/flags/" mediaTagVersion="1614092584" nocache="1" offset="0" sortAsc="1" thumb="/:/resources/show.png" title1="TV Shows" title2="All Shows" viewGroup="show" viewMode="131122"> | ||
| </MediaContainer> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <MediaContainer size="0" totalSize="1" allowSync="1" art="/:/resources/show-fanart.jpg" identifier="com.plexapp.plugins.library" librarySectionID="2" librarySectionTitle="TV Shows" librarySectionUUID="905308ec-5019-43d4-a449-75d2b9e42f93" mediaTagPrefix="/system/bundle/media/flags/" mediaTagVersion="1614092584" nocache="1" offset="0" sortAsc="1" thumb="/:/resources/show.png" title1="TV Shows" title2="All Shows" viewGroup="show" viewMode="131122"> | ||
| </MediaContainer> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.