Handle Mobile App registrations for device names containing of only emoji (#36957)
This commit is contained in:
1 parent
d88efe405e
commit
29f128eaad
5 files changed
+24
-1
No files matched your search
@@ -3,6 +3,7 @@ import secrets
|
||||
from typing import Dict
|
||||
|
||||
from aiohttp.web import Request, Response
|
||||
import emoji
|
||||
from nacl.secret import SecretBox
|
||||
import voluptuous as vol
|
||||
|
||||
@@ -10,6 +11,7 @@ from homeassistant.components.http import HomeAssistantView
|
||||
from homeassistant.components.http.data_validator import RequestDataValidator
|
||||
from homeassistant.const import CONF_WEBHOOK_ID, HTTP_CREATED
|
||||
from homeassistant.helpers import config_validation as cv
|
||||
from homeassistant.util import slugify
|
||||
|
||||
from .const import (
|
||||
ATTR_APP_DATA,
|
||||
@@ -75,6 +77,20 @@ class RegistrationsView(HomeAssistantView):
|
||||
|
||||
data[CONF_USER_ID] = request["hass_user"].id
|
||||
|
||||
if slugify(data[ATTR_DEVICE_NAME], separator=""):
|
||||
# if slug is not empty and would not only be underscores
|
||||
# use DEVICE_NAME
|
||||
pass
|
||||
elif emoji.emoji_count(data[ATTR_DEVICE_NAME]):
|
||||
# If otherwise empty string contains emoji
|
||||
# use descriptive name of the first emoji
|
||||
data[ATTR_DEVICE_NAME] = emoji.demojize(
|
||||
emoji.emoji_lis(data[ATTR_DEVICE_NAME])[0]["emoji"]
|
||||
).replace(":", "")
|
||||
else:
|
||||
# Fallback to DEVICE_ID
|
||||
data[ATTR_DEVICE_NAME] = data[ATTR_DEVICE_ID]
|
||||
|
||||
await hass.async_create_task(
|
||||
hass.config_entries.flow.async_init(
|
||||
DOMAIN, data=data, context={"source": "registration"}
|
||||
|
||||
Reference in new issue
Block a user