Use entity registry id instead of entity_id
This commit is contained in:
parent
71ffbe2453
commit
08266a0d54
2 changed files with 33 additions and 14 deletions
|
@ -5,6 +5,10 @@ from typing import Final
|
|||
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.device_automation import (
|
||||
async_get_entity_registry_entry_or_raise,
|
||||
async_validate_entity_schema,
|
||||
)
|
||||
from homeassistant.const import (
|
||||
ATTR_ENTITY_ID,
|
||||
CONF_DEVICE_ID,
|
||||
|
@ -29,15 +33,22 @@ from .const import (
|
|||
|
||||
ACTION_TYPES: Final[set[str]] = {"install", "skip"}
|
||||
|
||||
ACTION_SCHEMA = cv.DEVICE_ACTION_BASE_SCHEMA.extend(
|
||||
_ACTION_SCHEMA = cv.DEVICE_ACTION_BASE_SCHEMA.extend(
|
||||
{
|
||||
vol.Required(CONF_TYPE): vol.In(ACTION_TYPES),
|
||||
vol.Required(CONF_ENTITY_ID): cv.entity_domain(DOMAIN),
|
||||
vol.Required(CONF_ENTITY_ID): cv.entity_id_or_uuid,
|
||||
vol.Optional("backup"): cv.boolean,
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
async def async_validate_action_config(
|
||||
hass: HomeAssistant, config: ConfigType
|
||||
) -> ConfigType:
|
||||
"""Validate config."""
|
||||
return async_validate_entity_schema(hass, config, _ACTION_SCHEMA)
|
||||
|
||||
|
||||
async def async_get_actions(
|
||||
hass: HomeAssistant, device_id: str
|
||||
) -> list[dict[str, str]]:
|
||||
|
@ -55,7 +66,7 @@ async def async_get_actions(
|
|||
base_action = {
|
||||
CONF_DEVICE_ID: device_id,
|
||||
CONF_DOMAIN: DOMAIN,
|
||||
CONF_ENTITY_ID: entry.entity_id,
|
||||
CONF_ENTITY_ID: entry.id,
|
||||
}
|
||||
|
||||
# Add actions for each entity that belongs to this integration
|
||||
|
@ -98,7 +109,8 @@ async def async_get_action_capabilities(
|
|||
return {}
|
||||
|
||||
try:
|
||||
supported_features = get_supported_features(hass, config[ATTR_ENTITY_ID])
|
||||
entry = async_get_entity_registry_entry_or_raise(hass, config[CONF_ENTITY_ID])
|
||||
supported_features = get_supported_features(hass, entry.entity_id)
|
||||
except HomeAssistantError:
|
||||
supported_features = 0
|
||||
|
||||
|
|
|
@ -53,7 +53,7 @@ async def test_get_actions(
|
|||
config_entry_id=config_entry.entry_id,
|
||||
connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
|
||||
)
|
||||
entity_registry.async_get_or_create(
|
||||
entity_entry = entity_registry.async_get_or_create(
|
||||
DOMAIN,
|
||||
"test",
|
||||
"5678",
|
||||
|
@ -66,7 +66,7 @@ async def test_get_actions(
|
|||
"domain": DOMAIN,
|
||||
"type": action,
|
||||
"device_id": device_entry.id,
|
||||
"entity_id": f"{DOMAIN}.test_5678",
|
||||
"entity_id": entity_entry.id,
|
||||
"metadata": {"secondary": False},
|
||||
}
|
||||
for action in expected_action_types
|
||||
|
@ -115,7 +115,7 @@ async def test_get_actions_hidden_auxiliary(
|
|||
"domain": DOMAIN,
|
||||
"type": action,
|
||||
"device_id": device_entry.id,
|
||||
"entity_id": entity_entry.entity_id,
|
||||
"entity_id": entity_entry.id,
|
||||
"metadata": {"secondary": True},
|
||||
}
|
||||
for action in ["skip"]
|
||||
|
@ -138,7 +138,7 @@ async def test_get_actions_reporting_only(
|
|||
config_entry_id=config_entry.entry_id,
|
||||
connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
|
||||
)
|
||||
entity_registry.async_get_or_create(
|
||||
entity_entry = entity_registry.async_get_or_create(
|
||||
DOMAIN, "test", "123", device_id=device_entry.id
|
||||
)
|
||||
hass.states.async_set("update.test_123", "attributes", {"supported_features": 0})
|
||||
|
@ -147,7 +147,7 @@ async def test_get_actions_reporting_only(
|
|||
"domain": DOMAIN,
|
||||
"type": "skip",
|
||||
"device_id": device_entry.id,
|
||||
"entity_id": "update.test_123",
|
||||
"entity_id": entity_entry.id,
|
||||
"metadata": {"secondary": False},
|
||||
},
|
||||
]
|
||||
|
@ -169,7 +169,7 @@ async def test_get_actions_with_install(
|
|||
config_entry_id=config_entry.entry_id,
|
||||
connections={(dr.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
|
||||
)
|
||||
entity_registry.async_get_or_create(
|
||||
entity_entry = entity_registry.async_get_or_create(
|
||||
DOMAIN, "test", "123", device_id=device_entry.id
|
||||
)
|
||||
hass.states.async_set(
|
||||
|
@ -182,7 +182,7 @@ async def test_get_actions_with_install(
|
|||
"domain": DOMAIN,
|
||||
"type": action,
|
||||
"device_id": device_entry.id,
|
||||
"entity_id": "update.test_123",
|
||||
"entity_id": entity_entry.id,
|
||||
"metadata": {"secondary": False},
|
||||
}
|
||||
for action in ["install", "skip"]
|
||||
|
@ -235,10 +235,17 @@ async def test_get_action_capabilities(
|
|||
assert capabilities == expected_capabilities[action["type"]]
|
||||
|
||||
|
||||
async def test_action(hass: HomeAssistant, enable_custom_integrations: None) -> None:
|
||||
async def test_action(
|
||||
hass: HomeAssistant,
|
||||
entity_registry: er.EntityRegistry,
|
||||
enable_custom_integrations: None,
|
||||
) -> None:
|
||||
"""Test for install and skip actions."""
|
||||
platform = getattr(hass.components, f"test.{DOMAIN}")
|
||||
platform.init()
|
||||
assert await async_setup_component(hass, DOMAIN, {DOMAIN: {CONF_PLATFORM: "test"}})
|
||||
await hass.async_block_till_done()
|
||||
entry = entity_registry.async_get("update.update_backup")
|
||||
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
|
@ -253,7 +260,7 @@ async def test_action(hass: HomeAssistant, enable_custom_integrations: None) ->
|
|||
"action": {
|
||||
"domain": DOMAIN,
|
||||
"device_id": "abcdefgh",
|
||||
"entity_id": "update.update_backup",
|
||||
"entity_id": entry.id,
|
||||
"type": "skip",
|
||||
},
|
||||
},
|
||||
|
@ -265,7 +272,7 @@ async def test_action(hass: HomeAssistant, enable_custom_integrations: None) ->
|
|||
"action": {
|
||||
"domain": DOMAIN,
|
||||
"device_id": "abcdefgh",
|
||||
"entity_id": "update.update_backup",
|
||||
"entity_id": entry.id,
|
||||
"type": "install",
|
||||
"backup": True,
|
||||
},
|
||||
|
|
Loading…
Add table
Reference in a new issue