I’m trying to add entity services to my integration. But every time I try to call the service I’m getting a stack trace.
Error handling message: Unknown error
Traceback (most recent call last):
File "/workspaces/ha-core/homeassistant/components/websocket_api/decorators.py", line 25, in _handle_async_response
await func(hass, connection, msg)
File "/workspaces/ha-core/homeassistant/components/websocket_api/commands.py", line 525, in handle_execute_script
await script_obj.async_run(msg.get("variables"), context=context)
File "/workspaces/ha-core/homeassistant/helpers/script.py", line 1219, in async_run
await asyncio.shield(run.async_run())
File "/workspaces/ha-core/homeassistant/helpers/script.py", line 353, in async_run
await self._async_step(log_exceptions=False)
File "/workspaces/ha-core/homeassistant/helpers/script.py", line 371, in _async_step
await getattr(self, handler)()
File "/workspaces/ha-core/homeassistant/helpers/script.py", line 571, in _async_call_service_step
await service_task
File "/workspaces/ha-core/homeassistant/core.py", line 1446, in async_call
processed_data = handler.schema(service_data)
File "/usr/local/lib/python3.9/site-packages/voluptuous/schema_builder.py", line 272, in __call__
return self._compiled([], data)
File "/usr/local/lib/python3.9/site-packages/voluptuous/validators.py", line 215, in _run
return self._exec(self._compiled, value, path)
File "/usr/local/lib/python3.9/site-packages/voluptuous/validators.py", line 339, in _exec
v = func(path, v)
File "/usr/local/lib/python3.9/site-packages/voluptuous/schema_builder.py", line 817, in validate_callable
return schema(data)
File "/workspaces/ha-core/homeassistant/helpers/config_validation.py", line 134, in validate
raise vol.Invalid("must contain at least one of {}.".format(", ".join(keys)))
TypeError: sequence item 0: expected str instance, Optional found
The only code I added was in sensor.py (the last lines)
async def async_setup_entry(
hass: HomeAssistant, config: ConfigEntry, async_add_entities, discovery_info=None
):
"""Call the Renson integration to setup."""
renson_api: renson.RensonVentilation = hass.data[DOMAIN][config.entry_id]
entities: list = []
for description in sensor_descriptions:
entities.append(RensonSensor(description, renson_api))
async_add_entities(entities)
platform = entity_platform.async_get_current_platform()
platform.async_register_entity_service(SERVICE_SYNC_TIME, {}, "sync_time")
And in the SensorEntity I added a function:
@callback
async def sync_time(self, **kwargs):
"""Call sync time on Renson device."""
self.renson_api.sync_time()
I cannot find what I’m doing wrong and the developer documentation does also not saying much about entity services. Can someone help me finising my first integration in hass?