enkama / hass-variables

Home Assistant variables component

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error calling set_variable Service - RuntimeError: Cannot modify ReadOnlyDict

Snuffy2 opened this issue · comments

          I have tried right now but I get error... Any idea?

Variable has been defined like this, into variable.yaml file

variable_last_state:
  value: ""
  restore: true

which means that I have a sensor.variable_last_state entity

image

With this is working to change the value

service: variable.update_sensor
data:
  value: ok
target:
  entity_id: sensor.variable_last_state

But I need to use the legacy version

Originally posted by @pickonedev in #80 (comment)

I was able to reproduce the error. Looking into how to fix now.

2023-07-13 20:36:57.036 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [547343268432] Error handling message: Unknown error (unknown_error) Justin from 2600:4040:a51d:1d64:5ca2:d340:57c2:1707 (Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:109.0) Gecko/20100101 Firefox/115.0)
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/decorators.py", line 26, in _handle_async_response
    await func(hass, connection, msg)
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 680, in handle_execute_script
    response = await script_obj.async_run(msg.get("variables"), context=context)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1569, in async_run
    return await asyncio.shield(run.async_run())
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 420, in async_run
    await self._async_step(log_exceptions=False)
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 470, in _async_step
    self._handle_exception(
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 493, in _handle_exception
    raise exception
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 468, in _async_step
    await getattr(self, handler)()
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 703, in _async_call_service_step
    response_data = await self._async_run_long_action(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 665, in _async_run_long_action
    return long_task.result()
           ^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 1957, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 1997, in _execute_service
    return await cast(
           ^^^^^^^^^^^
  File "/config/custom_components/variable/__init__.py", line 73, in async_set_variable_legacy_service
    call.data.update({ATTR_ENTITY: entity_id})
  File "/usr/src/homeassistant/homeassistant/util/read_only_dict.py", line 7, in _readonly
    raise RuntimeError("Cannot modify ReadOnlyDict")
RuntimeError: Cannot modify ReadOnlyDict