mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Remove deprecated action api_call
from Habitica integration (#143978)
This commit is contained in:
parent
93f4f14b2a
commit
5250590b17
@ -1,6 +1,6 @@
|
||||
"""Constants for the habitica integration."""
|
||||
|
||||
from homeassistant.const import APPLICATION_NAME, CONF_PATH, __version__
|
||||
from homeassistant.const import APPLICATION_NAME, __version__
|
||||
|
||||
CONF_API_USER = "api_user"
|
||||
|
||||
@ -13,15 +13,6 @@ HABITICANS_URL = "https://habitica.com/static/img/home-main@3x.ffc32b12.png"
|
||||
|
||||
DOMAIN = "habitica"
|
||||
|
||||
# service constants
|
||||
SERVICE_API_CALL = "api_call"
|
||||
ATTR_PATH = CONF_PATH
|
||||
ATTR_ARGS = "args"
|
||||
|
||||
# event constants
|
||||
EVENT_API_CALL_SUCCESS = f"{DOMAIN}_{SERVICE_API_CALL}_success"
|
||||
ATTR_DATA = "data"
|
||||
|
||||
MANUFACTURER = "HabitRPG, Inc."
|
||||
NAME = "Habitica"
|
||||
|
||||
|
@ -29,7 +29,7 @@ import voluptuous as vol
|
||||
|
||||
from homeassistant.components.todo import ATTR_RENAME
|
||||
from homeassistant.config_entries import ConfigEntryState
|
||||
from homeassistant.const import ATTR_DATE, ATTR_NAME, CONF_NAME
|
||||
from homeassistant.const import ATTR_DATE, ATTR_NAME
|
||||
from homeassistant.core import (
|
||||
HomeAssistant,
|
||||
ServiceCall,
|
||||
@ -38,28 +38,24 @@ from homeassistant.core import (
|
||||
)
|
||||
from homeassistant.exceptions import HomeAssistantError, ServiceValidationError
|
||||
from homeassistant.helpers import config_validation as cv
|
||||
from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue
|
||||
from homeassistant.helpers.selector import ConfigEntrySelector
|
||||
from homeassistant.util import dt as dt_util
|
||||
|
||||
from .const import (
|
||||
ATTR_ADD_CHECKLIST_ITEM,
|
||||
ATTR_ALIAS,
|
||||
ATTR_ARGS,
|
||||
ATTR_CLEAR_DATE,
|
||||
ATTR_CLEAR_REMINDER,
|
||||
ATTR_CONFIG_ENTRY,
|
||||
ATTR_COST,
|
||||
ATTR_COUNTER_DOWN,
|
||||
ATTR_COUNTER_UP,
|
||||
ATTR_DATA,
|
||||
ATTR_DIRECTION,
|
||||
ATTR_FREQUENCY,
|
||||
ATTR_INTERVAL,
|
||||
ATTR_ITEM,
|
||||
ATTR_KEYWORD,
|
||||
ATTR_NOTES,
|
||||
ATTR_PATH,
|
||||
ATTR_PRIORITY,
|
||||
ATTR_REMINDER,
|
||||
ATTR_REMOVE_CHECKLIST_ITEM,
|
||||
@ -78,10 +74,8 @@ from .const import (
|
||||
ATTR_UNSCORE_CHECKLIST_ITEM,
|
||||
ATTR_UP_DOWN,
|
||||
DOMAIN,
|
||||
EVENT_API_CALL_SUCCESS,
|
||||
SERVICE_ABORT_QUEST,
|
||||
SERVICE_ACCEPT_QUEST,
|
||||
SERVICE_API_CALL,
|
||||
SERVICE_CANCEL_QUEST,
|
||||
SERVICE_CAST_SKILL,
|
||||
SERVICE_CREATE_DAILY,
|
||||
@ -106,14 +100,6 @@ from .coordinator import HabiticaConfigEntry
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
SERVICE_API_CALL_SCHEMA = vol.Schema(
|
||||
{
|
||||
vol.Required(ATTR_NAME): str,
|
||||
vol.Required(ATTR_PATH): vol.All(cv.ensure_list, [str]),
|
||||
vol.Optional(ATTR_ARGS): dict,
|
||||
}
|
||||
)
|
||||
|
||||
SERVICE_CAST_SKILL_SCHEMA = vol.Schema(
|
||||
{
|
||||
vol.Required(ATTR_CONFIG_ENTRY): ConfigEntrySelector({"integration": DOMAIN}),
|
||||
@ -266,46 +252,6 @@ def get_config_entry(hass: HomeAssistant, entry_id: str) -> HabiticaConfigEntry:
|
||||
def async_setup_services(hass: HomeAssistant) -> None: # noqa: C901
|
||||
"""Set up services for Habitica integration."""
|
||||
|
||||
async def handle_api_call(call: ServiceCall) -> None:
|
||||
async_create_issue(
|
||||
hass,
|
||||
DOMAIN,
|
||||
"deprecated_api_call",
|
||||
breaks_in_ha_version="2025.6.0",
|
||||
is_fixable=False,
|
||||
severity=IssueSeverity.WARNING,
|
||||
translation_key="deprecated_api_call",
|
||||
)
|
||||
_LOGGER.warning(
|
||||
"Deprecated action called: 'habitica.api_call' is deprecated and will be removed in Home Assistant version 2025.6.0"
|
||||
)
|
||||
|
||||
name = call.data[ATTR_NAME]
|
||||
path = call.data[ATTR_PATH]
|
||||
entries: list[HabiticaConfigEntry] = hass.config_entries.async_entries(DOMAIN)
|
||||
|
||||
api = None
|
||||
for entry in entries:
|
||||
if entry.data[CONF_NAME] == name:
|
||||
api = await entry.runtime_data.habitica.habitipy()
|
||||
break
|
||||
if api is None:
|
||||
_LOGGER.error("API_CALL: User '%s' not configured", name)
|
||||
return
|
||||
try:
|
||||
for element in path:
|
||||
api = api[element]
|
||||
except KeyError:
|
||||
_LOGGER.error(
|
||||
"API_CALL: Path %s is invalid for API on '{%s}' element", path, element
|
||||
)
|
||||
return
|
||||
kwargs = call.data.get(ATTR_ARGS, {})
|
||||
data = await api(**kwargs)
|
||||
hass.bus.async_fire(
|
||||
EVENT_API_CALL_SUCCESS, {ATTR_NAME: name, ATTR_PATH: path, ATTR_DATA: data}
|
||||
)
|
||||
|
||||
async def cast_skill(call: ServiceCall) -> ServiceResponse:
|
||||
"""Skill action."""
|
||||
entry = get_config_entry(hass, call.data[ATTR_CONFIG_ENTRY])
|
||||
@ -928,12 +874,6 @@ def async_setup_services(hass: HomeAssistant) -> None: # noqa: C901
|
||||
schema=SERVICE_CREATE_TASK_SCHEMA,
|
||||
supports_response=SupportsResponse.ONLY,
|
||||
)
|
||||
hass.services.async_register(
|
||||
DOMAIN,
|
||||
SERVICE_API_CALL,
|
||||
handle_api_call,
|
||||
schema=SERVICE_API_CALL_SCHEMA,
|
||||
)
|
||||
|
||||
hass.services.async_register(
|
||||
DOMAIN,
|
||||
|
@ -1,20 +1,4 @@
|
||||
# Describes the format for Habitica service
|
||||
api_call:
|
||||
fields:
|
||||
name:
|
||||
required: true
|
||||
example: "xxxNotAValidNickxxx"
|
||||
selector:
|
||||
text:
|
||||
path:
|
||||
required: true
|
||||
example: '["tasks", "user", "post"]'
|
||||
selector:
|
||||
object:
|
||||
args:
|
||||
example: '{"text": "Use API from Home Assistant", "type": "todo"}'
|
||||
selector:
|
||||
object:
|
||||
cast_skill:
|
||||
fields:
|
||||
config_entry: &config_entry
|
||||
|
@ -526,31 +526,9 @@
|
||||
"deprecated_entity": {
|
||||
"title": "The Habitica {name} entity is deprecated",
|
||||
"description": "The Habitica entity `{entity}` is deprecated and will be removed in a future release.\nPlease update your automations and scripts, disable `{entity}` and reload the integration/restart Home Assistant to fix this issue."
|
||||
},
|
||||
"deprecated_api_call": {
|
||||
"title": "The Habitica action habitica.api_call is deprecated",
|
||||
"description": "The Habitica action `habitica.api_call` is deprecated and will be removed in Home Assistant 2025.5.0.\n\nPlease update your automations and scripts to use other Habitica actions and entities."
|
||||
}
|
||||
},
|
||||
"services": {
|
||||
"api_call": {
|
||||
"name": "API name",
|
||||
"description": "Calls Habitica API.",
|
||||
"fields": {
|
||||
"name": {
|
||||
"name": "[%key:common::config_flow::data::name%]",
|
||||
"description": "Habitica's username to call for."
|
||||
},
|
||||
"path": {
|
||||
"name": "[%key:common::config_flow::data::path%]",
|
||||
"description": "Items from API URL in form of an array with method attached at the end. Consult https://habitica.com/apidoc/. Example uses https://habitica.com/apidoc/#api-Task-CreateUserTasks."
|
||||
},
|
||||
"args": {
|
||||
"name": "Args",
|
||||
"description": "Any additional JSON or URL parameter arguments. See apidoc mentioned for path. Example uses same API endpoint."
|
||||
}
|
||||
}
|
||||
},
|
||||
"cast_skill": {
|
||||
"name": "Cast a skill",
|
||||
"description": "Uses a skill or spell from your Habitica character on a specific task to affect its progress or status.",
|
||||
|
@ -8,17 +8,9 @@ from aiohttp import ClientError
|
||||
from freezegun.api import FrozenDateTimeFactory
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.habitica.const import (
|
||||
ATTR_ARGS,
|
||||
ATTR_DATA,
|
||||
ATTR_PATH,
|
||||
DOMAIN,
|
||||
EVENT_API_CALL_SUCCESS,
|
||||
SERVICE_API_CALL,
|
||||
)
|
||||
from homeassistant.components.habitica.const import DOMAIN
|
||||
from homeassistant.config_entries import SOURCE_REAUTH, ConfigEntryState
|
||||
from homeassistant.const import ATTR_NAME
|
||||
from homeassistant.core import Event, HomeAssistant
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .conftest import (
|
||||
ERROR_BAD_REQUEST,
|
||||
@ -27,13 +19,7 @@ from .conftest import (
|
||||
ERROR_TOO_MANY_REQUESTS,
|
||||
)
|
||||
|
||||
from tests.common import MockConfigEntry, async_capture_events, async_fire_time_changed
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def capture_api_call_success(hass: HomeAssistant) -> list[Event]:
|
||||
"""Capture api_call events."""
|
||||
return async_capture_events(hass, EVENT_API_CALL_SUCCESS)
|
||||
from tests.common import MockConfigEntry, async_fire_time_changed
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("habitica")
|
||||
@ -53,37 +39,6 @@ async def test_entry_setup_unload(
|
||||
assert config_entry.state is ConfigEntryState.NOT_LOADED
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("habitica")
|
||||
async def test_service_call(
|
||||
hass: HomeAssistant,
|
||||
config_entry: MockConfigEntry,
|
||||
capture_api_call_success: list[Event],
|
||||
) -> None:
|
||||
"""Test integration setup, service call and unload."""
|
||||
config_entry.add_to_hass(hass)
|
||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert config_entry.state is ConfigEntryState.LOADED
|
||||
|
||||
assert len(capture_api_call_success) == 0
|
||||
|
||||
TEST_SERVICE_DATA = {
|
||||
ATTR_NAME: "test-user",
|
||||
ATTR_PATH: ["tasks", "user", "post"],
|
||||
ATTR_ARGS: {"text": "Use API from Home Assistant", "type": "todo"},
|
||||
}
|
||||
await hass.services.async_call(
|
||||
DOMAIN, SERVICE_API_CALL, TEST_SERVICE_DATA, blocking=True
|
||||
)
|
||||
|
||||
assert len(capture_api_call_success) == 1
|
||||
captured_data = capture_api_call_success[0].data
|
||||
captured_data[ATTR_ARGS] = captured_data[ATTR_DATA]
|
||||
del captured_data[ATTR_DATA]
|
||||
assert captured_data == TEST_SERVICE_DATA
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("exception"),
|
||||
[ERROR_BAD_REQUEST, ERROR_TOO_MANY_REQUESTS, ClientError],
|
||||
|
Loading…
x
Reference in New Issue
Block a user