Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion homeassistant/components/media_player/onkyo.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
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
Comment thread
leothlon marked this conversation as resolved.
Outdated
import homeassistant.helpers.config_validation as cv

REQUIREMENTS = ['onkyo-eiscp==1.2.4']
Expand Down Expand Up @@ -55,6 +55,10 @@

TIMEOUT_MESSAGE = 'Timeout waiting for response.'

ATTR_VIDEO_OUTPUT = 'video_output'
ONKYO_SELECT_OUTPUT_SCHEMA = vol.Schema({vol.Required(ATTR_ENTITY_ID): cv.entity_ids, vol.Required(ATTR_VIDEO_OUTPUT): vol.In(['no', 'analog', 'yes', 'out', 'out-sub', 'sub', 'hdbaset', 'both', 'up'])})

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (202 > 79 characters)

DOMAIN = 'media_player'

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import domain.

SERVICE_SELECT_VIDEO_OUTPUT = 'select_video_output'

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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."""
Expand Down Expand Up @@ -90,6 +94,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]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

blank line contains whitespace

for device in devices:
if service.service == SERVICE_SELECT_VIDEO_OUTPUT:
device.select_output(service.data.get(ATTR_VIDEO_OUTPUT))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

blank line contains whitespace

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)
Expand Down Expand Up @@ -144,6 +161,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."""
Expand Down Expand Up @@ -174,6 +192,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
Expand All @@ -194,6 +213,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):
Expand Down Expand Up @@ -230,6 +250,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')
Expand Down Expand Up @@ -276,6 +301,10 @@ def play_media(self, media_type, media_id, **kwargs):
self.command('preset {}'.format(media_id))


def select_output(self, output):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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."""

Expand Down