Add Radarr sensor#7318
Conversation
|
Hi @tboyce021, It seems you haven't yet signed a CLA. Please do so here. Once you do that we will be able to review and accept this pull request. Thanks! |
| def to_unit(value, unit): | ||
| """Convert bytes to give unit.""" | ||
| return value / 1024**BYTE_SIZES.index(unit) | ||
|
|
| def to_key(data): | ||
| return '{} ({})'.format(data['title'], data['year']) | ||
|
|
||
| def to_unit(value, unit): |
| date = data['inCinemas'] | ||
| return date | ||
|
|
||
| def to_key(data): |
| datetime.fromtimestamp(time.time() + day*offset, tz=zone) | ||
| ) | ||
|
|
||
| def get_release_date(data): |
| return datetime.date( | ||
| datetime.fromtimestamp(time.time() + day*offset, tz=zone) | ||
| ) | ||
|
|
| attributes[to_key(movie)] = movie['hasFile'] | ||
| elif self.type == 'status': | ||
| attributes = self.data | ||
|
|
| elif self.type == 'wanted': | ||
| self.data = list( | ||
| filter( | ||
| lambda x: x['downloaded'] == False, |
There was a problem hiding this comment.
comparison to False should be 'if cond is False:' or 'if not cond:'
| if self.type == 'movies': | ||
| self.data = list( | ||
| filter( | ||
| lambda x: x['downloaded'] == True, |
There was a problem hiding this comment.
comparison to True should be 'if cond is True:' or 'if cond:'
|
NOTE: I have not tested this thoroughly yet (haven't tested |
| elif self.type == 'wanted': | ||
| self.data = list( | ||
| filter( | ||
| lambda x: not x['downloaded'], |
There was a problem hiding this comment.
Wasn't really sure what to do here. Radarr doesn't have a "wanted" API, so I just filtered movies based on whether they were downloaded or not.
There was a problem hiding this comment.
If Radarr doesn't support it, remove it.
| import homeassistant.helpers.config_validation as cv | ||
| from homeassistant.const import (CONF_API_KEY, CONF_HOST, CONF_PORT) | ||
| from homeassistant.const import CONF_MONITORED_CONDITIONS | ||
| from homeassistant.const import CONF_SSL |
There was a problem hiding this comment.
Merge all from homeassistant.const lines.
| PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ | ||
| vol.Required(CONF_API_KEY): cv.string, | ||
| vol.Required(CONF_MONITORED_CONDITIONS, default=[]): | ||
| vol.All(cv.ensure_list, [vol.In(list(SENSOR_TYPES.keys()))]), |
There was a problem hiding this comment.
.keys() is the default. Needs to be removed for pylint 1.7.1.
| self.port = conf.get(CONF_PORT) | ||
| self.urlbase = conf.get(CONF_URLBASE) | ||
| if self.urlbase: | ||
| self.urlbase = "%s/" % self.urlbase.strip('/') |
| elif self.type == 'wanted': | ||
| self.data = list( | ||
| filter( | ||
| lambda x: not x['downloaded'], |
There was a problem hiding this comment.
If Radarr doesn't support it, remove it.
| DEFAULT_URLBASE = '' | ||
| DEFAULT_DAYS = '1' | ||
| DEFAULT_UNIT = 'GB' | ||
|
|
There was a problem hiding this comment.
Add SCAN_INTERVAL. I think that's enough if this sensor is updated every 5 or 10 min per default.
| ENDPOINTS[self.type].format( | ||
| self.ssl, self.host, self.port, | ||
| self.urlbase, self.apikey, start, end), | ||
| timeout=5) |
There was a problem hiding this comment.
Honestly, I have no idea how to do this.. I wrote very little of this myself. It's almost all copied from the existing Sonarr sensor.
| ) | ||
| elif self.type == 'movies': | ||
| for movie in self.data: | ||
| attributes[to_key(movie)] = movie['downloaded'] |
There was a problem hiding this comment.
I also changed the attribute value to 'downloaded' instead of 'hasFile'. I honestly don't know which one is preferred. For me, they're always the same.
|
I'll work on getting tests next but it'll take me a day or two to get set up for that. |
|
Hello @tboyce021, When attempting to inspect the commits of your pull request for CLA signature status among all authors we encountered commit(s) which were not linked to a GitHub account, thus not allowing us to determine their status(es). The commits that are missing a linked GitHub account are the following:
Unfortunately, we are unable to accept this pull request until this situation is corrected. Here are your options:
We apologize for this inconvenience, especially since it usually bites new contributors to Home Assistant. We hope you understand the need for us to protect ourselves and the great community we all have built legally. The best thing to come out of this is that you only need to fix this once and it benefits the entire Home Assistant and GitHub community. Thanks, I look forward to checking this PR again soon! ❤️ |
There was a problem hiding this comment.
line too long (340 > 79 characters)
There was a problem hiding this comment.
line too long (163 > 79 characters)
There was a problem hiding this comment.
local variable 'today' is assigned to but never used
| self.assertEqual('Radarr Upcoming', device.name) | ||
| self.assertEqual( | ||
| '2017-01-27T00:00:00Z', | ||
| device.device_state_attributes["Resident Evil: The Final Chapter (2017)"] |
| self.assertEqual('Radarr Upcoming', device.name) | ||
| self.assertEqual( | ||
| '2017-01-27T00:00:00Z', | ||
| device.device_state_attributes["Resident Evil: The Final Chapter (2017)"] |
| { | ||
| "coverType": "banner", | ||
| "url": "/radarr/MediaCover/1/banner.jpg" | ||
| + "?lastWrite=636200219340000000" |
There was a problem hiding this comment.
continuation line unaligned for hanging indent
| { | ||
| "coverType": "banner", | ||
| "url": "/radarr/MediaCover/12/banner.jpg" | ||
| + "?lastWrite=636208663600000000" |
There was a problem hiding this comment.
continuation line unaligned for hanging indent
| """The tests for the radarr platform.""" | ||
| import unittest | ||
| import time | ||
| from datetime import datetime |
There was a problem hiding this comment.
'datetime.datetime' imported but unused
| @@ -0,0 +1,451 @@ | |||
| """The tests for the radarr platform.""" | |||
| import unittest | |||
| import time | |||
| { | ||
| "coverType": "banner", | ||
| "url": "/radarr/MediaCover/12/banner.jpg" | ||
| + "?lastWrite=636208663600000000" |
There was a problem hiding this comment.
continuation line unaligned for hanging indent
|
The tests were also mostly just copied from Sonarr, but with the data and stuff changed for Radarr. I'll work on getting the documentation up tomorrow. |
Description:
Adds a sensor component for Radarr.
Pull request in home-assistant.github.io with documentation (if applicable): home-assistant/home-assistant.io#2567
Example entry for
configuration.yaml(if applicable):Checklist:
If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
toxrun successfully. Your PR cannot be merged unless tests passREQUIREMENTSvariable (example).requirements_all.txtby runningscript/gen_requirements_all.py..coveragerc.If the code does not interact with devices:
toxrun successfully. Your PR cannot be merged unless tests pass