{"record":{"id":"9012faaf29c1d912","repo":"home-assistant/core","slug":"command-not-found-cmds-not-found-0-r","errorCode":null,"errorMessage":"Command not found: {cmds_not_found[0]!r}","messagePattern":"Command not found: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"homeassistant/components/broadlink/remote.py","lineNumber":480,"sourceCode":"            _LOGGER.error(\"Failed to call %s. %s\", service, err_msg)\n            raise ValueError(err_msg) from err\n\n        cmds_not_found = []\n        for command in commands:\n            try:\n                del codes[command]\n            except KeyError:\n                cmds_not_found.append(command)\n\n        if cmds_not_found:\n            if len(cmds_not_found) == 1:\n                err_msg = f\"Command not found: {cmds_not_found[0]!r}\"\n            else:\n                err_msg = f\"Commands not found: {cmds_not_found!r}\"\n\n            if len(cmds_not_found) == len(commands):\n                _LOGGER.error(\"Failed to call %s. %s\", service, err_msg)\n                raise ValueError(err_msg)\n\n            _LOGGER.error(\"Error during %s. %s\", service, err_msg)\n\n        # Clean up\n        if not codes:\n            del self._codes[subdevice]\n            if self._flags.pop(subdevice, None) is not None:\n                self._flag_storage.async_delay_save(self._get_flags, FLAG_SAVE_DELAY)\n\n        self._code_storage.async_delay_save(self._get_codes, CODE_SAVE_DELAY)\n","sourceCodeStart":462,"sourceCodeEnd":491,"githubUrl":"https://github.com/home-assistant/core/blob/58a3fdb3ea0538617f0a07efcfba6294de64fd59/homeassistant/components/broadlink/remote.py#L462-L491","documentation":"Constructed when exactly one requested command is missing from the stored codes during async_delete_command. The ValueError is only raised when ALL requested commands are missing; otherwise the message is logged as a partial-failure error and deletion of the found commands proceeds. Indicates the stored code dictionary has drifted from what the caller expects.","triggerScenarios":"Calling remote.delete_command with a single command name never learned, renamed, or already deleted; code was learned under a different subdevice; typos in the command string.","commonSituations":"Deleting a command twice in a row (first call removes it, second raises); scripts referencing command names from an older learning session; partial deletions in prior runs that logged but did not raise.","solutions":["Inspect the entity's stored codes to confirm the exact command names before deleting","If the command is already gone, drop it from the delete list — nothing remains to delete","Re-learn the command under the correct name if you actually want it stored","When deleting several commands, treat partial failures as logged warnings — only all-missing raises"],"exampleFix":"# before\nawait remote_svc.async_call('remote', 'delete_command', {\n    'entity_id': 'remote.broadlink', 'device': 'tv', 'command': 'powr',  # typo\n})\n\n# after\nstored = await remote_svc.async_call('remote', 'get_stored_codes',\n    {'entity_id': 'remote.broadlink'}, blocking=True, return_response=True)\ncommand = 'power' if 'power' in stored['remote.broadlink']['tv'] else None\nif command:\n    await remote_svc.async_call('remote', 'delete_command', {\n        'entity_id': 'remote.broadlink', 'device': 'tv', 'command': command,\n    })","handlingStrategy":"validation","validationCode":"stored = await hass.services.async_call(\n    'remote', 'get_stored_codes',\n    {'entity_id': 'remote.broadlink'}, blocking=True, return_response=True,\n)\ncommand_exists = command in stored['remote.broadlink'].get(subdevice, {})\nif not command_exists:\n    # already deleted or never learned; skip","typeGuard":null,"tryCatchPattern":"try:\n    await remote.async_delete_command(device=subdevice, command=command)\nexcept ValueError as err:\n    if 'Command not found' in str(err):\n        # requested command(s) already absent; idempotent no-op\n        pass\n    else:\n        raise","preventionTips":["Check exact command names (case-sensitive) via get_stored_codes before deleting","Design delete scripts to be idempotent — re-running after success raises when all commands are gone","Note partial-miss only logs; all-miss raises — split lists accordingly"],"tags":["broadlink","remote","delete-command","home-assistant"],"backgroundTag":null,"analyzedSha":"58a3fdb3ea0538617f0a07efcfba6294de64fd59","analyzedAt":"2026-08-14T20:54:38.818Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}