diff --git a/.coveragerc b/.coveragerc index 54120f305f4..de92c1c23e8 100644 --- a/.coveragerc +++ b/.coveragerc @@ -176,6 +176,8 @@ omit = homeassistant/components/dsmr_reader/* homeassistant/components/dte_energy_bridge/sensor.py homeassistant/components/dublin_bus_transport/sensor.py + homeassistant/components/dunehd/__init__.py + homeassistant/components/dunehd/const.py homeassistant/components/dunehd/media_player.py homeassistant/components/dwd_weather_warnings/sensor.py homeassistant/components/dweet/* diff --git a/CODEOWNERS b/CODEOWNERS index d00f428efed..82e3e388026 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -98,6 +98,7 @@ homeassistant/components/directv/* @ctalkington homeassistant/components/discogs/* @thibmaek homeassistant/components/doorbird/* @oblogic7 @bdraco homeassistant/components/dsmr_reader/* @depl0y +homeassistant/components/dunehd/* @bieniu homeassistant/components/dweet/* @fabaff homeassistant/components/dynalite/* @ziv1234 homeassistant/components/dyson/* @etheralm diff --git a/homeassistant/components/dunehd/__init__.py b/homeassistant/components/dunehd/__init__.py index a8b8a8cf7af..a1fa456aa09 100644 --- a/homeassistant/components/dunehd/__init__.py +++ b/homeassistant/components/dunehd/__init__.py @@ -1 +1,49 @@ -"""The dunehd component.""" +"""The Dune HD component.""" +import asyncio + +from pdunehd import DuneHDPlayer + +from homeassistant.const import CONF_HOST + +from .const import DOMAIN + +PLATFORMS = ["media_player"] + + +async def async_setup(hass, config): + """Set up the Dune HD component.""" + return True + + +async def async_setup_entry(hass, config_entry): + """Set up a config entry.""" + host = config_entry.data[CONF_HOST] + + player = DuneHDPlayer(host) + + hass.data.setdefault(DOMAIN, {}) + hass.data[DOMAIN][config_entry.entry_id] = player + + for component in PLATFORMS: + hass.async_create_task( + hass.config_entries.async_forward_entry_setup(config_entry, component) + ) + + return True + + +async def async_unload_entry(hass, config_entry): + """Unload a config entry.""" + unload_ok = all( + await asyncio.gather( + *[ + hass.config_entries.async_forward_entry_unload(config_entry, component) + for component in PLATFORMS + ] + ) + ) + + if unload_ok: + hass.data[DOMAIN].pop(config_entry.entry_id) + + return unload_ok diff --git a/homeassistant/components/dunehd/config_flow.py b/homeassistant/components/dunehd/config_flow.py new file mode 100644 index 00000000000..1f0efa668f9 --- /dev/null +++ b/homeassistant/components/dunehd/config_flow.py @@ -0,0 +1,101 @@ +"""Adds config flow for Dune HD integration.""" +import ipaddress +import logging +import re + +from pdunehd import DuneHDPlayer +import voluptuous as vol + +from homeassistant import config_entries, exceptions +from homeassistant.const import CONF_HOST + +from .const import DOMAIN # pylint:disable=unused-import + +_LOGGER = logging.getLogger(__name__) + + +def host_valid(host): + """Return True if hostname or IP address is valid.""" + try: + if ipaddress.ip_address(host).version == (4 or 6): + return True + except ValueError: + if len(host) > 253: + return False + allowed = re.compile(r"(?!-)[A-Z\d\-\_]{1,63}(?