Add HEOS media player component (#21721)

## Description:
Denon HEOS media player.

**Pull request in [home-assistant.io](https://github.com/home-assistant/home-assistant.io) with documentation (if applicable):** home-assistant/home-assistant.io#8848

## Example entry for `configuration.yaml` (if applicable):
```yaml
heos:
  host: HEOS-1                              
```

## Checklist:
  - [X] The code change is tested and works locally.
  - [X] Local tests pass with `tox`. **Your PR cannot be merged unless tests pass**
  - [X] There is no commented out code in this PR.

If user exposed functionality or configuration variables are added/changed:
  - [X] Documentation added/updated in [home-assistant.io](https://github.com/home-assistant/home-assistant.io)

If the code communicates with devices, web services, or third-party tools:
  - [X] New dependencies have been added to the `REQUIREMENTS` variable ([example][ex-requir]).
  - [X] New dependencies are only imported inside functions that use them ([example][ex-import]).
  - [X] New or updated dependencies have been added to `requirements_all.txt` by running `script/gen_requirements_all.py`.
  - [X] New files were added to `.coveragerc`.

If the code does not interact with devices:
  - [ ] Tests have been added to verify that the new code works.

[ex-requir]: https://github.com/home-assistant/home-assistant/blob/dev/homeassistant/components/keyboard/__init__.py#L14
[ex-import]: https://github.com/home-assistant/home-assistant/blob/dev/homeassistant/components/keyboard/__init__.py#L23


Co-authored-by: Andrew Sayre <6730289+andrewsayre@users.noreply.github.com>
This commit is contained in:
Andreas RydbrinkandAndrew Sayre authored and Robbie Trencheny committed 2019-03-28 19:03:02 -07:00
1 parent 709419e465
commit 01052f516b
4 files changed
+211

No files matched your search

+52
View File
@@ -0,0 +1,52 @@
"""Denon HEOS Media Player."""
import asyncio
import logging
import voluptuous as vol
from homeassistant.components.media_player.const import (
DOMAIN as MEDIA_PLAYER_DOMAIN)
from homeassistant.const import CONF_HOST, EVENT_HOMEASSISTANT_STOP
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.discovery import async_load_platform
from homeassistant.helpers.typing import ConfigType, HomeAssistantType
DOMAIN = 'heos'
REQUIREMENTS = ['aioheos==0.4.0']
CONFIG_SCHEMA = vol.Schema({
DOMAIN: vol.Schema({
vol.Required(CONF_HOST): cv.string
})
}, extra=vol.ALLOW_EXTRA)
_LOGGER = logging.getLogger(__name__)
async def async_setup(hass: HomeAssistantType, config: ConfigType):
"""Set up the HEOS component."""
from aioheos import AioHeosController
host = config[DOMAIN][CONF_HOST]
controller = AioHeosController(hass.loop, host)
try:
await asyncio.wait_for(controller.connect(), timeout=5.0)
except asyncio.TimeoutError:
_LOGGER.error('Timeout during setup.')
return False
async def controller_close(event):
"""Close connection when HASS shutsdown."""
await controller.close()
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, controller_close)
hass.data.setdefault(DOMAIN, {})
hass.data[DOMAIN][MEDIA_PLAYER_DOMAIN] = controller
hass.async_create_task(async_load_platform(
hass, MEDIA_PLAYER_DOMAIN, DOMAIN, {}, config))
return True