Skip to content
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

Multiple media players per widget #2534

Merged

Conversation

jannis3005
Copy link
Contributor

@jannis3005 jannis3005 commented May 18, 2022

Summary

I've added the option to specify multiple media players per widget, so that one can control more than one media player through one widget. They are prioritized from left to right (meaning the widget shows the first media player from the left that has a state of playing. if nothing is playing, it shows the first player that is specified in the Entity ID Field.

In addition that, to make it more clear what the user is controlling, i've added a media source lable to the widget and an option to toggle it.

I've also updated the preview image of the media player widget to match the new design.

Screenshots

Dark Light
Screenshot_20220518_214030 Screenshot_20220518_214040
Screenshot_20220518_214044 Screenshot_20220518_214042
Screenshot_20220518_214057 Screenshot_20220518_214105

Link to pull request in Documentation repository

Documentation: home-assistant/companion.home-assistant#749

Any other notes

@jannis3005 jannis3005 changed the title Multiple media players pwer widget Multiple media players per widget May 18, 2022
@jannis3005 jannis3005 force-pushed the multiple-media-players-pwer-widget branch from f6615de to ecedf21 Compare May 18, 2022 19:52
Copy link
Member

@jpelgrom jpelgrom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting idea! I've added some code related comments.

GitHub doesn't allow me to comment on an image, but I'm seeing a pink tint on the bottom left?

I don't think the UI is very intuitive though. Have you considered changing it to make it more obvious you can select multiple entities (for example, another label "Entity ID(s)" or even using something like a dialog instead of a single text input)?

…call's when finding active media player. add db migrations. add text color to media source label. set default value of showsource to false.
@jannis3005
Copy link
Contributor Author

I think that should be all of the concerns adressed :) here's a screenshot of ne new preview (i guess i missed that when creating the pr)

Screenshot_20220519_073719

@jannis3005
Copy link
Contributor Author

@jpelgrom anything else that needs to be addressed/should be changed? :)

Copy link
Member

@jpelgrom jpelgrom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As requested, more suggestions, everything else looks good to me. I'm just an individual who spends a lot of time around here though, someone else will have to give final approval and merge 🙂

Comment on lines 204 to +212
if (artist != null) {
label = artist
}
if (artist == null && title != null) {
label = title
}
if (artist == null && title == null && album != null) {
label = album
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not update the label using a when block? Because it will use the first match, that would allow removing all the == null checks.

label = when {
    artist != null -> artist
    title != null -> title
    album != null -> album
    else -> label
}

Comment on lines +204 to +212
val se = binding.widgetTextConfigEntityId.text.split(",")
se.forEach {
val e = entities[it.trim()]
if (e != null) selectedEntities.add(e)
}

intent.putExtra(
MediaPlayerControlsWidget.EXTRA_ENTITY_ID,
selectedEntity!!.entityId
selectedEntities.map { e -> e?.entityId }.reduce { a, b -> "$a,$b" }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renaming the parameter inside map isn't necessary, why not use it?

Comment on lines +203 to +208
selectedEntities = LinkedList()
val se = binding.widgetTextConfigEntityId.text.split(",")
se.forEach {
val e = entities[it.trim()]
if (e != null) selectedEntities.add(e)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a filter is better than a loop, but that's probably a personal preference.

selectedEntities = LinkedList(
    binding.widgetTextConfigEntityId.text.split(",")
        .mapNotNull { entities[it.trim()] }
)

try {
integrationUseCase.getEntity(mediaPlayerWidget.entityId)
mediaPlayerWidget.entityId.split(",").map { s -> integrationUseCase.getEntity(s.trim()) }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renaming the parameter inside map isn't necessary, why not use it?

@JBassett JBassett merged commit b9c1092 into home-assistant:master May 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants