Skip to content

Commit

Permalink
Merge pull request #83 from Snuffy2/Fix-set_variable-Service-ReadOnly…
Browse files Browse the repository at this point in the history
…Dict-RuntimeError

Fix set_variable ReadOnlyDict RuntimeError
  • Loading branch information
enkama authored Jul 14, 2023
2 parents 5a8b103 + 2ea9423 commit 7872a55
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions custom_components/variable/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,23 +69,22 @@ async def async_set_variable_legacy_service(call):

# _LOGGER.debug(f"[async_set_variable_legacy_service] Pre call data: {call.data}")
ENTITY_ID_FORMAT = Platform.SENSOR + ".{}"
entity_id = ENTITY_ID_FORMAT.format(call.data.get(ATTR_VARIABLE))
call.data.update({ATTR_ENTITY: entity_id})
var_ent = ENTITY_ID_FORMAT.format(call.data.get(ATTR_VARIABLE))
# _LOGGER.debug(f"[async_set_variable_legacy_service] Post call data: {call.data}")
await _async_set_legacy_service(call)
await _async_set_legacy_service(call, var_ent)

async def async_set_entity_legacy_service(call):
"""Handle calls to the set_entity legacy service."""

# _LOGGER.debug(f"[async_set_entity_legacy_service] call data: {call.data}")
await _async_set_legacy_service(call)
await _async_set_legacy_service(call, call.data.get(ATTR_ENTITY))

async def _async_set_legacy_service(call):
async def _async_set_legacy_service(call, var_ent):
"""Shared function for both set_entity and set_variable legacy services."""

# _LOGGER.debug(f"[_async_set_legacy_service] call data: {call.data}")
update_sensor_data = {
CONF_ENTITY_ID: [call.data.get(ATTR_ENTITY)],
CONF_ENTITY_ID: [var_ent],
ATTR_REPLACE_ATTRIBUTES: call.data.get(ATTR_REPLACE_ATTRIBUTES, False),
}
if call.data.get(ATTR_VALUE):
Expand Down

0 comments on commit 7872a55

Please sign in to comment.