home-assistant / architecture

Repo to discuss Home Assistant architecture
317 stars 100 forks source link

Extend Rest API - unique_id #769

Closed cpyarger closed 2 years ago

cpyarger commented 2 years ago

Context

Currently sensors created with the REST API are unable to be modified in the Home Assistant UI

image

It should look like this

image This is due to the inability to set the unique_id on the sensor via the REST API exposed to addons.

Proposal

At least for addons accessing the REST API via the proxy, allow for setting the attribute unique_id on sensor creation

Consequences

since this only effects sensors being initially created, any effect otherwise should be minimal. even if people pass the unique_id after creation of the sensor, it should have no effect.

balloob commented 2 years ago

This is by design.

States can be set remotely, but that is not the same as an entity. Entities are provided by integrations.

See https://www.home-assistant.io/blog/2021/05/12/integrations-api/

cpyarger commented 2 years ago

Entities are able to be created with the rest API. It makes sense to be able to do so properly by setting a unique Id, otherwise what have that feature exist at all in the API, some tasks are more complicated than an integration can easily handle. Take the sdrmr addon . Which requires multiple background processes, and libraries installed which eventually push data to update states.

Doing this in docker is trivial, but building an integration to do the same would require rewriting multiple major projects.

If you have any decent easy to understand examples of where or how to do this as an integration I would appreciate it.

Otherwise I'd like to keep this discussion open. As it is a thread on changing the design, "it is by design" seems like a rather lackluster response that doesn't actually address the issue

balloob commented 2 years ago

You're confusing states with entities. They are not the same. We're not going to add an entity API for the reasons laid out in the blog post. This is not up for discussion.