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:
- Having a List of New Episodes that are airing today on their dashboard
- 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.
-
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.
-
-
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.