diff --git a/homeassistant/components/mobile_app/http_api.py b/homeassistant/components/mobile_app/http_api.py index 7d8d6c28243..a5a96b83bc6 100644 --- a/homeassistant/components/mobile_app/http_api.py +++ b/homeassistant/components/mobile_app/http_api.py @@ -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"} diff --git a/homeassistant/components/mobile_app/manifest.json b/homeassistant/components/mobile_app/manifest.json index 477acbb2203..61e90e6bd8e 100644 --- a/homeassistant/components/mobile_app/manifest.json +++ b/homeassistant/components/mobile_app/manifest.json @@ -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"], diff --git a/homeassistant/package_constraints.txt b/homeassistant/package_constraints.txt index 464a3f38d6a..34d5935e71b 100644 --- a/homeassistant/package_constraints.txt +++ b/homeassistant/package_constraints.txt @@ -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' diff --git a/requirements_all.txt b/requirements_all.txt index 5be8258bffe..ac3981f3ea3 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -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 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index b1f68c4431c..50feabcaead 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -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