modificar_habitacion
Change the name of an existing smart home room and automatically update all associated devices with the new room name for consistent home automation management.
Instructions
Modifica el nombre de una habitación existente. Actualiza automáticamente todos los dispositivos asociados.
Args: old_name: nombre actual de la habitación new_name: nuevo nombre para la habitación
Returns: Confirmación con ambos nombres (antiguo y nuevo).
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| old_name | Yes | ||
| new_name | Yes |
Implementation Reference
- servers/mcp_rooms.py:187-200 (handler)The MCP tool handler function for 'modificar_habitacion'. It invokes the storage layer to update the room name and associated devices.@mcp.tool() def modificar_habitacion(old_name: str, new_name: str) -> dict: """ Modifica el nombre de una habitación existente. Actualiza automáticamente todos los dispositivos asociados. Args: old_name: nombre actual de la habitación new_name: nuevo nombre para la habitación Returns: Confirmación con ambos nombres (antiguo y nuevo). """ return storage.update_room(old_name, new_name)
- storage.py:92-109 (helper)Supporting method in the storage class that implements the room renaming logic, including validation, updating device room assignments, and persisting changes to JSON file.def update_room(self, old_name: str, new_name: str) -> dict: """Renombra una habitación y actualiza sus dispositivos.""" self.reload() # Sincronizar con archivo if old_name not in self.rooms: raise ValueError(f"Habitación '{old_name}' no existe") if new_name in self.rooms and new_name != old_name: raise ValueError(f"Habitación '{new_name}' ya existe") room = self.rooms.pop(old_name) room.name = new_name self.rooms[new_name] = room # Actualizar room en dispositivos for device_id in room.devices: self.devices[device_id].room = new_name self._save_to_file() return {"old_name": old_name, "new_name": new_name, "status": "updated"}
- servers/mcp_rooms.py:187-187 (registration)The @mcp.tool() decorator registers the modificar_habitacion function as an MCP tool.@mcp.tool()