Restore AndroidTV entity name from migration (#68756)

pull/68770/head
ollo69 2022-03-28 02:57:15 +02:00 committed by GitHub
parent c024033dae
commit 17ddbb4983
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 4 deletions

View File

@ -8,7 +8,7 @@ from androidtv import state_detection_rules_validator
import voluptuous as vol
from homeassistant import config_entries
from homeassistant.const import CONF_DEVICE_CLASS, CONF_HOST, CONF_NAME, CONF_PORT
from homeassistant.const import CONF_DEVICE_CLASS, CONF_HOST, CONF_PORT
from homeassistant.core import callback
from homeassistant.helpers import config_validation as cv
@ -164,7 +164,7 @@ class AndroidTVFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
self._abort_if_unique_id_configured()
return self.async_create_entry(
title=user_input.get(CONF_NAME) or host,
title=host,
data=user_input,
)

View File

@ -39,6 +39,7 @@ from homeassistant.const import (
ATTR_MODEL,
ATTR_SW_VERSION,
CONF_HOST,
CONF_NAME,
STATE_IDLE,
STATE_OFF,
STATE_PAUSED,
@ -128,7 +129,8 @@ async def async_setup_entry(
aftv = hass.data[DOMAIN][entry.entry_id][ANDROID_DEV]
device_class = aftv.DEVICE_CLASS
device_type = "Android TV" if device_class == DEVICE_ANDROIDTV else "Fire TV"
device_name = f"{device_type} {entry.data[CONF_HOST]}"
# CONF_NAME may be present in entry.data for configuration imported from YAML
device_name = entry.data.get(CONF_NAME) or f"{device_type} {entry.data[CONF_HOST]}"
device_args = [
aftv,

View File

@ -53,6 +53,7 @@ from homeassistant.const import (
ATTR_ENTITY_ID,
CONF_DEVICE_CLASS,
CONF_HOST,
CONF_NAME,
CONF_PORT,
EVENT_HOMEASSISTANT_STOP,
STATE_OFF,
@ -86,6 +87,14 @@ CONFIG_ANDROIDTV_PYTHON_ADB = {
}
}
# Android TV device with Python ADB implementation imported from YAML
CONFIG_ANDROIDTV_PYTHON_ADB_YAML = {
DOMAIN: {
CONF_NAME: "ADB yaml import",
**CONFIG_ANDROIDTV_PYTHON_ADB[DOMAIN],
}
}
# Android TV device with ADB server
CONFIG_ANDROIDTV_ADB_SERVER = {
DOMAIN: {
@ -127,7 +136,10 @@ def _setup(config):
patch_key = "server"
host = config[DOMAIN][CONF_HOST]
if config[DOMAIN].get(CONF_DEVICE_CLASS) != "firetv":
# CONF_NAME available for configuration imported from YAML
if conf_name := config[DOMAIN].get(CONF_NAME):
entity_id = slugify(conf_name)
elif config[DOMAIN].get(CONF_DEVICE_CLASS) != "firetv":
entity_id = slugify(f"Android TV {host}")
else:
entity_id = slugify(f"Fire TV {host}")
@ -147,6 +159,7 @@ def _setup(config):
"config",
[
CONFIG_ANDROIDTV_PYTHON_ADB,
CONFIG_ANDROIDTV_PYTHON_ADB_YAML,
CONFIG_FIRETV_PYTHON_ADB,
CONFIG_ANDROIDTV_ADB_SERVER,
CONFIG_FIRETV_ADB_SERVER,