Having trouble creating Configurable Component for Trakt.tv (OAuth Issues & How to make Component show under Configure Section of UI)?

I’m attempting to develop a Component to allow users to interact with the Trakt.tv accounts. After finding this thread of users that were also interested in such a component. The two use-case I came up with so far are:

  1. Having a List of New Episodes that are airing today on their dashboard
  2. Creating automations that allow users to mark an episode as watched after they finish viewing it on one of their integrated media_player components.

Given these two user-cases, I think the best category for this component would be under sensor, but I’m not entirely sure. Also, I’m running into a few issues in my quest to create this new component.

  1. Since the api requires OAuth I’m struggling to get authenticated.

    • I know I have to implement OAuth using a callback uri that points to HA, so I’ve been trying to study and use bits & pieces of the Spotify. I’ve added the callback uri (http://{ipaddress}:8123/api/trakt) to my Trakt app that I created.

    • I’m using PyTrakt to interact with the Trakt api, but I think I’ll need to find/create a different module to use because the way this, or at least how I have it setup currently, blocks Home Assistant from starting up.

      Command-line output for OAuth

      C:\Users\mhill\Desktop>py -m homeassistant --open-ui
      Config directory: C:\Users\mhill\AppData\Roaming\.homeassistant
      2018-10-17 12:18:51 INFO (MainThread) [homeassistant.loader] Loaded websocket_api from homeassistant.components.websocket_api
      2018-10-17 12:18:51 INFO (MainThread) [homeassistant.bootstrap] Home Assistant core initialized
      2018-10-17 12:18:51 INFO (MainThread) [homeassistant.loader] Loaded logger from homeassistant.components.logger
      2018-10-17 12:18:51 INFO (MainThread) [homeassistant.setup] Setting up logger
      Please go here and authorize, https://api-v2launch.trakt.tv/oauth/authorize?response_type=code&client_id=MYCLIENTID&redirect_uri=http%3A%2F%2FMYIPADDRESS%3A8123%2Fapi%2Ftrakt&state=8DADVtzv7ygQzyWKoRC7i0sMnFDwcR&username=CaffeinatedMike
      Paste the Code returned here:
      

      Partial trakt.py component code

      def setup_platform(hass, config, add_entities, discovery_info=None):
          """Set up the trakt platform."""
          import trakt
      
          callback_url = '{}{}'.format(hass.config.api.base_url, AUTH_CALLBACK_PATH)
          cache = config.get(CONF_CACHE_PATH, hass.config.path(DEFAULT_CACHE_PATH))
      
          trakt.core.CONFIG_PATH = cache
          #Tried both OAuth & Device Auth
          trakt.core.AUTH_METHOD = trakt.core.DEVICE_AUTH
          trakt.core.REDIRECT_URI = callback_url
      
          oauth = trakt.init('CaffeinatedMike', 
              client_id=config.get(CONF_CLIENT_ID),
              client_secret=config.get(CONF_CLIENT_SECRET))
      
      

    So, my first problem is being able to handle the oauth (redirecting the user when inside Home Assistant, having them approve the app, then return them to the redirect uri). I figured the best option would be to have the component show up under the Configure Section in the Configuration setting area, but I believe I read something saying that only certain components are allowed to be placed there.

  2. My other issue is more so just general confusion on a few things

    • Which kind of component should I make this?
    • How should I display the shows/customize how the component will look on the frontend?

I’ve been trying to make sense of some the stuff mentioned in the developer docs, but a lot of is very confusing or over-explained in technical terms for me to fully grasp.

Did you check out this custom-component?
Maybe it steers you to the right direction.

1 Like

I haven’t come across that component! Thank you for pointing it out to me :slight_smile: After all my searching I’m surprised I haven’t stumbled upon it myself :persevere:

Yeah, I just stumbled upon it last week or so.
I like your idead with the mark as watched. One way to display the upcoming media is using the upcoming media card.

That’s exactly what I had in mind. Except, that component states it only works with Sonarr & Radarr right now, not Trakt. I’ll have a look at it to see if I can implement trakt integration as well.

Edit: Oh, and I just now saw that that custom component relies on the user using lovelace, which I’m currently not and don’t plan on.

Sadly i can’t help you, but i got VIP on Trakt, and have been using it for the last 2-3 years, so hope you get this working.
And thanks in advance for the time you spend on it, however the outcome. :slight_smile:

I’m currently working on implementing this service into a component. Here’s my progress so far.

It’s still very early on in development, but I do have the shows display “Airing Now” if the show’s start_time (plus 45 minutes) is past the current time. The reason I selected 45 minutes is to split the difference between shows that are 30 minute episodes (cartoons) & shows that are 1 hour episodes (dramas). I’m still working on getting the component to fire events :slight_smile:

nice! i’m working on incorporating trakt too - but from another scope - watchlist / watched for now. am using appdaemon and lovelace for it though.