-
-
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
Changes from 2 commits
ee07d98
6d5dcfa
5fe3ee1
d60650c
c2b59ca
dedf64c
e855c25
45ad540
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,8 @@ | |
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 | ||
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,14 @@ | |
|
||
TIMEOUT_MESSAGE = 'Timeout waiting for response.' | ||
|
||
ATTR_VIDEO_OUTPUT = 'video_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, | ||
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. line too long (85 > 79 characters) |
||
vol.Required(ATTR_VIDEO_OUTPUT): vol.In(ACCEPTED_VALUES)}) | ||
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. line too long (99 > 79 characters) |
||
DOMAIN = 'media_player' | ||
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. import domain. |
||
SERVICE_SELECT_VIDEO_OUTPUT = 'select_video_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. prefix with platform name. |
||
|
||
|
||
def determine_zones(receiver): | ||
"""Determine what zones are available for the receiver.""" | ||
|
@@ -90,6 +99,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_VIDEO_OUTPUT: | ||
device.select_output(service.data.get(ATTR_VIDEO_OUTPUT)) | ||
|
||
hass.services.register( | ||
DOMAIN, SERVICE_SELECT_VIDEO_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 +166,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 +197,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 +218,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 +255,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 +305,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 +380,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.""" | ||
|
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).