Allow adding unique device ID to mobile app registration (#30457)
* Allow adding unique device ID to mobile app registration * Remove unknown data * Better fix
This commit is contained in:
1 parent
6e909ab3f1
commit
2f362b44c4
5 files changed
+34
-16
No files matched your search
@@ -21,6 +21,7 @@ from .const import (
|
||||
ATTR_DEVICE_NAME,
|
||||
ATTR_MANUFACTURER,
|
||||
ATTR_MODEL,
|
||||
ATTR_MODEL_ID,
|
||||
ATTR_OS_NAME,
|
||||
ATTR_OS_VERSION,
|
||||
ATTR_SUPPORTS_ENCRYPTION,
|
||||
@@ -40,18 +41,23 @@ class RegistrationsView(HomeAssistantView):
|
||||
name = "api:mobile_app:register"
|
||||
|
||||
@RequestDataValidator(
|
||||
{
|
||||
vol.Optional(ATTR_APP_DATA, default={}): dict,
|
||||
vol.Required(ATTR_APP_ID): cv.string,
|
||||
vol.Required(ATTR_APP_NAME): cv.string,
|
||||
vol.Required(ATTR_APP_VERSION): cv.string,
|
||||
vol.Required(ATTR_DEVICE_NAME): cv.string,
|
||||
vol.Required(ATTR_MANUFACTURER): cv.string,
|
||||
vol.Required(ATTR_MODEL): cv.string,
|
||||
vol.Required(ATTR_OS_NAME): cv.string,
|
||||
vol.Optional(ATTR_OS_VERSION): cv.string,
|
||||
vol.Required(ATTR_SUPPORTS_ENCRYPTION, default=False): cv.boolean,
|
||||
}
|
||||
vol.Schema(
|
||||
{
|
||||
vol.Optional(ATTR_APP_DATA, default={}): dict,
|
||||
vol.Required(ATTR_APP_ID): cv.string,
|
||||
vol.Required(ATTR_APP_NAME): cv.string,
|
||||
vol.Required(ATTR_APP_VERSION): cv.string,
|
||||
vol.Required(ATTR_DEVICE_NAME): cv.string,
|
||||
vol.Required(ATTR_MANUFACTURER): cv.string,
|
||||
vol.Required(ATTR_MODEL): cv.string,
|
||||
vol.Optional(ATTR_MODEL_ID): cv.string, # Added in 0.104
|
||||
vol.Required(ATTR_OS_NAME): cv.string,
|
||||
vol.Optional(ATTR_OS_VERSION): cv.string,
|
||||
vol.Required(ATTR_SUPPORTS_ENCRYPTION, default=False): cv.boolean,
|
||||
},
|
||||
# To allow future apps to send more data
|
||||
extra=vol.REMOVE_EXTRA,
|
||||
)
|
||||
)
|
||||
async def post(self, request: Request, data: Dict) -> Response:
|
||||
"""Handle the POST request for registration."""
|
||||
@@ -64,7 +70,13 @@ class RegistrationsView(HomeAssistantView):
|
||||
CONF_CLOUDHOOK_URL
|
||||
] = await hass.components.cloud.async_create_cloudhook(webhook_id)
|
||||
|
||||
data[ATTR_DEVICE_ID] = str(uuid.uuid4()).replace("-", "")
|
||||
model_id = data.get(ATTR_MODEL_ID)
|
||||
|
||||
if model_id is None:
|
||||
data[ATTR_DEVICE_ID] = str(uuid.uuid4()).replace("-", "")
|
||||
|
||||
else:
|
||||
data[ATTR_DEVICE_ID] = f"{data[ATTR_APP_ID]}-{model_id}"
|
||||
|
||||
data[CONF_WEBHOOK_ID] = webhook_id
|
||||
|
||||
@@ -73,9 +85,10 @@ class RegistrationsView(HomeAssistantView):
|
||||
|
||||
data[CONF_USER_ID] = request["hass_user"].id
|
||||
|
||||
ctx = {"source": "registration"}
|
||||
await hass.async_create_task(
|
||||
hass.config_entries.flow.async_init(DOMAIN, context=ctx, data=data)
|
||||
hass.config_entries.flow.async_init(
|
||||
DOMAIN, data=data, context={"source": "registration"}
|
||||
)
|
||||
)
|
||||
|
||||
remote_ui_url = None
|
||||
|
||||
Reference in new issue
Block a user