Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
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
1 change: 1 addition & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,7 @@ omit =
homeassistant/components/media_player/frontier_silicon.py
homeassistant/components/media_player/gpmdp.py
homeassistant/components/media_player/gstreamer.py
homeassistant/components/media_player/harman_kardon_avr.py
homeassistant/components/media_player/horizon.py
homeassistant/components/media_player/itunes.py
homeassistant/components/media_player/kodi.py
Expand Down
127 changes: 127 additions & 0 deletions homeassistant/components/media_player/harman_kardon_avr.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
"""
Support for interface with an Harman/Kardon or JBL AVR.

For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/media_player.harman_kardon_avr/
"""
import logging
import voluptuous as vol
Comment thread
Devqon marked this conversation as resolved.

import homeassistant.helpers.config_validation as cv
from homeassistant.components.media_player import (
Comment thread
Devqon marked this conversation as resolved.
SUPPORT_TURN_OFF, SUPPORT_VOLUME_MUTE, SUPPORT_VOLUME_STEP,
PLATFORM_SCHEMA, SUPPORT_TURN_ON, SUPPORT_SELECT_SOURCE,
MediaPlayerDevice)
from homeassistant.const import (
Comment thread
Devqon marked this conversation as resolved.
CONF_HOST, CONF_NAME, CONF_PORT, STATE_OFF, STATE_ON)

REQUIREMENTS = ['hkavr==0.0.3']

_LOGGER = logging.getLogger(__name__)

DEFAULT_NAME = 'Harman Kardon AVR'
DEFAULT_PORT = 10025

SUPPORT_HARMAN_KARDON_AVR = SUPPORT_VOLUME_STEP | SUPPORT_VOLUME_MUTE | \
SUPPORT_TURN_OFF | SUPPORT_TURN_ON | \
SUPPORT_SELECT_SOURCE

SOURCES = ["Disc", "STB", "Cable Sat", "Media Server", "DVR", "Radio", "TV",
Comment thread
Devqon marked this conversation as resolved.
Outdated
"USB", "Game", "Home Network", "AUX"]

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Required(CONF_HOST): cv.string,
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port,
})


def setup_platform(hass, config, add_devices, discover_info=None):
Comment thread
Devqon marked this conversation as resolved.
Outdated
"""Set up the AVR platform."""
import hkavr

name = config.get(CONF_NAME)
Comment thread
Devqon marked this conversation as resolved.
Outdated
host = config.get(CONF_HOST)
port = config.get(CONF_PORT)

avr = hkavr.HkAVR(host, port, name)

avr_device = HkAvrDevice(avr)
if avr_device is None:
Comment thread
Devqon marked this conversation as resolved.
Outdated
_LOGGER.warning("Could not connect to AVR")
return False
Comment thread
Devqon marked this conversation as resolved.
Outdated
add_devices([avr_device], True)
Comment thread
Devqon marked this conversation as resolved.
Outdated


class HkAvrDevice(MediaPlayerDevice):
"""Representation of a Harman Kardon AVR / JBL AVR TV."""

def __init__(self, avr):
"""Initialize a new HarmanKardonAVR."""
self._avr = avr
self._name = avr.name
self._host = avr.host
self._port = avr.port

self._state = avr.state
Comment thread
Devqon marked this conversation as resolved.
Outdated
self._power = avr.power
self._muted = self._avr.muted
self._source_list = SOURCES

def update(self):
"""Update the state of this media_player."""
self._avr.update()
self._power = self._avr.power
self._state = self._avr.state
self._muted = self._avr.muted

@property
def name(self):
"""Return the name of the device."""
return self._name

@property
def state(self):
"""Return the state of the device."""
return self._state

@property
def is_volume_muted(self):
"""Muted status not available."""
return self._muted

@property
def source_list(self):
"""Available sources."""
return self._source_list

@property
def supported_features(self):
"""Flag media player features that are supported."""
return SUPPORT_HARMAN_KARDON_AVR

def turn_on(self):
"""Turn the AVR on."""
if self._avr.power_on():
self._state = STATE_ON
Comment thread
Devqon marked this conversation as resolved.
Outdated

def turn_off(self):
"""Turn off the AVR."""
if self._avr.power_off():
self._state = STATE_OFF
Comment thread
Devqon marked this conversation as resolved.
Outdated

def select_source(self, source):
"""Select input source."""
return self._avr.select_source(source)

def volume_up(self):
"""Volume up the AVR."""
return self._avr.volume_up()

def volume_down(self):
"""Volume down AVR."""
return self._avr.volume_down()

def mute_volume(self, mute):
"""Send mute command."""
return self._avr.mute(mute)
3 changes: 3 additions & 0 deletions requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,9 @@ hikvision==0.4
# homeassistant.components.notify.hipchat
hipnotify==1.0.8

# homeassistant.components.media_player.harman_kardon_avr
hkavr==0.0.3

# homeassistant.components.sensor.pi_hole
hole==0.3.0

Expand Down