bushvin / hass-integrations

My custom Home Assistant integrations
Apache License 2.0
61 stars 11 forks source link

Include attributes for consume-mode & media_type (if possible) #35

Closed Switch123456789 closed 10 months ago

Switch123456789 commented 10 months ago

Hey, it is me again :) still messing around with your integration to see what I can do.

Today I wanted to make Lovelace react to the media_type that is playing (local:track:, youtube:video:, http:, ect.) I know it is part of media_content_id but it turned out to be a pain in the b*tt to just do a simple trim on a string within lovelace to get a proper value, so it would be very handy for those 2 people on earth who would want that without the clutter.

Having feedback in Home Assistant for the state of the consume_mode would be nice as well :)

bushvin commented 10 months ago

Not quite sure what you aim to do with the media_content_id. If you could provide an example that would make things clearer.

I'm not sure on how to add consume_mode to the entity, but it makes sense. I will dig in a bit

Switch123456789 commented 10 months ago

Not quite sure what you aim to do with the media_content_id.

It's value contains the media-type (or rather media source), I wish to see what the media-source is in lovelace. I could try to split the string in jinja or java (costum:button-card) to get unique strings that will work as conditions.

I can see that this might be not worth the effort to implement, depending on how much work it would take

I will dig in a bit

Thank you :) Are there limitations to mopidy's media-player-entity?

Switch123456789 commented 10 months ago

I found a way to extract the music-source from media_content_id, those 2 example strings show how.

As Template: state_attr('media_player.mopidy', 'media_content_id').split(':')[0] In costum:button-card: states['media_player.mopidy'].attributes.media_content_id.split(':')[0]

Causes a bit of clutter, but it's not too bad :D

bushvin commented 10 months ago

Aha... I think I understand. You would like to have the source (eg local, spotify, tunein, tidal,...) separately

That is doable. I could add an attribute called source_extension

bushvin commented 10 months ago

Something like this (line 23 in the screenshot) mopidy_extension Screenshot_20231022_160810

Switch123456789 commented 10 months ago

Something like this

exactly!

bushvin commented 10 months ago

In an effort to provide some more newer Home Assistant features, I've refactored all my code. The above can be found in my development branch for v2 called feature/compat.

If you want, you can give it a spin.

Switch123456789 commented 10 months ago

Nice! I am working with v2 since yesterday and it's working fine :) thank you!

I noticed that some services are not available, turn_on turn_off & toggle. I think because of that it is impossible to stop playback with the default media-player-card/info-panel. Personally I don't mind that since I don't use it and calling the media_player.stop-service does turn off the player but I can imagine some people might get bothered by that.

EDIT: media_playlist seems to be gone , I use that for a bunch of things, I hope you can bring that back sir :)

Your efforts are much appreciated.

bushvin commented 10 months ago

Thanks for the feedback!

I did indeed remove the turn_on and turn_off capability, as after reading a bit on the topic it means you have a real toggle to turn on or off the device, which is not the case.

Both the default media card and the mini-media-card can pause what you are playing. Stopping it from any of these cards seems not to have been implemented.

Personally I prefer not having the turn on/off functionality, as it hides too much stuff when turning it off.

I also asked feedback in my home assistant thread, so I'll see what happens...

Switch123456789 commented 10 months ago

Makes sense, I am not sure but I though Mopidy keeps sending audio when paused, this could waste some of the host machines resources, as long as you don't remove stop button I am happy :)

Did you notice my edit in the last post? Most of my implementations rely on playlists, please help :D

bushvin commented 10 months ago

It must have crossed posts. I did not intentionally remove media_playlist, so I will definitely restore its functionality.

Wrt signal being sent out when not turned off, how can I reproduce this? What are the steps you took, so I can investigate a bit more?

bushvin commented 10 months ago

media_playlist should be available now

bushvin commented 10 months ago

fixed with #37

Switch123456789 commented 10 months ago

Yesterday I finally found time to check out your changes. I noticed you included the capability to add songs to the queue, which wasn't possible before (or I didn't see it), that's great :)

I did some testing and things work very well! There is only 2 minor things I noticed:

  1. Sometimes when changing the song the entity doesn't report that it is still playing for a second or two (might be a mopidy thing tough)
  2. Long response-times in general when sending commands. For example when I skip songs from within Home Assistant, sometimes the entity gets updated 2 seconds after the song started playing.

Nonetheless this update is great and much appreciated. Thank you!!!

bushvin commented 10 months ago

Many thanks for testing. The lag you are experiencing is because of the home assistant component update schedule. it is a fixed time interval (of about 10 seconds). I believe I would be able to do it using async methods, but I need to look into this. I am not a coder, so these things tend to take some time for me to understand how to properly code.

Switch123456789 commented 10 months ago

I feel you, I just created my first home assistant add-on with only knowing a thing or two about shell script and had to learn everything from scratch on my way (it is a mopidy-add-on with extras btw.).

It would be a nice addition to have a more responsive interface but it's not a deal-breaker if it isn't. Controlling the music in my whole flat with Home Assistant is already so cool & practical within itself :) I love it!