cdnninja / yoto_ha

Home Assistant Integration for Yoto
MIT License
51 stars 7 forks source link

feat request: media player icon #68

Closed cjb0001 closed 3 months ago

cjb0001 commented 3 months ago

Would you mind also adding the 16x16 icon attribute? I couldn't figure out how to reference the icon from the currently playing chapter/track. It will need to be added as an "extra_state_attribute". Here are some examples of how other media_player integrations have done this. Seems like state check before returning the icon is the right thing to do. Thanks

Denon
    @property
    def extra_state_attributes(self) -> dict[str, Any]:
        """Return device specific state attributes."""
        receiver = self._receiver
        if receiver.power != POWER_ON:
            return {}
        state_attributes: dict[str, Any] = {}
        if (
            sound_mode_raw := receiver.sound_mode_raw
        ) is not None and receiver.support_sound_mode:
            state_attributes[ATTR_SOUND_MODE_RAW] = sound_mode_raw
        if (dynamic_eq := receiver.dynamic_eq) is not None:
            state_attributes[ATTR_DYNAMIC_EQ] = dynamic_eq
        return state_attributes

zidoo
    @property
    def extra_state_attributes(self):
        """Return the device specific state attributes."""
        extras = {
            "uri",
            "height",
            "width",
            "zoom",
            "tag",
            "date",
            "bitrate",
            "fps",
            "audio",
            "video",
        }
        attributes = {}
        for item in extras:
            value = self.coordinator.media_info.get(item)
            if value:
                attributes["media_" + item] = value

        return attributes

 heos
    @property
    def extra_state_attributes(self) -> dict[str, Any]:
        """Get additional attribute about the state."""
        return {
            "media_album_id": self._player.now_playing_media.album_id,
            "media_queue_id": self._player.now_playing_media.queue_id,
            "media_source_id": self._player.now_playing_media.source_id,
            "media_station": self._player.now_playing_media.station,
            "media_type": self._player.now_playing_media.type,
        }

directv
    def extra_state_attributes(self):
        """Return device specific state attributes."""
        if self._is_standby:
            return {}
        return {
            ATTR_MEDIA_CURRENTLY_RECORDING: self.media_currently_recording,
            ATTR_MEDIA_RATING: self.media_rating,
            ATTR_MEDIA_RECORDED: self.media_recorded,
            ATTR_MEDIA_START_TIME: self.media_start_time,
        }
cdnninja commented 3 months ago

Are you looking for the track icon or the chapter icon? I haven't seen the difference in my yoto yet but maybe I don't have a card that has that.

For reference will be from here once we pick: https://github.com/cdnninja/yoto_api/blob/master/yoto_api/Card.py I don't think I populate track icon yet.

cdnninja commented 3 months ago

I have created the code to parse all the track and chapter data into the object listed above: https://github.com/cdnninja/yoto_api/pull/59

That is first step. Next we can easily display that data.

cdnninja commented 3 months ago

81 does this. Let me know thoughts on if this is what you were thinking. Right now track sometimes comes as "null" but it doesn't error out. Wondering if that is okay or if I should only return non null. It doesn't error or anything

image

cdnninja commented 3 months ago

I corrected this. It will now only show if data exists.