-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Trakt component with config flow support (#33)
* Update Trakt integration to use config flow * update when options change * add hacs.json
- Loading branch information
Showing
8 changed files
with
457 additions
and
209 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"config": { | ||
"step": { | ||
"pick_implementation": { "title": "Pick Authentication Method" } | ||
}, | ||
"abort": { | ||
"already_setup": "You can only configure one Trakt instance.", | ||
"authorize_url_timeout": "Timeout generating authorize url.", | ||
"missing_configuration": "The Trakt integration is not configured. Please follow the documentation." | ||
}, | ||
"create_entry": { "default": "Successfully authenticated with Trakt." } | ||
}, | ||
"options": { | ||
"step": { | ||
"init": { | ||
"data": { | ||
"scan_interval": "Update frequency (minutes)", | ||
"days": "Days to look forward for movies/shows", | ||
"exclude": "list of excluded shows (comma separated)" | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
"""Config flow for Trakt.""" | ||
import logging | ||
import voluptuous as vol | ||
|
||
from homeassistant import config_entries | ||
from homeassistant.const import CONF_EXCLUDE, CONF_SCAN_INTERVAL | ||
from homeassistant.core import callback | ||
from homeassistant.helpers import config_entry_oauth2_flow | ||
from .const import CONF_DAYS, DEFAULT_DAYS, DEFAULT_SCAN_INTERVAL, DOMAIN | ||
|
||
|
||
class TraktOAuth2FlowHandler( | ||
config_entry_oauth2_flow.AbstractOAuth2FlowHandler, domain=DOMAIN | ||
): | ||
"""Handle a Trakt config flow.""" | ||
|
||
DOMAIN = DOMAIN | ||
CONNECTION_CLASS = config_entries.CONN_CLASS_LOCAL_POLL | ||
|
||
@property | ||
def logger(self) -> logging.Logger: | ||
"""Return logger.""" | ||
return logging.getLogger(__name__) | ||
|
||
@staticmethod | ||
@callback | ||
def async_get_options_flow(config_entry): | ||
"""Get the options flow for this handler.""" | ||
return TraktOptionsFlowHandler(config_entry) | ||
|
||
|
||
class TraktOptionsFlowHandler(config_entries.OptionsFlow): | ||
"""Handle Trakt options.""" | ||
|
||
def __init__(self, config_entry): | ||
"""Initialize Trakt options flow.""" | ||
self.config_entry = config_entry | ||
|
||
async def async_step_init(self, user_input=None): | ||
"""Manage the Trakt options.""" | ||
if user_input is not None: | ||
user_input[CONF_EXCLUDE] = user_input[CONF_EXCLUDE].split(",") | ||
return self.async_create_entry(title="", data=user_input) | ||
|
||
options = { | ||
vol.Optional( | ||
CONF_SCAN_INTERVAL, | ||
default=self.config_entry.options.get( | ||
CONF_SCAN_INTERVAL, DEFAULT_SCAN_INTERVAL | ||
), | ||
): int, | ||
vol.Optional( | ||
CONF_DAYS, | ||
default=self.config_entry.options.get(CONF_DAYS, DEFAULT_DAYS), | ||
): int, | ||
vol.Optional( | ||
CONF_EXCLUDE, default=self.config_entry.options.get(CONF_EXCLUDE, None), | ||
): str, | ||
} | ||
|
||
return self.async_show_form(step_id="init", data_schema=vol.Schema(options)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
"""Constants used in the Trakt integration.""" | ||
DOMAIN = "trakt" | ||
|
||
OAUTH2_AUTHORIZE = "https://api-v2launch.trakt.tv/oauth/authorize" | ||
OAUTH2_TOKEN = "https://api-v2launch.trakt.tv/oauth/token" | ||
|
||
ATTRIBUTION = "Data provided by trakt.tv" | ||
|
||
CONF_DAYS = "days" | ||
CONF_EXCLUDE = "exclude" | ||
|
||
DATA_UPDATED = "trakt_data_updated" | ||
DATA_TRAKT_CRED = "trakt_credentials" | ||
|
||
DEFAULT_DAYS = 30 | ||
DEFAULT_SCAN_INTERVAL = 60 | ||
DEFAULT_NAME = "Trakt Upcoming Calendar" | ||
|
||
CARD_DEFAULT = { | ||
"title_default": "$title", | ||
"line1_default": "$episode", | ||
"line2_default": "$release", | ||
"line3_default": "$rating - $runtime", | ||
"line4_default": "$number - $studio", | ||
"icon": "mdi:arrow-down-bold", | ||
} |
Oops, something went wrong.