Revert "Allow setting entity options with config/entity_registry/update" (#64693)

This commit is contained in:
Erik Montnemery 2022-01-24 06:07:12 +01:00 committed by GitHub
parent 32099ea38a
commit 55ff1e9c1d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 65 deletions

View file

@ -84,8 +84,6 @@ async def websocket_get_entity(hass, connection, msg):
vol.Coerce(RegistryEntryDisabler), RegistryEntryDisabler.USER.value
),
),
vol.Inclusive("options_domain", "entity_option"): str,
vol.Inclusive("options", "entity_option"): vol.Any(None, dict),
}
)
async def websocket_update_entity(hass, connection, msg):
@ -95,8 +93,7 @@ async def websocket_update_entity(hass, connection, msg):
"""
registry = await async_get_registry(hass)
entity_id = msg["entity_id"]
if entity_id not in registry.entities:
if msg["entity_id"] not in registry.entities:
connection.send_message(
websocket_api.error_message(msg["id"], ERR_NOT_FOUND, "Entity not found")
)
@ -108,7 +105,7 @@ async def websocket_update_entity(hass, connection, msg):
if key in msg:
changes[key] = msg[key]
if "new_entity_id" in msg and msg["new_entity_id"] != entity_id:
if "new_entity_id" in msg and msg["new_entity_id"] != msg["entity_id"]:
changes["new_entity_id"] = msg["new_entity_id"]
if hass.states.get(msg["new_entity_id"]) is not None:
connection.send_message(
@ -121,7 +118,7 @@ async def websocket_update_entity(hass, connection, msg):
return
if "disabled_by" in msg and msg["disabled_by"] is None:
entity = registry.entities[entity_id]
entity = registry.entities[msg["entity_id"]]
if entity.device_id:
device_registry = await hass.helpers.device_registry.async_get_registry()
device = device_registry.async_get(entity.device_id)
@ -135,28 +132,12 @@ async def websocket_update_entity(hass, connection, msg):
try:
if changes:
registry.async_update_entity(entity_id, **changes)
entry = registry.async_update_entity(msg["entity_id"], **changes)
except ValueError as err:
connection.send_message(
websocket_api.error_message(msg["id"], "invalid_info", str(err))
)
return
if "new_entity_id" in msg:
entity_id = msg["new_entity_id"]
try:
if "options_domain" in msg:
registry.async_update_entity_options(
entity_id, msg["options_domain"], msg["options"]
)
except ValueError as err:
connection.send_message(
websocket_api.error_message(msg["id"], "invalid_info", str(err))
)
return
entry = registry.async_get(entity_id)
result = {"entity_entry": _entry_ext_dict(entry)}
if "disabled_by" in changes and changes["disabled_by"] is None:
config_entry = hass.config_entries.async_get_entry(entry.config_entry_id)
@ -214,7 +195,6 @@ def _entry_ext_dict(entry):
data = _entry_dict(entry)
data["capabilities"] = entry.capabilities
data["device_class"] = entry.device_class
data["options"] = entry.options
data["original_device_class"] = entry.original_device_class
data["original_icon"] = entry.original_icon
data["original_name"] = entry.original_name

View file

@ -111,7 +111,6 @@ async def test_get_entity(hass, client):
"entity_id": "test_domain.name",
"icon": None,
"name": "Hello World",
"options": {},
"original_device_class": None,
"original_icon": None,
"original_name": None,
@ -139,7 +138,6 @@ async def test_get_entity(hass, client):
"entity_id": "test_domain.no_name",
"icon": None,
"name": None,
"options": {},
"original_device_class": None,
"original_icon": None,
"original_name": None,
@ -199,7 +197,6 @@ async def test_update_entity(hass, client):
"entity_id": "test_domain.world",
"icon": "icon:after update",
"name": "after update",
"options": {},
"original_device_class": None,
"original_icon": None,
"original_name": None,
@ -253,7 +250,6 @@ async def test_update_entity(hass, client):
"entity_id": "test_domain.world",
"icon": "icon:after update",
"name": "after update",
"options": {},
"original_device_class": None,
"original_icon": None,
"original_name": None,
@ -263,40 +259,6 @@ async def test_update_entity(hass, client):
"reload_delay": 30,
}
# UPDATE ENTITY OPTION
await client.send_json(
{
"id": 9,
"type": "config/entity_registry/update",
"entity_id": "test_domain.world",
"options_domain": "sensor",
"options": {"unit_of_measurement": "beard_second"},
}
)
msg = await client.receive_json()
assert msg["result"] == {
"entity_entry": {
"area_id": "mock-area-id",
"capabilities": None,
"config_entry_id": None,
"device_class": "custom_device_class",
"device_id": None,
"disabled_by": None,
"entity_category": None,
"entity_id": "test_domain.world",
"icon": "icon:after update",
"name": "after update",
"options": {"sensor": {"unit_of_measurement": "beard_second"}},
"original_device_class": None,
"original_icon": None,
"original_name": None,
"platform": "test_platform",
"unique_id": "1234",
},
}
async def test_update_entity_require_restart(hass, client):
"""Test updating entity."""
@ -345,7 +307,6 @@ async def test_update_entity_require_restart(hass, client):
"entity_id": "test_domain.world",
"icon": None,
"name": None,
"options": {},
"original_device_class": None,
"original_icon": None,
"original_name": None,
@ -450,7 +411,6 @@ async def test_update_entity_no_changes(hass, client):
"entity_id": "test_domain.world",
"icon": None,
"name": "name of entity",
"options": {},
"original_device_class": None,
"original_icon": None,
"original_name": None,
@ -534,7 +494,6 @@ async def test_update_entity_id(hass, client):
"entity_id": "test_domain.planet",
"icon": None,
"name": None,
"options": {},
"original_device_class": None,
"original_icon": None,
"original_name": None,