#####################################################
##
##   FILENAME: cards/music.yaml
##   DESCRIPTION: card that shows info 
##   about the current played song and
##   players current state
##   USAGE:
##   package:
##     ...
##     card_music: !include
##       file: cards/music.yaml
##       vars:
##         entity_id: media_player.xxxx
##
##   display:
##   - id: !extend main_display
##        pages:
##          - id: player_page
##            lambda: |-
##              id(all_pages).execute();
##              // insert music card:
##              // >> id(music_card).execute(x, y);
##              id(music_card).execute(20, 125);
##
#####################################################

image:
  - file: mdi:music-box-outline
    id: icon_music_album
    resize: 20x20
  - file: mdi:account-music
    id: icon_music_artist
    resize: 20x20
  - file: mdi:music-note
    id: icon_music_songtitle
    resize: 20x20
  - file: mdi:pause-box-outline
    id: icon_music_pause
    resize: 75x75
  - file: mdi:play-box-outline
    id: icon_music_play
    resize: 75x75

text_sensor:
  - platform: homeassistant
    id: music_album
    entity_id: ${music_card_enity_id}
    attribute: media_album_name
    on_value: 
      - script.execute: update_main
  - platform: homeassistant
    id: music_artist
    entity_id: ${music_card_enity_id}
    attribute: media_artist
  - platform: homeassistant
    id: music_title
    entity_id: ${music_card_enity_id}
    attribute: media_title
    on_value: 
      - script.execute: update_main
  - platform: homeassistant
    id: music_playerstate
    entity_id: ${music_card_enity_id}
    on_value: 
      - script.execute: update_main

script:
  - id: music_card
    parameters: 
      x: int
      y: int
    then: 
      - lambda: |-
          // id(main_display).print(60+x, 0+y, id(font_arial20), id(white), TextAlign::TOP_LEFT , id(music_playerstate).state.c_str());
          if (strcmp(id(music_playerstate).state.c_str(), "paused") == 0) {
              id(main_display).image(x, 1+y, id(icon_music_pause), ImageAlign::TOP_LEFT, id(orange));
          } else if (strcmp(id(music_playerstate).state.c_str(), "playing") == 0) {
              id(main_display).image(x, 1+y, id(icon_music_play), ImageAlign::TOP_LEFT, id(orange));
          }
          //
          // album
          id(main_display).image(75+3+x, 4+y, id(icon_music_album), ImageAlign::TOP_LEFT, id(orange));
          id(main_display).print(75+25+x, 0+y, id(font_arial20), id(white), TextAlign::TOP_LEFT , id(music_album).state.c_str());
          //
          // artist
          id(main_display).image(75+3+x, 30+y, id(icon_music_artist), ImageAlign::TOP_LEFT, id(orange));
          id(main_display).print(75+25+x, 26+y, id(font_arial20), id(white), TextAlign::TOP_LEFT , id(music_artist).state.c_str()); 
          //
          // song title
          id(main_display).image(75+3+x, 56+y, id(icon_music_songtitle), ImageAlign::TOP_LEFT, id(orange));
          id(main_display).print(75+25+x, 52+y, id(font_arial20), id(white), TextAlign::TOP_LEFT , id(music_title).state.c_str()); 