Remove YAML support from harmony (#45140)

This commit is contained in:
J. Nick Koston
2021-01-14 09:45:32 +01:00
committed by GitHub
parent 23a73dc5b1
commit 4efe6762c4
4 changed files with 3 additions and 131 deletions
@@ -129,19 +129,6 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
},
)
async def async_step_import(self, validated_input):
"""Handle import."""
await self.async_set_unique_id(
validated_input[UNIQUE_ID], raise_on_progress=False
)
self._abort_if_unique_id_configured()
# Everything was validated in remote async_setup_platform
# all we do now is create.
return await self._async_create_entry_from_valid_input(
validated_input, validated_input
)
@staticmethod
@callback
def async_get_options_flow(config_entry):
+2 -53
View File
@@ -12,12 +12,10 @@ from homeassistant.components.remote import (
ATTR_HOLD_SECS,
ATTR_NUM_REPEATS,
DEFAULT_DELAY_SECS,
PLATFORM_SCHEMA,
)
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
from homeassistant.const import ATTR_ENTITY_ID, CONF_HOST, CONF_NAME
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ATTR_ENTITY_ID
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import PlatformNotReady
from homeassistant.helpers import entity_platform
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.dispatcher import async_dispatcher_connect
@@ -36,15 +34,8 @@ from .const import (
PREVIOUS_ACTIVE_ACTIVITY,
SERVICE_CHANGE_CHANNEL,
SERVICE_SYNC,
UNIQUE_ID,
)
from .subscriber import HarmonyCallback
from .util import (
find_best_name_for_remote,
find_matching_config_entries_for_host,
find_unique_id_for_remote,
get_harmony_client_if_available,
)
_LOGGER = logging.getLogger(__name__)
@@ -53,18 +44,6 @@ PARALLEL_UPDATES = 0
ATTR_CHANNEL = "channel"
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
{
vol.Optional(ATTR_ACTIVITY): cv.string,
vol.Required(CONF_NAME): cv.string,
vol.Optional(ATTR_DELAY_SECS, default=DEFAULT_DELAY_SECS): vol.Coerce(float),
vol.Required(CONF_HOST): cv.string,
# The client ignores port so lets not confuse the user by pretenting we do anything with this
},
extra=vol.ALLOW_EXTRA,
)
HARMONY_SYNC_SCHEMA = vol.Schema({vol.Optional(ATTR_ENTITY_ID): cv.entity_ids})
HARMONY_CHANGE_CHANNEL_SCHEMA = vol.Schema(
@@ -75,36 +54,6 @@ HARMONY_CHANGE_CHANNEL_SCHEMA = vol.Schema(
)
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Set up the Harmony platform."""
if discovery_info:
# Now handled by ssdp in the config flow
return
if find_matching_config_entries_for_host(hass, config[CONF_HOST]):
return
# We do the validation to verify we can connect
# so we can raise PlatformNotReady to force
# a retry so we can avoid a scenario where the config
# entry cannot be created via import because hub
# is not yet ready.
harmony = await get_harmony_client_if_available(config[CONF_HOST])
if not harmony:
raise PlatformNotReady
validated_config = config.copy()
validated_config[UNIQUE_ID] = find_unique_id_for_remote(harmony)
validated_config[CONF_NAME] = find_best_name_for_remote(config, harmony)
hass.async_create_task(
hass.config_entries.flow.async_init(
DOMAIN, context={"source": SOURCE_IMPORT}, data=validated_config
)
)
async def async_setup_entry(
hass: HomeAssistant, entry: ConfigEntry, async_add_entities
):
+1 -22
View File
@@ -2,9 +2,7 @@
import aioharmony.exceptions as harmony_exceptions
from aioharmony.harmonyapi import HarmonyAPI
from homeassistant.const import CONF_HOST, CONF_NAME
from .const import DOMAIN
from homeassistant.const import CONF_NAME
def find_unique_id_for_remote(harmony: HarmonyAPI):
@@ -41,22 +39,3 @@ async def get_harmony_client_if_available(ip_address: str):
await harmony.close()
return harmony
def find_matching_config_entries_for_host(hass, host):
"""Search existing config entries for one matching the host."""
for entry in hass.config_entries.async_entries(DOMAIN):
if entry.data[CONF_HOST] == host:
return entry
return None
def list_names_from_hublist(hub_list):
"""Extract the name key value from a hub list of names."""
if not hub_list:
return []
return [
element["name"]
for element in hub_list
if element.get("name") and element.get("id") != -1
]