Handle Mobile App registrations for device names containing of only emoji (#36957)
parent
d88efe405e
commit
29f128eaad
|
@ -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"}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
"name": "Mobile App",
|
||||
"config_flow": true,
|
||||
"documentation": "https://www.home-assistant.io/integrations/mobile_app",
|
||||
"requirements": ["PyNaCl==1.3.0"],
|
||||
"requirements": ["PyNaCl==1.3.0", "emoji==0.5.4"],
|
||||
"dependencies": ["http", "webhook", "person"],
|
||||
"after_dependencies": ["cloud", "camera"],
|
||||
"codeowners": ["@robbiet480"],
|
||||
|
|
|
@ -11,6 +11,7 @@ ciso8601==2.1.3
|
|||
cryptography==2.9.2
|
||||
defusedxml==0.6.0
|
||||
distro==1.5.0
|
||||
emoji==0.5.4
|
||||
hass-nabucasa==0.34.6
|
||||
home-assistant-frontend==20200620.0
|
||||
importlib-metadata==1.6.0;python_version<'3.8'
|
||||
|
|
|
@ -528,6 +528,9 @@ eliqonline==1.2.2
|
|||
# homeassistant.components.elkm1
|
||||
elkm1-lib==0.7.18
|
||||
|
||||
# homeassistant.components.mobile_app
|
||||
emoji==0.5.4
|
||||
|
||||
# homeassistant.components.emulated_roku
|
||||
emulated_roku==0.2.1
|
||||
|
||||
|
|
|
@ -244,6 +244,9 @@ elgato==0.2.0
|
|||
# homeassistant.components.elkm1
|
||||
elkm1-lib==0.7.18
|
||||
|
||||
# homeassistant.components.mobile_app
|
||||
emoji==0.5.4
|
||||
|
||||
# homeassistant.components.emulated_roku
|
||||
emulated_roku==0.2.1
|
||||
|
||||
|
|
Loading…
Reference in New Issue