Skip to content

Commit

Permalink
✨ ability to exclude show titles (#13)
Browse files Browse the repository at this point in the history
* ✨ ability to exclude show titles

* Specify show year to avoid duplicates
  • Loading branch information
iantrich authored Jan 6, 2019
1 parent 08a0bb3 commit 859ed37
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
21 changes: 12 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![Version](https://img.shields.io/badge/version-0.0.5-green.svg?style=for-the-badge)](#) [![mantained](https://img.shields.io/maintenance/yes/2018.svg?style=for-the-badge)](#)
[![Version](https://img.shields.io/badge/version-0.0.6-green.svg?style=for-the-badge)](#) [![mantained](https://img.shields.io/maintenance/yes/2018.svg?style=for-the-badge)](#)

[![maintainer](https://img.shields.io/badge/maintainer-Ian%20Richardson%20%40iantrich-blue.svg?style=for-the-badge)](#)

Expand Down Expand Up @@ -30,18 +30,21 @@ sensor:
secret: 'sdfoiwahjeflkaswjefi83q7829045uoijksldf'
username: iantrich
days: 10
exclude:
'The Bachelor'
```
**Configuration variables:**
key | description
:--- | :---
**platform (Required)** | `trakt`
**id (Required)** | Client ID (create new app at https://trakt.tv/oauth/applications)
**secret (Required)** | Client Secret (create new app at https://trakt.tv/oauth/applications)
**username (Required)** | trakt.tv username
**days (Optional)** | How many days to look forward for movies/shows. Default `30`
**name (Optional)** | Sensor name. Default `Trakt Upcoming Calendar`
key | type | description
:--- | :--- | :---
**platform (Required)** | string | `trakt`
**id (Required)** | sring | Client ID (create new app at https://trakt.tv/oauth/applications)
**secret (Required)** | string | Client Secret (create new app at https://trakt.tv/oauth/applications)
**username (Required)** | string | trakt.tv username
**days (Optional)** | number | How many days to look forward for movies/shows. Default `30`
**name (Optional)** | string | Sensor name. Default `Trakt Upcoming Calendar`
**exclude (Optional)** | array | List of show titles to exclude as Trakt does not allow removal of shows from its service

***

Expand Down
15 changes: 10 additions & 5 deletions custom_components/sensor/trakt.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,31 @@
from homeassistant.components.sensor import PLATFORM_SCHEMA
from homeassistant.helpers.entity import Entity

__version__ = '0.0.5'
__version__ = '0.0.6'

REQUIREMENTS = ['trakt==2.8.2', 'requests_oauthlib==1.0.0']

BASE_URL = 'https://api-v2launch.trakt.tv/'
CONF_CLIENT_ID = 'id'
CONF_CLIENT_SECRET = 'secret'
CONF_USERNAME = 'username'
CONF_DAYS = 'days'
CONF_EXCLUDE = 'exclude'
CONF_NAME = 'name'
CONF_USERNAME = 'username'
DATA_UPCOMING = 'trakt_upcoming'
REDIRECT_URI = 'urn:ietf:wg:oauth:2.0:oob'
SCAN_INTERVAL = timedelta(minutes=30)
TOKEN_FILE = '.trakt.conf'

LIST_SCHEMA = vol.Schema([str])

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Required(CONF_CLIENT_ID): cv.string,
vol.Required(CONF_CLIENT_SECRET): cv.string,
vol.Required(CONF_USERNAME): cv.string,
vol.Optional(CONF_DAYS, default=30): cv.positive_int,
vol.Optional(CONF_NAME, default='Trakt Upcoming Calendar'): cv.string,
vol.Optional(CONF_EXCLUDE, default=[]): LIST_SCHEMA,
})

_CONFIGURING = {}
Expand Down Expand Up @@ -126,6 +130,7 @@ def __init__(self, hass, config, token):
self._state = None
self._hass.data[DATA_UPCOMING] = {}
self._name = config[CONF_NAME]
self._exclude = config[CONF_EXCLUDE]
self.update()

def update(self):
Expand All @@ -152,11 +157,11 @@ def update(self):
self._state = len(calendar)

for show in calendar:
if not show:
if not show or show.show in self._exclude:
continue

try:
show_details = TVShow(show.show)
show_details = TVShow.search(show.show, show.year)
except AttributeError:
_LOGGER.error('Unable to retrieve show details for ' + show.show)

Expand All @@ -166,7 +171,7 @@ def update(self):
session = requests.Session()
try:
tmdb_url = session.get('http://api.tmdb.org/3/tv/{}?api_key=0eee347e2333d7a97b724106353ca42f'.format(
str(show_details.tmdb)))
str(show_details[0].tmdb)))
tmdb_json = tmdb_url.json()
except requests.exceptions.RequestException as e:
_LOGGER.warning('api.themoviedb.org is not responding')
Expand Down

0 comments on commit 859ed37

Please sign in to comment.