-
-
Notifications
You must be signed in to change notification settings - Fork 37.5k
Add Ombi integration #26755
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Add Ombi integration #26755
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
17a2a41
Add Ombi integration
37e19f2
Black
7072f5c
Remove trailing comma
56ee0ed
Change dict.get to dict[key] for known keys
9fce49e
Remove monitored conditions from config
ffa27ac
Define SCAN_INTERVAL for default scan interval
9a9668d
Adjust requests syntax and add music_requests
a87f473
Remove Ombi object initialization
a9dd25d
Move constants to const.py
e4f9fab
Fix imports
1c2df49
Set pyombi requirement to version 0.1.3
1c1ba5c
Add services.yaml
0dbe480
Add config schema and setup for integration
458db12
Set pyombi requirement to version 0.1.3
3e75ac1
Fix syntax for scan interval
0da03f2
Fix datetime import
41b64a8
Add all files from ombi component
dbaf247
Move imports around
856c3d9
Move imports around
e085f77
Move pyombi import to top of module
55281a9
Move scan_interval to sensor module
258f6dc
Add custom validator for urlbase
7cc2ae6
Add guard clause for discovery_info
3f825d5
Add service validation schemas and constants
fa05b6f
Bump pyombi version
de75d7a
Adjust urlbase validation
32f4710
Add exception warnings for irretrievable media
c7de8fe
Bump pyombi
6af3d4c
Change from .get to dict[key]
8fb96a2
Change schema and conf variable names
bed2108
Set return to return false
4e6c85a
Remove unneeded return
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,149 @@ | ||
| """Support for Ombi.""" | ||
| import logging | ||
|
|
||
| import pyombi | ||
| import voluptuous as vol | ||
|
|
||
| from homeassistant.const import ( | ||
| CONF_API_KEY, | ||
| CONF_HOST, | ||
| CONF_PORT, | ||
| CONF_SSL, | ||
| CONF_USERNAME, | ||
| ) | ||
| import homeassistant.helpers.config_validation as cv | ||
|
|
||
| from .const import ( | ||
| ATTR_NAME, | ||
| ATTR_SEASON, | ||
| CONF_URLBASE, | ||
| DEFAULT_PORT, | ||
| DEFAULT_SEASON, | ||
| DEFAULT_SSL, | ||
| DEFAULT_URLBASE, | ||
| DOMAIN, | ||
| SERVICE_MOVIE_REQUEST, | ||
| SERVICE_MUSIC_REQUEST, | ||
| SERVICE_TV_REQUEST, | ||
| ) | ||
|
|
||
| _LOGGER = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| def urlbase(value) -> str: | ||
| """Validate and transform urlbase.""" | ||
| if value is None: | ||
| raise vol.Invalid("string value is None") | ||
| value = str(value).strip("/") | ||
| if not value: | ||
| return value | ||
| return value + "/" | ||
|
|
||
|
|
||
| SUBMIT_MOVIE_REQUEST_SERVICE_SCHEMA = vol.Schema({vol.Required(ATTR_NAME): cv.string}) | ||
|
|
||
| SUBMIT_MUSIC_REQUEST_SERVICE_SCHEMA = vol.Schema({vol.Required(ATTR_NAME): cv.string}) | ||
|
|
||
| SUBMIT_TV_REQUEST_SERVICE_SCHEMA = vol.Schema( | ||
| { | ||
| vol.Required(ATTR_NAME): cv.string, | ||
| vol.Optional(ATTR_SEASON, default=DEFAULT_SEASON): vol.In( | ||
| ["first", "latest", "all"] | ||
| ), | ||
| } | ||
| ) | ||
|
|
||
| CONFIG_SCHEMA = vol.Schema( | ||
| { | ||
| DOMAIN: vol.Schema( | ||
| { | ||
| vol.Required(CONF_API_KEY): cv.string, | ||
| vol.Required(CONF_HOST): cv.string, | ||
| vol.Required(CONF_USERNAME): cv.string, | ||
| vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port, | ||
| vol.Optional(CONF_URLBASE, default=DEFAULT_URLBASE): urlbase, | ||
| vol.Optional(CONF_SSL, default=DEFAULT_SSL): cv.boolean, | ||
| } | ||
| ) | ||
| }, | ||
| extra=vol.ALLOW_EXTRA, | ||
| ) | ||
|
|
||
|
|
||
| def setup(hass, config): | ||
| """Set up the Ombi component platform.""" | ||
|
|
||
| ombi = pyombi.Ombi( | ||
| ssl=config[DOMAIN][CONF_SSL], | ||
| host=config[DOMAIN][CONF_HOST], | ||
| port=config[DOMAIN][CONF_PORT], | ||
| api_key=config[DOMAIN][CONF_API_KEY], | ||
| username=config[DOMAIN][CONF_USERNAME], | ||
| urlbase=config[DOMAIN][CONF_URLBASE], | ||
| ) | ||
|
|
||
| try: | ||
| ombi.test_connection() | ||
| except pyombi.OmbiError as err: | ||
| _LOGGER.warning("Unable to setup Ombi: %s", err) | ||
| return False | ||
|
|
||
| hass.data[DOMAIN] = {"instance": ombi} | ||
|
|
||
| def submit_movie_request(call): | ||
| """Submit request for movie.""" | ||
| name = call.data[ATTR_NAME] | ||
| movies = ombi.search_movie(name) | ||
| if movies: | ||
| movie = movies[0] | ||
| ombi.request_movie(movie["theMovieDbId"]) | ||
| else: | ||
| raise Warning("No movie found.") | ||
|
|
||
| def submit_tv_request(call): | ||
| """Submit request for TV show.""" | ||
| name = call.data[ATTR_NAME] | ||
| tv_shows = ombi.search_tv(name) | ||
|
|
||
| if tv_shows: | ||
| season = call.data[ATTR_SEASON] | ||
| show = tv_shows[0]["id"] | ||
| if season == "first": | ||
| ombi.request_tv(show, request_first=True) | ||
| elif season == "latest": | ||
| ombi.request_tv(show, request_latest=True) | ||
| elif season == "all": | ||
| ombi.request_tv(show, request_all=True) | ||
| else: | ||
| raise Warning("No TV show found.") | ||
|
|
||
| def submit_music_request(call): | ||
| """Submit request for music album.""" | ||
| name = call.data[ATTR_NAME] | ||
| music = ombi.search_music_album(name) | ||
| if music: | ||
| ombi.request_music(music[0]["foreignAlbumId"]) | ||
| else: | ||
| raise Warning("No music album found.") | ||
|
|
||
| hass.services.register( | ||
| DOMAIN, | ||
| SERVICE_MOVIE_REQUEST, | ||
| submit_movie_request, | ||
| schema=SUBMIT_MOVIE_REQUEST_SERVICE_SCHEMA, | ||
| ) | ||
| hass.services.register( | ||
| DOMAIN, | ||
| SERVICE_MUSIC_REQUEST, | ||
| submit_music_request, | ||
| schema=SUBMIT_MUSIC_REQUEST_SERVICE_SCHEMA, | ||
| ) | ||
| hass.services.register( | ||
| DOMAIN, | ||
| SERVICE_TV_REQUEST, | ||
| submit_tv_request, | ||
| schema=SUBMIT_TV_REQUEST_SERVICE_SCHEMA, | ||
| ) | ||
| hass.helpers.discovery.load_platform("sensor", DOMAIN, {}, config) | ||
|
|
||
| return True |
This file contains hidden or 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 @@ | ||
| """Support for Ombi.""" | ||
| ATTR_NAME = "name" | ||
| ATTR_SEASON = "season" | ||
|
|
||
| CONF_URLBASE = "urlbase" | ||
|
|
||
| DEFAULT_NAME = DOMAIN = "ombi" | ||
| DEFAULT_PORT = 5000 | ||
| DEFAULT_SEASON = "latest" | ||
| DEFAULT_SSL = False | ||
| DEFAULT_URLBASE = "" | ||
|
|
||
| SERVICE_MOVIE_REQUEST = "submit_movie_request" | ||
| SERVICE_MUSIC_REQUEST = "submit_music_request" | ||
| SERVICE_TV_REQUEST = "submit_tv_request" | ||
|
|
||
| SENSOR_TYPES = { | ||
| "movies": {"type": "Movie requests", "icon": "mdi:movie"}, | ||
| "tv": {"type": "TV show requests", "icon": "mdi:television-classic"}, | ||
| "music": {"type": "Music album requests", "icon": "mdi:album"}, | ||
| "pending": {"type": "Pending requests", "icon": "mdi:clock-alert-outline"}, | ||
| "approved": {"type": "Approved requests", "icon": "mdi:check"}, | ||
| "available": {"type": "Available requests", "icon": "mdi:download"}, | ||
| } |
This file contains hidden or 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,8 @@ | ||
| { | ||
| "domain": "ombi", | ||
| "name": "Ombi", | ||
| "documentation": "https://www.home-assistant.io/components/ombi/", | ||
| "dependencies": [], | ||
| "codeowners": ["@larssont"], | ||
| "requirements": ["pyombi==0.1.5"] | ||
| } |
This file contains hidden or 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,77 @@ | ||
| """Support for Ombi.""" | ||
| from datetime import timedelta | ||
| import logging | ||
|
|
||
| from pyombi import OmbiError | ||
|
|
||
| from homeassistant.helpers.entity import Entity | ||
|
|
||
| from .const import DOMAIN, SENSOR_TYPES | ||
|
|
||
| _LOGGER = logging.getLogger(__name__) | ||
|
|
||
| SCAN_INTERVAL = timedelta(seconds=60) | ||
|
|
||
|
|
||
| def setup_platform(hass, config, add_entities, discovery_info=None): | ||
| """Set up the Ombi sensor platform.""" | ||
| if discovery_info is None: | ||
| return | ||
|
|
||
| sensors = [] | ||
|
|
||
| ombi = hass.data[DOMAIN]["instance"] | ||
|
|
||
| for sensor in SENSOR_TYPES: | ||
| sensor_label = sensor | ||
| sensor_type = SENSOR_TYPES[sensor]["type"] | ||
| sensor_icon = SENSOR_TYPES[sensor]["icon"] | ||
| sensors.append(OmbiSensor(sensor_label, sensor_type, ombi, sensor_icon)) | ||
|
|
||
| add_entities(sensors, True) | ||
|
|
||
|
|
||
| class OmbiSensor(Entity): | ||
| """Representation of an Ombi sensor.""" | ||
|
|
||
| def __init__(self, label, sensor_type, ombi, icon): | ||
| """Initialize the sensor.""" | ||
| self._state = None | ||
| self._label = label | ||
| self._type = sensor_type | ||
| self._ombi = ombi | ||
| self._icon = icon | ||
|
|
||
| @property | ||
| def name(self): | ||
| """Return the name of the sensor.""" | ||
| return f"Ombi {self._type}" | ||
|
|
||
| @property | ||
| def icon(self): | ||
| """Return the icon to use in the frontend.""" | ||
| return self._icon | ||
|
|
||
| @property | ||
| def state(self): | ||
| """Return the state of the sensor.""" | ||
| return self._state | ||
|
|
||
| def update(self): | ||
| """Update the sensor.""" | ||
| try: | ||
| if self._label == "movies": | ||
| self._state = self._ombi.movie_requests | ||
| elif self._label == "tv": | ||
| self._state = self._ombi.tv_requests | ||
| elif self._label == "music": | ||
| self._state = self._ombi.music_requests | ||
| elif self._label == "pending": | ||
| self._state = self._ombi.total_requests["pending"] | ||
| elif self._label == "approved": | ||
| self._state = self._ombi.total_requests["approved"] | ||
| elif self._label == "available": | ||
| self._state = self._ombi.total_requests["available"] | ||
| except OmbiError as err: | ||
| _LOGGER.warning("Unable to update Ombi sensor: %s", err) | ||
| self._state = None | ||
This file contains hidden or 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,27 @@ | ||
| # Ombi services.yaml entries | ||
|
|
||
| submit_movie_request: | ||
| description: Searches for a movie and requests the first result. | ||
| fields: | ||
| name: | ||
| description: Search parameter | ||
| example: "beverly hills cop" | ||
|
|
||
|
|
||
| submit_tv_request: | ||
| description: Searches for a TV show and requests the first result. | ||
| fields: | ||
| name: | ||
| description: Search parameter | ||
| example: "breaking bad" | ||
| season: | ||
| description: Which season(s) to request (first, latest or all) | ||
| example: "latest" | ||
|
|
||
|
|
||
| submit_music_request: | ||
| description: Searches for a music album and requests the first result. | ||
| fields: | ||
| name: | ||
| description: Search parameter | ||
| example: "nevermind" |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.