mirror of
https://github.com/home-assistant/core.git
synced 2026-02-15 07:36:16 +00:00
Use service helper to extract bring config entry (#162790)
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
"""Actions for Bring! integration."""
|
||||
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from bring_api import (
|
||||
ActivityType,
|
||||
BringAuthException,
|
||||
@@ -13,7 +11,6 @@ import voluptuous as vol
|
||||
|
||||
from homeassistant.components.event import ATTR_EVENT_TYPE
|
||||
from homeassistant.components.todo import DOMAIN as TODO_DOMAIN
|
||||
from homeassistant.config_entries import ConfigEntryState
|
||||
from homeassistant.const import ATTR_ENTITY_ID
|
||||
from homeassistant.core import HomeAssistant, ServiceCall, callback
|
||||
from homeassistant.exceptions import HomeAssistantError, ServiceValidationError
|
||||
@@ -46,19 +43,6 @@ SERVICE_ACTIVITY_STREAM_REACTION_SCHEMA = vol.Schema(
|
||||
)
|
||||
|
||||
|
||||
def get_config_entry(hass: HomeAssistant, entry_id: str) -> BringConfigEntry:
|
||||
"""Return config entry or raise if not found or not loaded."""
|
||||
entry = hass.config_entries.async_get_entry(entry_id)
|
||||
if TYPE_CHECKING:
|
||||
assert entry
|
||||
if entry.state is not ConfigEntryState.LOADED:
|
||||
raise ServiceValidationError(
|
||||
translation_domain=DOMAIN,
|
||||
translation_key="entry_not_loaded",
|
||||
)
|
||||
return entry
|
||||
|
||||
|
||||
@callback
|
||||
def async_setup_services(hass: HomeAssistant) -> None:
|
||||
"""Set up services for Bring! integration."""
|
||||
@@ -78,7 +62,9 @@ def async_setup_services(hass: HomeAssistant) -> None:
|
||||
ATTR_ENTITY_ID: call.data[ATTR_ENTITY_ID],
|
||||
},
|
||||
)
|
||||
config_entry = get_config_entry(hass, entity.config_entry_id)
|
||||
config_entry: BringConfigEntry = service.async_get_config_entry(
|
||||
hass, DOMAIN, entity.config_entry_id
|
||||
)
|
||||
|
||||
coordinator = config_entry.runtime_data.data
|
||||
|
||||
|
||||
@@ -124,10 +124,6 @@
|
||||
"entity_not_found": {
|
||||
"message": "Failed to send reaction for Bring! — Unknown entity {entity_id}"
|
||||
},
|
||||
|
||||
"entry_not_loaded": {
|
||||
"message": "The account associated with this Bring! list is either not loaded or disabled in Home Assistant."
|
||||
},
|
||||
"notify_missing_argument": {
|
||||
"message": "This action requires field {field}, please enter a valid value for {field}"
|
||||
},
|
||||
|
||||
@@ -112,10 +112,7 @@ async def test_send_reaction_config_entry_not_loaded(
|
||||
|
||||
assert bring_config_entry.state is ConfigEntryState.NOT_LOADED
|
||||
|
||||
with pytest.raises(
|
||||
ServiceValidationError,
|
||||
match="The account associated with this Bring! list is either not loaded or disabled in Home Assistant",
|
||||
):
|
||||
with pytest.raises(ServiceValidationError) as err:
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
SERVICE_ACTIVITY_STREAM_REACTION,
|
||||
@@ -125,6 +122,8 @@ async def test_send_reaction_config_entry_not_loaded(
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
assert err.value.translation_key == "service_config_entry_not_loaded"
|
||||
assert err.value.translation_placeholders["entry_title"] == "Mock Title"
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_bring_client")
|
||||
|
||||
Reference in New Issue
Block a user