-
-
Notifications
You must be signed in to change notification settings - Fork 37.2k
Support for the Harman Kardon AVR #18471
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
MartinHjelmare
merged 15 commits into
home-assistant:dev
from
Devqon:mediaplayer_hk-avr
Dec 13, 2018
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
32a368b
Feature: support for the HK AVR
Devqon 0509cee
Remove testcode
Devqon 297526a
Feature: support for the HK AVR
Devqon ad7ad94
Remove testcode
Devqon 1425c20
Added checklist
Devqon e8aa47c
Review fixes whitespaces
Devqon 58ba32b
Lint fixes
Devqon eaf4119
Merge branch 'mediaplayer_hk-avr' of https://github.com/Devqon/home-a…
Devqon 9b7cd1a
Merge branch 'dev' into mediaplayer_hk-avr
Devqon c83a596
Review fixes, add current source
Devqon 1d5f2bf
Remove unused imports
Devqon 4d0c653
Review fixes; State constants, dict[key]
Devqon c392218
More review fixes, Unknown state and Sources
Devqon 0d854ed
Review fix; rename devices to entities
Devqon a0d24fc
Merge branch 'dev' of https://github.com/home-assistant/home-assistan…
Devqon 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
132 changes: 132 additions & 0 deletions
132
homeassistant/components/media_player/harman_kardon_avr.py
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,132 @@ | ||
| """ | ||
| 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 | ||
|
|
||
| import homeassistant.helpers.config_validation as cv | ||
| from homeassistant.components.media_player import ( | ||
Devqon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| SUPPORT_TURN_OFF, SUPPORT_VOLUME_MUTE, SUPPORT_VOLUME_STEP, | ||
| PLATFORM_SCHEMA, SUPPORT_TURN_ON, SUPPORT_SELECT_SOURCE, | ||
| MediaPlayerDevice) | ||
| from homeassistant.const import ( | ||
Devqon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| CONF_HOST, CONF_NAME, CONF_PORT, STATE_OFF, STATE_ON) | ||
|
|
||
| REQUIREMENTS = ['hkavr==0.0.5'] | ||
|
|
||
| _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 | ||
|
|
||
| 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_entities, discover_info=None): | ||
| """Set up the AVR platform.""" | ||
| import hkavr | ||
|
|
||
| name = config[CONF_NAME] | ||
| host = config[CONF_HOST] | ||
| port = config[CONF_PORT] | ||
|
|
||
| avr = hkavr.HkAVR(host, port, name) | ||
| avr_device = HkAvrDevice(avr) | ||
|
|
||
| add_entities([avr_device], True) | ||
|
|
||
|
|
||
| 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._source_list = avr.sources | ||
|
|
||
| self._state = None | ||
| self._muted = avr.muted | ||
| self._current_source = avr.current_source | ||
Devqon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| def update(self): | ||
| """Update the state of this media_player.""" | ||
| if self._avr.is_on(): | ||
| self._state = STATE_ON | ||
| elif self._avr.is_off(): | ||
| self._state = STATE_OFF | ||
| else: | ||
| self._state = None | ||
|
|
||
| self._muted = self._avr.muted | ||
| self._current_source = self._avr.current_source | ||
|
|
||
| @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(self): | ||
| """Return the current input source.""" | ||
| return self._current_source | ||
|
|
||
| @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.""" | ||
| self._avr.power_on() | ||
|
|
||
| def turn_off(self): | ||
| """Turn off the AVR.""" | ||
| self._avr.power_off() | ||
|
|
||
| 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) | ||
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.