'dict' object is not callable

I’m developing a custom component for image processing, and getting this error in the logs:

2021-04-30 11:14:10 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [547491405776] 'dict' object is not callable
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 167, in handle_call_service
await hass.services.async_call(
File "/usr/src/homeassistant/homeassistant/core.py", line 1481, in async_call
task.result()
File "/usr/src/homeassistant/homeassistant/core.py", line 1516, in _execute_service
await handler.job.target(service_call)
File "/usr/src/homeassistant/homeassistant/components/hassio/__init__.py", line 477, in async_handle_core_service
errors = await conf_util.async_check_ha_config_file(hass)
File "/usr/src/homeassistant/homeassistant/config.py", line 904, in async_check_ha_config_file
res = await check_config.async_check_ha_config_file(hass)
File "/usr/src/homeassistant/homeassistant/helpers/check_config.py", line 225, in async_check_ha_config_file
p_validated = platform_schema(p_validated)
TypeError: 'dict' object is not callable

I’ve tried lots of changing the PLATFORM_SCHEMA, but I still get this error. Here’s what I’m using:

from homeassistant.components.image_processing import (
  CONF_ENTITY_ID,
  PLATFORM_SCHEMA
)
CONF_CLASSIFIER = "classifier"
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
  {
    vol.Required(CONF_ENTITY_ID): cv.entity_id,
    vol.Required(CONF_CLASSIFIER): cv.isfile,
  }
)

Does anybody know how to fix this?

Edit: Random messing around fixed it.

The error message told you the problem:

p_validated = platform_schema(p_validated)

platform_schema is a dictionary, so if you want to get this value out of it, you need to use platform_schema['p_validated']. By using parentheses, you’re treating it like a function (callable).

I’m not running that function, I’m declaring PLATFORM_SCHEMA.

Confusingly the various register_xx methods of the registry handle schemas differently.

Some, such as async_register_entity_service will accept a dict.

HOWEVER

Most require the object to be a vol.Schema, not dict.

Just call vol.Schema(THE_DICT_YOU_DEFINED)


import voluptuous as vol
import homeassistant.helpers.config_validation as cv
import homeassistant.helpers.service as service_helper
...
IMAGE_ANNOTATION_ANNOTATE: Final = {
    vol.Required(ATTR_FILENAME): cv.template,
    vol.Required(ATTR_ANNOTATION): cv.template,
}

...
def setup(hass: HomeAssistant, config: ConfigType) -> bool:
    hass.services.register(
        domain=DOMAIN,
        service=ACTION,
        service_func=handle_annotation,
        schema=vol.Schema(IMAGE_ANNOTATION_ANNOTATE),
    )