-
-
Notifications
You must be signed in to change notification settings - Fork 28.4k
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
Added service select_video_output and video_out attribute #18081
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ee07d98
Added service select_video_output and video_out attribute
leothlon 6d5dcfa
Fixed white lines and long lines
leothlon 5fe3ee1
Made line shorter
leothlon d60650c
Added period to comment according to flake8 rules
leothlon c2b59ca
Imported domain const
leothlon dedf64c
Prefixed service with platform name
leothlon e855c25
changed "video output" to "hdmi output" to better reflect eiscp cammand
leothlon 45ad540
video_output to hdmi_output rename
leothlon File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 |
---|---|---|
|
@@ -14,8 +14,9 @@ | |
from homeassistant.components.media_player import ( | ||
PLATFORM_SCHEMA, SUPPORT_PLAY, SUPPORT_PLAY_MEDIA, SUPPORT_SELECT_SOURCE, | ||
SUPPORT_TURN_OFF, SUPPORT_TURN_ON, SUPPORT_VOLUME_MUTE, SUPPORT_VOLUME_SET, | ||
SUPPORT_VOLUME_STEP, MediaPlayerDevice) | ||
from homeassistant.const import CONF_HOST, CONF_NAME, STATE_OFF, STATE_ON | ||
SUPPORT_VOLUME_STEP, MediaPlayerDevice, DOMAIN) | ||
from homeassistant.const import ( | ||
CONF_HOST, CONF_NAME, STATE_OFF, STATE_ON, ATTR_ENTITY_ID) | ||
import homeassistant.helpers.config_validation as cv | ||
|
||
REQUIREMENTS = ['onkyo-eiscp==1.2.4'] | ||
|
@@ -55,6 +56,16 @@ | |
|
||
TIMEOUT_MESSAGE = 'Timeout waiting for response.' | ||
|
||
ATTR_HDMI_OUTPUT = 'hdmi_output' | ||
ACCEPTED_VALUES = ['no', 'analog', 'yes', 'out', | ||
'out-sub', 'sub', 'hdbaset', 'both', 'up'] | ||
ONKYO_SELECT_OUTPUT_SCHEMA = vol.Schema({ | ||
vol.Required(ATTR_ENTITY_ID): cv.entity_ids, | ||
vol.Required(ATTR_HDMI_OUTPUT): vol.In(ACCEPTED_VALUES) | ||
}) | ||
|
||
SERVICE_SELECT_HDMI_OUTPUT = 'onkyo_select_hdmi_output' | ||
|
||
|
||
def determine_zones(receiver): | ||
"""Determine what zones are available for the receiver.""" | ||
|
@@ -90,6 +101,19 @@ def setup_platform(hass, config, add_entities, discovery_info=None): | |
host = config.get(CONF_HOST) | ||
hosts = [] | ||
|
||
def service_handle(service): | ||
"""Handle for services.""" | ||
entity_ids = service.data.get(ATTR_ENTITY_ID) | ||
devices = [d for d in hosts if d.entity_id in entity_ids] | ||
|
||
for device in devices: | ||
if service.service == SERVICE_SELECT_HDMI_OUTPUT: | ||
device.select_output(service.data.get(ATTR_HDMI_OUTPUT)) | ||
|
||
hass.services.register( | ||
DOMAIN, SERVICE_SELECT_HDMI_OUTPUT, service_handle, | ||
schema=ONKYO_SELECT_OUTPUT_SCHEMA) | ||
|
||
if CONF_HOST in config and host not in KNOWN_HOSTS: | ||
try: | ||
receiver = eiscp.eISCP(host) | ||
|
@@ -144,6 +168,7 @@ def __init__(self, receiver, sources, name=None, | |
self._source_list = list(sources.values()) | ||
self._source_mapping = sources | ||
self._reverse_mapping = {value: key for key, value in sources.items()} | ||
self._attributes = {} | ||
|
||
def command(self, command): | ||
"""Run an eiscp command and catch connection errors.""" | ||
|
@@ -174,6 +199,7 @@ def update(self): | |
volume_raw = self.command('volume query') | ||
mute_raw = self.command('audio-muting query') | ||
current_source_raw = self.command('input-selector query') | ||
hdmi_out_raw = self.command('hdmi-output-selector query') | ||
|
||
if not (volume_raw and mute_raw and current_source_raw): | ||
return | ||
|
@@ -194,6 +220,7 @@ def update(self): | |
[i for i in current_source_tuples[1]]) | ||
self._muted = bool(mute_raw[1] == 'on') | ||
self._volume = volume_raw[1] / self._max_volume | ||
self._attributes["video_out"] = ','.join(hdmi_out_raw[1]) | ||
|
||
@property | ||
def name(self): | ||
|
@@ -230,6 +257,11 @@ def source_list(self): | |
"""List of available input sources.""" | ||
return self._source_list | ||
|
||
@property | ||
def device_state_attributes(self): | ||
"""Return device specific state attributes.""" | ||
return self._attributes | ||
|
||
def turn_off(self): | ||
"""Turn the media player off.""" | ||
self.command('system-power standby') | ||
|
@@ -275,6 +307,10 @@ def play_media(self, media_type, media_id, **kwargs): | |
source in DEFAULT_PLAYABLE_SOURCES): | ||
self.command('preset {}'.format(media_id)) | ||
|
||
def select_output(self, output): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. too many blank lines (2) |
||
"""Set hdmi-out.""" | ||
self.command('hdmi-output-selector={}'.format(output)) | ||
|
||
|
||
class OnkyoDeviceZone(OnkyoDevice): | ||
"""Representation of an Onkyo device's extra zone.""" | ||
|
@@ -346,7 +382,7 @@ def turn_off(self): | |
|
||
def set_volume_level(self, volume): | ||
"""Set volume level, input is range 0..1. Onkyo ranges from 1-80.""" | ||
self.command('zone{}.volume={}'.format(self._zone, int(volume*80))) | ||
self.command('zone{}.volume={}'.format(self._zone, int(volume * 80))) | ||
|
||
def volume_up(self): | ||
"""Increase volume by 1 step.""" | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this valid for all onkyos?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those are the accepted values according to the onkyo-eiscp library, not all of them would work on all recievers i dont think (for me "out" switches to main and "out-sub" switches to sub, "sub" switches to both. so its not totally clear what to use but rather trial and error, planning to update this in the docs when i get time).
The command would only work for recievers with more than one hdmi-out port ofc.
Other than that i wouldn't really know as i only got one reciever to test with. (onkyo-eiscp said the command is for Japanese models but i got a European one and it works fine).