gcorgnet / sensor.emby_upcoming_media

Home Assistant component to feed Upcoming Media Card with the latest releases on an Emby instance.
MIT License
20 stars 17 forks source link

Data attribute is a string and not an object #12

Open jumping2000 opened 3 years ago

jumping2000 commented 3 years ago

Version of the custom_component

Emby Latest Media 0.3.4

Configuration


- platform: emby_upcoming_media
  api_key: !secret apikey
  user_id: !secret userid
  host: !secret host
  port: !secret port
  ssl: false
  max: 5
  use_backdrop: false
  include:
    - Film
    - Serie TV

Describe the bug

The component is working, but the "data" attribute is a string and not an object so it's not usable with jinjia in HA. Please could you make the "data" attribute an object? thanks

{{ states.sensor.emby_latest_film.attributes.data is string }} gives true

{{ state_attr('sensor.emby_latest_film', 'data') is string }} gives true

the above code is not working because the data attribute is a string:


          {% set data = state_attr('sensor.emby_latest_film', 'data') %} 
          {{ data[1].title }}
          {%- if data[1].release is none -%} ({{ data[1].aired.split('-')[0] }})
          {% else %} ({{ data[1].release }}) {% endif %}

I see that people using the component Plex Recently Added Component (https://github.com/custom-components/sensor.plex_recently_added) that gives a similar "data" attribute can use Jinjia templates with HA.

THE SOLUTION SEEMS TO BE: replace attributes["data"] = json.dumps(card_json)
with attributes['data'] = card_json in sensor.py

Debug log


Add your logs here.